GatewayRouterBuilder.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package camel.central.gateway.route;
  2. import camel.central.gateway.processor.ErrorHandle;
  3. import camel.central.gateway.processor.GatewayProcessor;
  4. import camel.central.gateway.processor.WsProcessor;
  5. import org.apache.camel.Exchange;
  6. import org.apache.camel.builder.RouteBuilder;
  7. import org.springframework.stereotype.Component;
  8. /**
  9. * @author HZY
  10. * @vsrsion 1.0
  11. * Created at 2017/3/13.
  12. */
  13. @Component
  14. public class GatewayRouterBuilder extends RouteBuilder {
  15. protected static final String SIMPLE_ENDPOINT_ADDRESS = "http://0.0.0.0:3333/ws/api";
  16. protected static final String SIMPLE_ENDPOINT_URI = "cxf:" + SIMPLE_ENDPOINT_ADDRESS
  17. + "?serviceClass=camel.central.gateway.processor.WsService"
  18. // + "&dataFormat=CXF_MESSAGE"
  19. ;
  20. @Override
  21. public void configure() throws Exception {
  22. from("jetty:http://0.0.0.0:9998?matchOnUriPrefix=true").routeId("proxy")
  23. .to("jetty:http://192.168.1.221:10000?bridgeEndpoint=true&throwExceptionOnFailure=false");
  24. from("jetty:http://0.0.0.0:9999/api").routeId("api")
  25. .process(new GatewayProcessor())
  26. .routingSlip(method(GatewayProcessor.class, "route"));
  27. from("direct:errorHandle")
  28. .choice()
  29. .when(header(Exchange.HTTP_URI).contains("paramError")).bean(new ErrorHandle(), "paramError")
  30. .when(header(Exchange.HTTP_URI).contains("outdateError")).bean(new ErrorHandle(), "outdateError")
  31. .when(header(Exchange.HTTP_URI).contains("signValidError")).bean(new ErrorHandle(), "signValidError")
  32. .when(header(Exchange.HTTP_URI).contains("unauthorizedError")).bean(new ErrorHandle(), "unauthorizedError")
  33. .endChoice();
  34. from("jetty:http://0.0.0.0:9999/healthy").routeId("healthy")
  35. .log("=========================心跳测试=====================");
  36. from(SIMPLE_ENDPOINT_URI)
  37. .setHeader(Exchange.BEAN_MULTI_PARAMETER_ARRAY, constant(true))
  38. .process(new WsProcessor())
  39. .routingSlip(method(GatewayProcessor.class, "route"))
  40. .to("bean:wsProcessor?method=responseWs");
  41. }
  42. }