1 import com.alibaba.fastjson.JSONException;
2 import com.alibaba.fastjson.JSONObject;
3 import javax.ws.rs.core.HttpHeaders;
4 import javax.ws.rs.core.MediaType;
5 import java.util.HashMap;
6 import java.util.Map;
7 import java.util.concurrent.Callable;
8
9 public class ShiPinThreadHandleRequest implements Callable<JSONObject> {
10 private JSONObject parameter;
11 public ShiPinThreadHandleRequest(JSONObject parameter,RestUtils restUtils) throws JSONException {
12 this.parameter=parameter;
13 try {
14 String requesType = this.parameter.getString(FinalFieldName.REQUESTYPE);
15 Object paramData = (Object)this.parameter.get(FinalFieldName.PARAMDATA);
16 JSONObject object = (JSONObject)JSONObject.toJSON(paramData);
17 String paramJson = object.toJSONString();
18 Map<String, String> headerMap = buildHeader();
19 String HtmlJson = null;
20 if(FinalFieldName.GET.equals(requesType)){
21 HtmlJson=restUtils.get(this.parameter.getString(FinalFieldName.REQUESTURL),headerMap.toString());
22 }
23 if(FinalFieldName.POST.equals(requesType)){
24 HtmlJson=restUtils.post(this.parameter.getString(FinalFieldName.REQUESTURL),paramJson,headerMap);
25 }
26 // 统一返回结果
27 this.parameter.put(FinalFieldName.APIVALUE,HtmlJson);
28 }
29 catch(Exception e)
30 {
31 e.printStackTrace();
32 }
33 }
34
35 public JSONObject call() throws Exception {
36 return this.parameter;
37 }
38
39 private Map<String, String> buildHeader() {
40 Map<String, String> headerMap = new HashMap<>();
41 headerMap.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
42 headerMap.put("X-HW-APPKEY", "czyImZk1LvPcP+m+BgmyzA==");
43 headerMap.put("X-HW-ID", "app_000000035085");
44 return headerMap;
45 }
46 }
47