FanXiaoyu пре 6 година
родитељ
комит
c3fa68cd2d

+ 2 - 1
src/main/java/com/sagacloud/route/ExceptionHandlerBaseRoute.java

@@ -35,7 +35,8 @@ public class ExceptionHandlerBaseRoute extends RouteBuilder {
             @Override
             public void process(Exchange exchange) throws Exception {
                 Exception exception = (Exception) exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
-                exchange.getOut().setBody(VendersUtil.errorJsonMsg(""));
+                exception.printStackTrace();
+                exchange.getOut().setBody(VendersUtil.errorJsonMsg(exception.getMessage()));
             }
         });
     }

+ 4 - 20
src/main/java/com/sagacloud/route/InitEnvRoute.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.sagacloud.cache.ProPasCache;
 import com.sagacloud.utils.PropUtil;
+import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 
 import javax.ws.rs.core.MediaType;
@@ -21,13 +22,15 @@ public class InitEnvRoute extends RouteBuilder {
     public void configure() throws Exception {
 
         fromF("timer://simpleTimer?period=30m").to("direct:syn");
-        fromF("timer://simpleTimer?period=30m").to("direct:synProjectName");
+
 
 
         from("direct:syn")
                 .to(dataPlatform + "/mng/project/query?bridgeEndpoint=true&secret=A123456")
                 .process(exchange -> {
                     ProPasCache.syncProject(exchange.getIn().getBody(String.class));
+                    exchange.getIn().setBody(null);
+                    exchange.getIn().setHeader(Exchange.HTTP_URI, venders+"/auxiliary/vender/query?bridgeEndpoint=true&method=POST");
                 })
                 .to(venders + "/auxiliary/vender/query")
                 .process(exchange -> {
@@ -38,26 +41,7 @@ public class InitEnvRoute extends RouteBuilder {
                 .get()
                 .to("direct:syn");
 
-        rest("/project/sync_name").post()
-                .consumes(MediaType.APPLICATION_JSON)
-                .produces(MediaType.APPLICATION_JSON)
-                .route()
-                .to("direct:synProjectName");
 
-        from("direct:synProjectName")
-                .process(exchange -> {
-                    JSONArray criterias = new JSONArray();
-                    for (String pjId : ProPasCache.nameMap.keySet()) {
-                        JSONObject obj = new JSONObject();
-                        obj.put("projectId",pjId);
-                        obj.put("projectLocalName",ProPasCache.nameMap.get(pjId));
-                        criterias.add(obj);
-                    }
-                    JSONObject inserJson = new JSONObject();
-                    inserJson.put("criterias",criterias);
-                    exchange.getIn().setBody(inserJson.toString());
-                })
-                .to(InitEnvRoute.venders+"/auxiliary/project/create?bridgeEndpoint=true");
 
     }
 

+ 30 - 0
src/main/java/com/sagacloud/route/Route.java

@@ -19,6 +19,8 @@ import com.sagacloud.route.processors.supplier.SupplierFilter;
 import com.sagacloud.utils.Const;
 import org.apache.camel.Exchange;
 import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.ws.rs.core.MediaType;
 import java.io.StringWriter;
@@ -29,11 +31,13 @@ import java.util.List;
  * Created by Xiaoyu on 2018/7/10
  */
 public class Route extends ExceptionHandlerBaseRoute {
+    private static final Logger log = LoggerFactory.getLogger(Route.class);
     @Override
     public void configure() throws Exception {
         configExceptionHandler();
 
         fromF("timer://simpleTimer?period=1m").process(new OnTimeTaskProcessor()).to("direct:syncAllProject");
+        fromF("timer://simpleTimer?period=30m").to("direct:synProjectName");
 
         rest().get("/doc")
                 .produces("text/html;charset=UTF-8")
@@ -178,6 +182,32 @@ public class Route extends ExceptionHandlerBaseRoute {
                     exchange.getIn().setBody(exchange.getProperty("projectId" + exchange.getExchangeId()));
                 })
                 .to("direct:getPropertyStatisticsByProject");
+
+
+        rest("/project/").post("sync_name")
+                .consumes(MediaType.APPLICATION_JSON)
+                .produces(MediaType.APPLICATION_JSON)
+                .route()
+                .to("direct:synProjectName");
+
+        from("direct:synProjectName")
+                .process(exchange -> {
+                    log.info("开始同步项目名");
+                    JSONArray criterias = new JSONArray();
+                    for (String pjId : ProPasCache.nameMap.keySet()) {
+                        JSONObject obj = new JSONObject();
+                        obj.put("projectId",pjId);
+                        obj.put("projectLocalName",ProPasCache.nameMap.get(pjId));
+                        criterias.add(obj);
+                    }
+                    JSONObject inserJson = new JSONObject();
+                    inserJson.put("criterias",criterias);
+                    log.info("数据:"+inserJson.toString());
+                    exchange.getIn().setBody(inserJson.toString());
+                    exchange.getIn().setHeader(Exchange.HTTP_URI, InitEnvRoute.venders+"/auxiliary/project/create?method=POST");
+                    log.info(InitEnvRoute.venders+"/auxiliary/project/create?method=POST");
+                })
+                .to(InitEnvRoute.venders+"/auxiliary/project/create");
     }
 
 

+ 1 - 1
src/main/resources/prod/config.properties

@@ -1,4 +1,4 @@
 dataPlatform.baseUrl=http://localhost:8888/data-platform-3
 #vendersÄÚÍøµØÖ·
-venders.baseUrl=http://172.17.134.222:8888/venders
+venders.baseUrl=http://localhost:8888/venders