|
@ -1,84 +0,0 @@
|
|
|
package camel.gateway.route;
|
|
|
|
|
|
import camel.gateway.processor.ErrorHandle;
|
|
|
import camel.gateway.processor.GatewayProcessor;
|
|
|
import camel.gateway.processor.SignProcessor;
|
|
|
import camel.log.TracerFormatter;
|
|
|
import org.apache.camel.Exchange;
|
|
|
import org.apache.camel.builder.RouteBuilder;
|
|
|
import org.apache.camel.processor.interceptor.Tracer;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
/**
|
|
|
* @author HZY
|
|
|
* @vsrsion 1.0
|
|
|
* Created at 2017/3/13.
|
|
|
*/
|
|
|
@Component
|
|
|
public class GatewayRouterBuilder extends RouteBuilder {
|
|
|
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"
|
|
|
;
|
|
|
@Override
|
|
|
public void configure() throws Exception {
|
|
|
this.getContext().setUseMDCLogging(true);
|
|
|
this.getContext().setTracing(true);
|
|
|
|
|
|
Tracer tracer = new Tracer();
|
|
|
// DefaultTraceFormatter formatter = new DefaultTraceFormatter();
|
|
|
TracerFormatter formatter = new TracerFormatter();
|
|
|
formatter.setShowHeaders(true);
|
|
|
formatter.setShowBody(true);
|
|
|
formatter.setShowBodyType(true);
|
|
|
formatter.setShowOutHeaders(true);
|
|
|
formatter.setShowOutBody(true);
|
|
|
formatter.setShowOutBodyType(true);
|
|
|
|
|
|
tracer.setFormatter(formatter);
|
|
|
this.getContext().addInterceptStrategy(tracer);
|
|
|
|
|
|
this.getContext().getProperties().put(Exchange.LOG_DEBUG_BODY_STREAMS, "true");
|
|
|
this.getContext().getProperties().put(Exchange.BEAN_MULTI_PARAMETER_ARRAY, "true");
|
|
|
|
|
|
from("jetty:http://0.0.0.0:9998?matchOnUriPrefix=true").routeId("proxy")
|
|
|
.to("jetty:http://192.168.1.221:10000?bridgeEndpoint=true&throwExceptionOnFailure=false");
|
|
|
|
|
|
from("jetty:http://0.0.0.0:9999/api").routeId("api")
|
|
|
.process(new GatewayProcessor())
|
|
|
.routingSlip(method(GatewayProcessor.class, "route"));
|
|
|
|
|
|
|
|
|
from("direct:errorHandle")
|
|
|
.choice()
|
|
|
.when(header(Exchange.HTTP_URI).contains("paramError")).bean(new ErrorHandle(), "paramError")
|
|
|
.when(header(Exchange.HTTP_URI).contains("outdateError")).bean(new ErrorHandle(), "outdateError")
|
|
|
.when(header(Exchange.HTTP_URI).contains("signValidError")).bean(new ErrorHandle(), "signValidError")
|
|
|
.when(header(Exchange.HTTP_URI).contains("unauthorizedError")).bean(new ErrorHandle(), "unauthorizedError")
|
|
|
.endChoice();
|
|
|
|
|
|
//
|
|
|
// from("jetty:http://0.0.0.0:9996/error/{error}")
|
|
|
// .choice()
|
|
|
// .when(header(Exchange.HTTP_URI).contains("paramError")).bean(new ErrorHandle(), "paramError")
|
|
|
// .when(header(Exchange.HTTP_URI).contains("outdateError")).bean(new ErrorHandle(), "outdateError")
|
|
|
// .when(header(Exchange.HTTP_URI).contains("signValidError")).bean(new ErrorHandle(), "signValidError")
|
|
|
// .when(header(Exchange.HTTP_URI).contains("unauthorizedError")).bean(new ErrorHandle(), "unauthorizedError")
|
|
|
// .endChoice();
|
|
|
|
|
|
from("jetty:http://0.0.0.0:9999/healthy").routeId("healthy")
|
|
|
.log("=========================心跳测试=====================");
|
|
|
|
|
|
from("jetty:http://0.0.0.0:9999/sign").routeId("sign")
|
|
|
.process(new SignProcessor());
|
|
|
|
|
|
// from(SIMPLE_ENDPOINT_URI)
|
|
|
// .setHeader(Exchange.BEAN_MULTI_PARAMETER_ARRAY, constant(true))
|
|
|
// .process(new WsProcessor())
|
|
|
// .routingSlip(method(GatewayProcessor.class, "route"))
|
|
|
// .to("bean:wsProcessor?method=responseWs")
|
|
|
;
|
|
|
}
|
|
|
|
|
|
}
|