Forráskód Böngészése

!3 feat: http采集功能中增加post的body和content-type
* 增加http post内容

random-chat 4 éve
szülő
commit
ef0ba111cc

+ 11 - 1
collector/src/main/java/com/usthe/collector/collect/http/HttpCollectImpl.java

@@ -25,10 +25,12 @@ import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.client.methods.RequestBuilder;
 import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.BasicCredentialsProvider;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.util.EntityUtils;
 import org.springframework.http.HttpMethod;
+import org.springframework.util.StringUtils;
 
 import javax.net.ssl.SSLException;
 import java.io.IOException;
@@ -296,6 +298,9 @@ public class HttpCollectImpl extends AbstractCollect {
             log.error("not support the http method: {}.", httpProtocol.getMethod());
             return null;
         }
+
+        String contentType = null;
+
         // params
         Map<String, String> params = httpProtocol.getParams();
         if (params != null && !params.isEmpty()) {
@@ -303,6 +308,7 @@ public class HttpCollectImpl extends AbstractCollect {
                 requestBuilder.addParameter(param.getKey(), param.getValue());
             }
         }
+
         // headers
         Map<String, String> headers = httpProtocol.getHeaders();
         if (headers != null && !headers.isEmpty()) {
@@ -332,7 +338,11 @@ public class HttpCollectImpl extends AbstractCollect {
             String value = DispatchConstants.BEARER + " " + httpProtocol.getAuthorization().getBearerTokenToken();
             requestBuilder.addHeader(HttpHeaders.AUTHORIZATION, value);
         }
-        // todo 处理请求内容 body 暂不支持body
+
+        // 请求内容,会覆盖post协议的params
+        if(StringUtils.hasLength(httpProtocol.getPayload())){
+            requestBuilder.setEntity(new StringEntity(httpProtocol.getPayload(),"UTF-8"));
+        }
 
         // uri
         if (IpDomainUtil.isHasSchema(httpProtocol.getHost())) {

+ 5 - 0
common/src/main/java/com/usthe/common/entity/job/protocol/HttpProtocol.java

@@ -46,6 +46,11 @@ public class HttpProtocol {
      */
     private Map<String, String> params;
     /**
+     * http请求携带的请求体
+     */
+    private String payload;
+
+    /**
      * 认证信息
      */
     private Authorization authorization;

+ 1 - 0
manager/src/main/java/com/usthe/manager/service/impl/MonitorServiceImpl.java

@@ -169,6 +169,7 @@ public class MonitorServiceImpl implements MonitorService {
                             }
                             param.setType(CommonConstants.PARAM_TYPE_NUMBER);
                             break;
+                        case "textarea":
                         case "text":
                             Short limit = paramDefine.getLimit();
                             if (limit != null) {

+ 8 - 0
manager/src/main/resources/define/app/api.yml

@@ -20,6 +20,10 @@ configmap:
     type: 1
   - key: password
     type: 2
+  - key: contentType
+    type: 1
+  - key: payload
+    type: 1
 # 指标组列表
 metrics:
   # 第一个监控指标组 cpu
@@ -48,6 +52,10 @@ metrics:
       method: ^_^method^_^
       # 是否启用ssl/tls,即是http还是https,默认false
       ssl: ^_^ssl^_^
+      payload: ^_^payload^_^
+      # 请求头内容
+      headers:
+        content-type: ^_^contentType^_^
       # 认证
       authorization:
         # 认证方式: Basic Auth, Digest Auth, Bearer Token

+ 8 - 0
manager/src/main/resources/define/param/api.yml

@@ -37,6 +37,10 @@ param:
         value: PUT
       - label: DELETE请求
         value: DELETE
+  - field: contentType
+    name: Content-Type
+    type: text
+    required: false
   - field: username
     name: 用户名
     type: text
@@ -52,3 +56,7 @@ param:
     # 当type为boolean时,前端用switch展示开关
     type: boolean
     required: true
+  - field: payload
+    name: 请求BODY
+    type: textarea
+    required: false

+ 24 - 0
web-app/src/app/routes/monitor/monitor-edit/monitor-edit.component.html

@@ -63,6 +63,30 @@
           />
         </nz-form-control>
 
+
+        <nz-form-label
+          *ngIf="paramDefine.type === 'textarea'"
+          nzSpan="7"
+          [nzRequired]="paramDefine.required"
+          [nzFor]="paramDefine.field"
+        >{{ paramDefine.name }}
+        </nz-form-label>
+        <nz-form-control
+          *ngIf="paramDefine.type === 'textarea'"
+          nzSpan="8"
+          [nzErrorTip]="'validation.required' | i18n"
+        >
+          <textarea
+            nz-input
+            [(ngModel)]="params[i].value"
+            [required]="paramDefine.required"
+            [name]="paramDefine.field"
+            [id]="paramDefine.field"
+            [placeholder]="paramDefine.placeholder ? paramDefine.placeholder : ''"
+            rows="3"
+          ></textarea>
+        </nz-form-control>
+
         <nz-form-label *ngIf="paramDefine.type === 'password'" nzSpan="7" [nzRequired]="paramDefine.required" [nzFor]="paramDefine.field"
           >{{ paramDefine.name }}
         </nz-form-label>

+ 23 - 0
web-app/src/app/routes/monitor/monitor-new/monitor-new.component.html

@@ -72,6 +72,29 @@
           />
         </nz-form-control>
 
+        <nz-form-label
+          *ngIf="paramDefine.type === 'textarea'"
+          nzSpan="7"
+          [nzRequired]="paramDefine.required"
+          [nzFor]="paramDefine.field"
+        >{{ paramDefine.name }}
+        </nz-form-label>
+        <nz-form-control
+          *ngIf="paramDefine.type === 'textarea'"
+          nzSpan="8"
+          [nzErrorTip]="'validation.required' | i18n"
+        >
+          <textarea
+            nz-input
+            [(ngModel)]="params[i].value"
+            [required]="paramDefine.required"
+            [name]="paramDefine.field"
+            [id]="paramDefine.field"
+            [placeholder]="paramDefine.placeholder ? paramDefine.placeholder : ''"
+            rows="3"
+          ></textarea>
+        </nz-form-control>
+
         <nz-form-label *ngIf="paramDefine.type === 'password'" nzSpan="7" [nzRequired]="paramDefine.required" [nzFor]="paramDefine.field"
           >{{ paramDefine.name }}
         </nz-form-label>