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 virtual OutputModel requestActionAsync(HttpWebRequest request, Boolean bSafe, ResponseCallBack callBack) { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); try { if (callBack != null) { OutputModel m = ParamInvokeUtil.getOutputModel(callBack); fillResponseValue2Object(response, m); callBack.onAPIResponse(m); } } catch (Exception e) { logger.Fatal(e.Message); onOkhttpFailure(e.Message, callBack); } finally { if (response != null) { response.Close(); } } return(null); }
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); }
private void onOkhttpFailure(String message, ResponseCallBack callBack) { try { if (callBack != null) { OutputModel m = ParamInvokeUtil.getOutputModel(callBack); fillResponseCallbackModel(Constant.REQUEST_ERROR_CODE, message, m); callBack.onAPIResponse(m); } } catch (Exception ee) { logger.Fatal(ee.Message); throw new Exception(ee.Message); } }
public OutputModel requestAction(HttpWebRequest request, Boolean bSafe, Type outputClass) { HttpWebResponse response = null; try { OutputModel model = (OutputModel)ParamInvokeUtil.getOutputModel(outputClass); response = (HttpWebResponse)request.GetResponse(); fillResponseValue2Object(response, model); return(model); } catch (WebException e) { logger.Fatal(e.Message); Stream stream = e.Response.GetResponseStream(); StreamReader st = new StreamReader(stream); string str = st.ReadToEnd(); System.Console.WriteLine(str); } return(null); }