Route.java 4.1 KB

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