Route.java 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package com.sagacloud.route;
  2. import com.github.rjeschke.txtmark.Processor;
  3. import com.sagacloud.Exceptions.InvalidPostException;
  4. import com.sagacloud.route.processors.GetInsuranceNoListProcessor;
  5. import com.sagacloud.route.processors.handleWarrantyFromVenderProcessor;
  6. import com.sagacloud.route.processors.GetPropByPjProcessor;
  7. import com.sagacloud.utils.Const;
  8. import com.sagacloud.utils.VendersUtil;
  9. import org.apache.camel.Exchange;
  10. import org.apache.camel.builder.RouteBuilder;
  11. import org.apache.commons.io.IOUtils;
  12. import javax.ws.rs.core.MediaType;
  13. import java.io.StringWriter;
  14. /**
  15. * Created by Xiaoyu on 2018/7/10
  16. */
  17. public class Route extends RouteBuilder {
  18. @Override
  19. public void configure() throws Exception {
  20. rest().get("/doc")
  21. .produces("text/html;charset=UTF-8")
  22. .route()
  23. .process(msg -> {
  24. String docContentStr = Processor.process(Route.class.getClassLoader().getResourceAsStream("documentation.md"));
  25. StringWriter writer = new StringWriter();
  26. IOUtils.copy(Route.class.getClassLoader().getResourceAsStream("template.html"), writer, "utf-8");
  27. String tmplateContentStr = writer.toString();
  28. msg.getOut().setBody(tmplateContentStr.replace("#replaceMePlease#", docContentStr));
  29. });
  30. // 查询项目下的资产
  31. rest("/manufacturer/property/").post("query")
  32. .consumes(MediaType.APPLICATION_JSON)
  33. .produces(MediaType.APPLICATION_JSON)
  34. .route()
  35. .process();
  36. // 查询项目下的资产
  37. rest("/supplier/property/").post("query")
  38. .consumes(MediaType.APPLICATION_JSON)
  39. .produces(MediaType.APPLICATION_JSON)
  40. .route()
  41. .process();
  42. // 获取在保资产清单
  43. rest("/insurance/project/").post("query")
  44. .consumes(MediaType.APPLICATION_JSON)
  45. .produces(MediaType.APPLICATION_JSON)
  46. .route()
  47. .process(new GetInsuranceNoListProcessor())
  48. .to(String.join("", InitEnvRoute.venders, "/insurance/contract/query"))
  49. .process(new GetInsuranceNoListProcessor())
  50. .to(String.join("", InitEnvRoute.dataPlatform, "/property/relation_query"))
  51. .process(new GetInsuranceNoListProcessor());
  52. // 获取所有保单列表
  53. rest("/insurance/contract/").post("query")
  54. .consumes(MediaType.APPLICATION_JSON)
  55. .produces(MediaType.APPLICATION_JSON)
  56. .route()
  57. .process();
  58. // 根据保单获取资产
  59. rest("/insurance/contract/property/").post("query")
  60. .consumes(MediaType.APPLICATION_JSON)
  61. .produces(MediaType.APPLICATION_JSON)
  62. .route()
  63. .process();
  64. // 查询指定项目内合同有效期内的资产/查询指定项目内历史维护资产
  65. rest("/maintainance/property/").post("query")
  66. .consumes(MediaType.APPLICATION_JSON)
  67. .produces(MediaType.APPLICATION_JSON)
  68. .route()
  69. .process();
  70. //body位JSONObject,含有projectId字段
  71. from("direct:getPropertiesByPj")
  72. .process(new GetPropByPjProcessor())
  73. .to(Const.dataPlatform+"/property/relation_query")
  74. .process(exchange -> {
  75. System.out.println(exchange.getIn().getBody(String.class));
  76. });
  77. rest("/test").post()
  78. .consumes(MediaType.APPLICATION_JSON)
  79. .produces(MediaType.APPLICATION_JSON)
  80. .route()
  81. .to("direct:getPropertiesByPj");
  82. }
  83. protected void configExceptionHandler(){
  84. onException(InvalidPostException.class).handled(true).process(new org.apache.camel.Processor() {
  85. @Override
  86. public void process(Exchange exchange) throws Exception {
  87. Exception exception = (Exception) exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
  88. exchange.getOut().setBody(VendersUtil.errorJsonMsg(exception.getMessage()));
  89. }
  90. });
  91. }
  92. }