GatewayRouterBuilder.java 2.3 KB

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