首页 > 其他分享 >ProbeQueryTask

ProbeQueryTask

时间:2022-10-31 21:13:15浏览次数:36  
标签:ProbeQueryTask JSONObject param header import com public

 1 package com.*.it.regioc.task;
 2 
 3 import com.alibaba.fastjson.JSONObject;
 4 import com.*.it.regioc.bean.model.api.ApiParameter;
 5 import com.*.it.regioc.utils.HttpUtils;
 6 import lombok.extern.slf4j.Slf4j;
 7 import java.io.IOException;
 8 import java.util.Map;
 9 import java.util.concurrent.Callable;
10 
11 @Slf4j
12 public class ProbeQueryTask implements Callable<JSONObject> {
13     private final ApiParameter param;
14     private final Map<String, String> header;
15 
16     public ProbeQueryTask(ApiParameter param, Map<String, String> header) {
17         this.param = param;
18         this.header = header;
19     }
20 
21     private JSONObject execute() {
22         String url = param.getRequestUrl();
23         Object data = param.getRequestData();
24         String requestData = null;
25         if (data != null) {
26             requestData = JSONObject.toJSONString(data);
27         }
28         JSONObject result = null;
29         try {
30             String resultStr = HttpUtils.postRequest(url, requestData, header);
31             result = JSONObject.parseObject(resultStr);
32         } catch (IOException e) {
33             log.error("探针查询异常:{}", param, e);
34         }
35         return result;
36     }
37 
38     @Override
39     public JSONObject call() throws Exception {
40         System.err.println(param);
41         return execute();
42     }
43 
44     public ApiParameter getParam() {
45         return param;
46     }
47 }

 

标签:ProbeQueryTask,JSONObject,param,header,import,com,public
From: https://www.cnblogs.com/mingruifeng/p/16845800.html

相关文章