package com.sagacloud.route; import com.github.rjeschke.txtmark.Processor; import com.sagacloud.Exceptions.InvalidPostException; import com.sagacloud.route.processors.GetInsuranceNoListProcessor; import com.sagacloud.route.processors.GetPropByPjProcessor; import com.sagacloud.utils.Const; import org.apache.camel.builder.RouteBuilder; import org.apache.commons.io.IOUtils; import javax.ws.rs.core.MediaType; import java.io.StringWriter; /** * Created by Xiaoyu on 2018/7/10 */ public class Route extends RouteBuilder { @Override public void configure() throws Exception { rest().get("/doc") .produces("text/html;charset=UTF-8") .route() .process(msg -> { String docContentStr = Processor.process(Route.class.getClassLoader().getResourceAsStream("documentation.md")); StringWriter writer = new StringWriter(); IOUtils.copy(Route.class.getClassLoader().getResourceAsStream("template.html"), writer, "utf-8"); String tmplateContentStr = writer.toString(); msg.getOut().setBody(tmplateContentStr.replace("#replaceMePlease#", docContentStr)); }); // 查询项目下的资产 rest("/manufacturer/property/").post("query") .consumes(MediaType.APPLICATION_JSON) .produces(MediaType.APPLICATION_JSON) .route() .process(); // 查询项目下的资产 rest("/supplier/property/").post("query") .consumes(MediaType.APPLICATION_JSON) .produces(MediaType.APPLICATION_JSON) .route() .process(); // 获取在保资产清单 rest("/insurance/project/").post("query") .consumes(MediaType.APPLICATION_JSON) .produces(MediaType.APPLICATION_JSON) .route() .process(new GetInsuranceNoListProcessor()) .to(String.join("", InitEnvRoute.venders, "/insurance/contract/query")) .process(new GetInsuranceNoListProcessor()) .to(String.join("", InitEnvRoute.dataPlatform, "/property/relation_query")) .process(new GetInsuranceNoListProcessor()); // 获取所有保单列表 rest("/insurance/contract/").post("query") .consumes(MediaType.APPLICATION_JSON) .produces(MediaType.APPLICATION_JSON) .route() .process(); // 根据保单获取资产 rest("/insurance/contract/property/").post("query") .consumes(MediaType.APPLICATION_JSON) .produces(MediaType.APPLICATION_JSON) .route() .process(); // 查询指定项目内合同有效期内的资产/查询指定项目内历史维护资产 rest("/maintainance/property/").post("query") .consumes(MediaType.APPLICATION_JSON) .produces(MediaType.APPLICATION_JSON) .route() .process(); // from("direct:getPropertiesByPj") } protected void configExceptionHandler(){ onException(InvalidPostException.class).handled(true).process(new org.apache.camel.Processor() { @Override public void process(Exchange exchange) throws Exception { Exception exception = (Exception) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); exchange.getOut().setBody(VendersUtil.errorJsonMsg(exception.getMessage())); } }); //body位JSONObject,含有projectId字段 from("direct:getPropertiesByPj") .process(new GetPropByPjProcessor()) .to(Const.dataPlatform+"/property/relation_query") .process(exchange -> { System.out.println(exchange.getIn().getBody(String.class)); }); rest("/test").post() .consumes(MediaType.APPLICATION_JSON) .produces(MediaType.APPLICATION_JSON) .route() .to("direct:getPropertiesByPj"); } }