package camel.gateway.route; import camel.gateway.processor.ErrorHandle; import camel.gateway.processor.GatewayProcessor; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.springframework.stereotype.Component; /** * @author HZY * @vsrsion 1.0 * Created at 2017/3/13. */ @Component public class GatewayRouterBuilder extends RouteBuilder { @Override public void configure() throws Exception { from("jetty:http://0.0.0.0:9998?matchOnUriPrefix=true").routeId("proxy") .to("jetty:http://127.0.0.1:10000?bridgeEndpoint=true&throwExceptionOnFailure=false"); from("jetty:http://0.0.0.0:9999/api").routeId("api") .log(body().toString()) .process(new GatewayProcessor()) .routingSlip(method(GatewayProcessor.class, "route")) .log(body().toString()); from("jetty:http://0.0.0.0:9999/error") .choice() .when(header(Exchange.HTTP_URI).contains("paramError")).bean(new ErrorHandle(), "paramError") .when(header(Exchange.HTTP_URI).contains("outdataError")).bean(new ErrorHandle(), "outdataError") .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("=========================心跳测试====================="); } }