Browse Source

api暂时不使用服务名获取服务地址

huangzhiyong 8 years ago
parent
commit
438882c150

+ 4 - 4
hos-camel2/src/main/java/camel/gateway/processor/ErrorHandle.java

@ -10,26 +10,26 @@ import org.springframework.stereotype.Component;
@Component("errorHandle")
public class ErrorHandle {
    public void paramError(Exchange exchange) {
        exchange.getOut().setHeader("errorCode","paramError");
        exchange.getOut().setHeader("errorCode","{\"successFlg\":false,\"pageSize\":10,\"currPage\":0,\"totalPage\":0,\"totalCount\":0,\"detailModelList\":null,\"obj\":null,\"errorMsg\":\"paramError!\",\"errorCode\":0}");
        exchange.getOut().setBody("paramError");
    }
    public void outdataError(Exchange exchange) {
        exchange.getOut().setHeader("errorCode","outdataError");
        exchange.getOut().setHeader("errorCode","{\"successFlg\":false,\"pageSize\":10,\"currPage\":0,\"totalPage\":0,\"totalCount\":0,\"detailModelList\":null,\"obj\":null,\"errorMsg\":\"outdataError!\",\"errorCode\":0}");
        exchange.getOut().setBody("outdataError");
    }
    public void signValidError(Exchange exchange) {
        exchange.getOut().setHeader("errorCode","signValidError");
        exchange.getOut().setHeader("errorCode","{\"successFlg\":false,\"pageSize\":10,\"currPage\":0,\"totalPage\":0,\"totalCount\":0,\"detailModelList\":null,\"obj\":null,\"errorMsg\":\"signValidError!\",\"errorCode\":0}");
        exchange.getOut().setBody("signValidError");
    }
    public void unauthorizedError(Exchange exchange) {
        exchange.getOut().setHeader("errorCode","unauthorizedError");
        exchange.getOut().setHeader("errorCode","{\"successFlg\":false,\"pageSize\":10,\"currPage\":0,\"totalPage\":0,\"totalCount\":0,\"detailModelList\":null,\"obj\":null,\"errorMsg\":\"unauthorizedError!\",\"errorCode\":0}");
        exchange.getOut().setBody("unauthorizedError");

+ 15 - 3
hos-camel2/src/main/java/camel/gateway/processor/GatewayProcessor.java

@ -183,7 +183,7 @@ public class GatewayProcessor implements Processor {
                return "";
            }
            final String[] endPoint = {"restlet:" + url + appApi.getMsMethodName() + "?socketTimeout=60000&connectionTimeout=60000&restletMethod=" + methodMap.get(appApi.getMethod())};
            final String[] endPoint = {"restlet:" + appApi.getMicroServiceUri() + appApi.getMsMethodName() + "?socketTimeout=60000&connectionTimeout=60000&restletMethod=" + methodMap.get(appApi.getMethod())};
            final String[] body = {""};
            appApi.getParameters().forEach(p -> {
                JsonNode paramNode = jsonNode.get(p.getName());
@ -191,9 +191,9 @@ public class GatewayProcessor implements Processor {
                    return;
                }
                String value = paramNode.asText();
                Object value = nodeValue(paramNode);
                if (p.getType().equals("0")) { //path param
                    endPoint[0] = endPoint[0].replaceAll("\\{[^}]*\\}", value);
                    endPoint[0] = endPoint[0].replaceAll("\\{[^}]*\\}", value.toString());
                } else if (p.getType().equals("2")) { //head param
                    exchange.getOut().setHeader(p.getName(), value);
                } else {
@ -278,7 +278,19 @@ public class GatewayProcessor implements Processor {
        }
        return response.getBody();
    }
    public String nodeValue(JsonNode node){
        Object value = null;
        switch (node.getNodeType().name()){
            case "NUMBER" : value = node.asInt();break;
            case "STRING" : value = node.asText();break;
            case "BOOLEAN" : value = node.asBoolean();break;
            case "OBJECT" : value = node.toString();break;
            default:value = "";break;
        }
        return value.toString();
    }
}

+ 1 - 3
hos-camel2/src/main/java/camel/gateway/processor/WsProcessor.java

@ -17,7 +17,6 @@ import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import java.io.StringReader;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -42,8 +41,7 @@ public class WsProcessor implements Processor {
            Object errorCode = exchange.getIn().getHeader("errorCode");
            if (errorCode!=null){
                //错误信息返回
                LinkedHashMap<Object, Object> errorMap = new LinkedHashMap<>();
                errorMap.put("errorCode",errorCode);
                Map<Object, Object> errorMap = objectMapper.readValue(errorCode.toString(),Map.class);
                String xmlResponse = xmlMapper.writeValueAsString(errorMap);
                return createDefaultSoapMessage(xmlResponse);
            }

+ 1 - 1
hos-camel2/src/main/java/camel/gateway/route/GatewayRouterBuilder.java

@ -17,7 +17,7 @@ import org.springframework.stereotype.Component;
 */
@Component
public class GatewayRouterBuilder extends RouteBuilder {
    protected static final String SIMPLE_ENDPOINT_ADDRESS = "http://0.0.0.0:3333/soap/ws";
    protected static final String SIMPLE_ENDPOINT_ADDRESS = "http://0.0.0.0:3333/ws/api";
    protected static final String SIMPLE_ENDPOINT_URI = "cxf:" + SIMPLE_ENDPOINT_ADDRESS
            + "?serviceClass=camel.gateway.processor.WsService"
//            + "&dataFormat=CXF_MESSAGE"