Explorar el Código

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/com/sagacloud/route/Route.java
FanXiaoyu hace 6 años
padre
commit
b3bbc8a31c

+ 12 - 0
src/main/java/com/sagacloud/Exceptions/InvalidPostException.java

@@ -0,0 +1,12 @@
+package com.sagacloud.Exceptions;
+/*
+ * Author: Jxing
+ * Create Time: 2018/7/12
+ */
+
+public class InvalidPostException extends Exception {
+    public InvalidPostException(String msg)
+    {
+        super(msg);
+    }
+}

+ 44 - 0
src/main/java/com/sagacloud/pojos/InsurancePost.java

@@ -0,0 +1,44 @@
+package com.sagacloud.pojos;
+/*
+ * Author: Jxing
+ * Create Time: 2018/7/12
+ */
+
+public class InsurancePost {
+    private String venderId;
+    private String projectId;
+    private String insuranceNo;
+    private boolean expire;
+
+    public String getVenderId() {
+        return venderId;
+    }
+
+    public void setVenderId(String venderId) {
+        this.venderId = venderId;
+    }
+
+    public String getProjectId() {
+        return projectId;
+    }
+
+    public void setProjectId(String projectId) {
+        this.projectId = projectId;
+    }
+
+    public String getInsuranceNo() {
+        return insuranceNo;
+    }
+
+    public void setInsuranceNo(String insuranceNo) {
+        this.insuranceNo = insuranceNo;
+    }
+
+    public boolean isExpire() {
+        return expire;
+    }
+
+    public void setExpire(boolean expire) {
+        this.expire = expire;
+    }
+}

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

@@ -1,6 +1,7 @@
 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;
@@ -67,6 +68,18 @@ public class Route extends RouteBuilder {
                 .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())

+ 16 - 0
src/main/java/com/sagacloud/route/processors/GetInsuranceNoListProcessor.java

@@ -5,12 +5,28 @@ package com.sagacloud.route.processors;
  */
 
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.sagacloud.Exceptions.InvalidPostException;
+import com.sagacloud.cache.ProPasCache;
+import com.sagacloud.pojos.InsurancePost;
+import com.sagacloud.route.InitEnvRoute;
+import com.sagacloud.utils.Const;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 
 public class GetInsuranceNoListProcessor implements Processor {
     @Override
     public void process(Exchange exchange) throws Exception {
+        String jsonStr = exchange.getIn().getBody(String.class);
+        InsurancePost post = JSONObject.parseObject(jsonStr, InsurancePost.class);
 
+        if(post.getVenderId() == null || post.getProjectId() == null || ProPasCache.getPjSecret(post.getProjectId()) == null)
+            throw new InvalidPostException("参数错误!");
+        //exchange.getIn().setBody();
+        exchange.setProperty("postParam", post);
+        exchange.getIn().setHeader(Exchange.HTTP_URI, String.join("", InitEnvRoute.venders, "/insurance/contract/query?method=POST"));
+        exchange.getIn().setHeader(Exchange.HTTP_QUERY,String.join("", Const.HEADER_PROJECT , "=", post.getProjectId(),
+                "&", Const.HEADER_SECRET, "=", ProPasCache.getPjSecret(post.getProjectId())));
     }
 }