Browse Source

优化http节点

caixiaofeng 6 tháng trước cách đây
mục cha
commit
2dfb70709e

+ 24 - 9
flow-workflow/flow-workflow-entity/src/main/java/com/flow/entity/node/HttpNode.java

@@ -10,18 +10,15 @@ import lombok.Data;
 import lombok.EqualsAndHashCode;
 import org.flowable.bpmn.model.*;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 
 @EqualsAndHashCode(callSuper = true)
 @Data
 public class HttpNode extends Node {
     private String url;
     private String method;
-    private List<Map<String, String>> headers;
-    private List<Map<String, String>> body;
+    private List<Map<String, Object>> headers;
+    private List<Map<String, Object>> body;
     private Long requestTimeout = 0L;
     private Integer retryCount;
     private TimeUnitEnum unit = TimeUnitEnum.MINUTE;
@@ -67,20 +64,38 @@ public class HttpNode extends Node {
         try {
             ObjectMapper objectMapper = ApplicationContextUtil.getBean(ObjectMapper.class);
             if (CollectionUtils.isNotEmpty(this.headers)) {
-                String headers = objectMapper.writeValueAsString(this.headers);
+                Map<Object, Object> map = new HashMap<>();
+                for (Map<String, Object> header : this.headers) {
+                    Object label = header.get("label");
+                    Object value = header.get("value");
+                    if (Objects.nonNull(label) && Objects.nonNull(value)) {
+                        map.put(label, value);
+                    }
+                }
+                String headers = objectMapper.writeValueAsString(map);
                 FieldExtension headerExtension = new FieldExtension();
                 headerExtension.setFieldName("requestHeaders");
                 headerExtension.setExpression(headers);
                 fieldExtensions.add(headerExtension);
             }
             if (CollectionUtils.isNotEmpty(this.body)) {
-                String requestBody = objectMapper.writeValueAsString(this.body);
+                Map<Object, Object> map = new HashMap<>();
+                for (Map<String, Object> boy : this.body) {
+                    Object label = boy.get("label");
+                    Object value = boy.get("value");
+                    if (Objects.nonNull(label) && Objects.nonNull(value)) {
+                        map.put(label, value);
+                    }
+                }
+                String body = objectMapper.writeValueAsString(map);
+                String requestBody = objectMapper.writeValueAsString(body);
                 FieldExtension bodyExtension = new FieldExtension();
                 bodyExtension.setFieldName("requestBody");
                 bodyExtension.setExpression(requestBody);
                 fieldExtensions.add(bodyExtension);
             }
-        } catch (JsonProcessingException ignored) {}
+        } catch (JsonProcessingException ignored) {
+        }
         FieldExtension timeoutExtension = new FieldExtension();
         timeoutExtension.setFieldName("requestTimeout");
         timeoutExtension.setStringValue(this.requestTimeout.toString());