| 
					
				 | 
			
			
				@ -7,20 +7,31 @@ import com.yihu.hos.core.http.HTTPResponse; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.hos.core.http.HttpClientKit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.camel.Exchange; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.camel.Processor; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.cloud.client.ServiceInstance; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.cloud.client.discovery.DiscoveryClient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Component; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.text.ParseException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.text.SimpleDateFormat; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Calendar; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.HashMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.stream.Stream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@Component 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				public class GatewayProcessor implements Processor { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    static Map<String, AppApi> apiMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    static final String agUrl = "http://192.168.1.221:10000"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    ParamVerifyBean paramSign; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private DiscoveryClient discoveryClient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void process(Exchange exchange) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String, Object> headers = exchange.getIn().getHeaders(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -108,7 +119,6 @@ public class GatewayProcessor implements Processor { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String sign = params.get("sign").toString();                     // 簽名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ParamVerifyBean paramSign = new ParamVerifyBean(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            paramSign.addParam(params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            paramSign.genParam(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //TODO 获取app secret传入验证 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -172,7 +182,11 @@ public class GatewayProcessor implements Processor { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            methodMap.put("3", "put"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JsonNode jsonNode = objectMapper.readValue(param, JsonNode.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String url = appApi.getMicroServiceUri().split(",")[0]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String url = serviceUrl(appApi.getMicroServiceName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (StringUtil.isEmpty(url)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            final String[] endPoint = {"restlet:" + url + appApi.getMsMethodName() + "?socketTimeout=60000&connectionTimeout=60000&restletMethod=" + methodMap.get(appApi.getMethod())}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            final String[] body = {""}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            appApi.getParameters().forEach(p -> { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -254,4 +268,19 @@ public class GatewayProcessor implements Processor { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 通过服务名获取微服务地址 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param serviceName  微服务名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String serviceUrl(String serviceName) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<ServiceInstance> instances = discoveryClient.getInstances(serviceName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (instances!=null && !instances.isEmpty()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ServiceInstance serviceInstance = instances.get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return serviceInstance.getUri().toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |