首页 > 其他分享 >ShiPinThreadHandleRequest

ShiPinThreadHandleRequest

时间:2022-10-28 21:14:37浏览次数:50  
标签:Map JSONObject FinalFieldName headerMap import ShiPinThreadHandleRequest paramet

import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;

public class ShiPinThreadHandleRequest implements Callable<JSONObject> {
    private  JSONObject parameter;
    public ShiPinThreadHandleRequest(JSONObject parameter,RestUtils restUtils) throws JSONException {
        this.parameter=parameter;
        try {
            String requesType = this.parameter.getString(FinalFieldName.REQUESTYPE);
            Object paramData = (Object)this.parameter.get(FinalFieldName.PARAMDATA);
            JSONObject object = (JSONObject)JSONObject.toJSON(paramData);
            String paramJson = object.toJSONString();
            Map<String, String> headerMap = buildHeader();
            String HtmlJson = null;
            if(FinalFieldName.GET.equals(requesType)){
                HtmlJson=restUtils.get(this.parameter.getString(FinalFieldName.REQUESTURL),headerMap.toString());
            }
            if(FinalFieldName.POST.equals(requesType)){
                HtmlJson=restUtils.post(this.parameter.getString(FinalFieldName.REQUESTURL),paramJson,headerMap);
            }
            // 统一返回结果
            this.parameter.put(FinalFieldName.APIVALUE,HtmlJson);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

    public JSONObject call() throws Exception {
        return this.parameter;
    }

    private Map<String, String> buildHeader() {
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
        headerMap.put("X-HW-APPKEY", "czyImZk1LvPcP+m+BgmyzA==");
        headerMap.put("X-HW-ID", "app_000000035085");
        return headerMap;
    }
}

 

标签:Map,JSONObject,FinalFieldName,headerMap,import,ShiPinThreadHandleRequest,paramet
From: https://www.cnblogs.com/mingruifeng/p/16837492.html

相关文章