public void sendApiRequestAsync( Dictionary <object, object> context, RequestInputModel paramBean, ResponseCallBack callback) { string validate = paramBean != null?paramBean.validateParam() : ""; Config Config = (Config)context[Constant.CONFIG_CONTEXT_KEY]; string configValidate = Config.validateParam(); if (!StringUtil.isEmpty(validate) || !StringUtil.isEmpty(configValidate)) { if (StringUtil.isEmpty(validate)) { validate = configValidate; } OutputModel Out = ParamInvokeUtil.getOutputModel(callback); HttpRequestClient.fillResponseCallbackModel(Constant.REQUEST_ERROR_CODE, validate, Out); callback.onAPIResponse(Out); } else { HttpWebRequest request = buildRequest(context, paramBean); HttpRequestClient.getInstance() .requestActionAsync(request, Config.isSafeOkHttp(), callback); } }
public OutputModel sendApiRequest(Dictionary <object, object> context, RequestInputModel paramBean, Type outputClass) { string validate = paramBean != null?paramBean.validateParam() : ""; Config Config = (Config)context[Constant.CONFIG_CONTEXT_KEY]; string configValidate = Config.validateParam(); if (!StringUtil.isEmpty(validate) || !StringUtil.isEmpty(configValidate)) { if (StringUtil.isEmpty(validate)) { validate = configValidate; } try { OutputModel model = (OutputModel)Activator.CreateInstance(outputClass); HttpRequestClient.fillResponseCallbackModel(Constant.REQUEST_ERROR_CODE, validate, model); return(model); } catch (Exception e) { logger.Fatal(e.Message); throw new QCException(e.Message); } } else { HttpWebRequest request = buildRequest(context, paramBean); return(HttpRequestClient.getInstance().requestAction(request, Config.isSafeOkHttp(), outputClass)); } }
public void sendApiRequestAsync(String requestUrl, Dictionary <object, object> context, ResponseCallBack callback) { Config Config = (Config)context[Constant.CONFIG_CONTEXT_KEY]; HttpWebRequest request = HttpRequestClient.getInstance().buildUrlRequest(requestUrl); HttpRequestClient.getInstance().requestActionAsync(request, Config.isSafeOkHttp(), callback); }
public static HttpRequestClient getInstance() { if (ins == null) { ins = new HttpRequestClient(); } return(ins); }
public OutputModel sendApiRequest( string requestUrl, Dictionary <object, object> context, Type outputClass) { Config Config = (Config)context[Constant.CONFIG_CONTEXT_KEY]; HttpWebRequest request = HttpRequestClient.getInstance().buildUrlRequest(requestUrl); return(HttpRequestClient.getInstance() .requestAction(request, Config.isSafeOkHttp(), outputClass)); }
private HttpWebRequest buildRequest(Dictionary <object, object> context, RequestInputModel Params) { Config Config = (Config)context[Constant.CONFIG_CONTEXT_KEY]; string zone = (string)context[Constant.PARAM_KEY_REQUEST_ZONE]; Dictionary <object, object> paramsQuery = ParamInvokeUtil.getRequestParams(Params, Constant.PARAM_TYPE_QUERY); Dictionary <object, object> paramsBody = ParamInvokeUtil.getRequestParams(Params, Constant.PARAM_TYPE_BODY); Dictionary <object, object> paramsHeaders = ParamInvokeUtil.getRequestParams(Params, Constant.PARAM_TYPE_HEADER); paramsHeaders.Add("action", context["action"]); if (paramsHeaders.ContainsKey("zone")) { paramsHeaders["zone"] = zone; } else { paramsHeaders.Add("zone", zone); } if (context.ContainsKey(Constant.PARAM_KEY_USER_AGENT)) { paramsHeaders.Add(Constant.PARAM_KEY_USER_AGENT, context[Constant.PARAM_KEY_USER_AGENT]); } String requestApi = (String)context[Constant.PARAM_KEY_REQUEST_APINAME]; //string FileBody = GetBodyFile(context[Constant.PARAM_KEY_OBJECT_NAME].ToString()).ToString(); string method = (string)context[Constant.PARAM_KEY_REQUEST_METHOD]; string requestPath = Config.getHost() + Config.getUri(); string singedUrl = SignatureUtil.getURL( Config.getAccessKey(), Config.getAccessSecret(), method, requestPath, paramsQuery, paramsHeaders); singedUrl = Config.getProtocol() + "://" + singedUrl; logger.Info(singedUrl); //System.Console.WriteLine(singedUrl); HttpWebRequest request = HttpRequestClient.getInstance() .buildCloudRequest(method, paramsBody, singedUrl, paramsHeaders); return(request); }