public void sendApiRequestAsync( Dictionary <object, object> context, RequestInputModel paramBean, ResponseCallBack callback) { string validate = paramBean != null?paramBean.validateParam() : ""; EvnContext evnContext = (EvnContext)context[QSConstant.EVN_CONTEXT_KEY]; string evnValidate = evnContext.validateParam(); if (!QSStringUtil.isEmpty(validate) || !QSStringUtil.isEmpty(evnValidate)) { if (QSStringUtil.isEmpty(validate)) { validate = evnValidate; } OutputModel Out = QSParamInvokeUtil.getOutputModel(callback); QSHttpRequestClient.fillResponseCallbackModel(QSConstant.REQUEST_ERROR_CODE, validate, Out); callback.onAPIResponse(Out); } else { HttpWebRequest request = buildRequest(context, paramBean); QSHttpRequestClient.getInstance() .requestActionAsync(request, evnContext.isSafeOkHttp(), callback); } }
public void testSignature() { ParamTestModel instancesInput = new ParamTestModel(); instancesInput.setAction("TestAction"); List <String> imgs = new List <String>(); imgs.Add("test-0001"); imgs.Add("test-0002"); instancesInput.setImageID(imgs); Dictionary <object, object> queryParam = QSParamInvokeUtil.getRequestParams(instancesInput, QSConstant.PARAM_TYPE_QUERY); /*https://api.qc.dev/iaas?access_key_id=QYACCESSKEYIDEXAMPLE&image_id.0=test-0001&image_id.1=test-0002& * // search_word=serch_word_test&signature_method=HmacSHA256&signature_version=1& * // time_stamp=2016-12-02T13%3A07%3A16Z&version=1&signature=r%2FR9TmmnZQWhkEi1gQy5qV9wEPjoJYi9QHSKzliq2eg%3D */ String d = QSSignatureUtil.formatGmtDate(DateTime.Now); String url = QSSignatureUtil.getAuth( "QYACCESSKEYIDEXAMPLE", "wudajefiLSJDWIFJLSD", "GET", "objectTest", queryParam, null); Assert.AreEqual(url.IndexOf("QS QYACCESSKEYIDEXAMPLE:") >= 0, true); }
public virtual OutputModel requestActionAsync(HttpWebRequest request, Boolean bSafe, ResponseCallBack callBack) { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); try { if (callBack != null) { OutputModel m = QSParamInvokeUtil.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); }
public void testClassToModel() { Object outmodel = null; try { outmodel = QSParamInvokeUtil.getOutputModel(typeof(Bucket.PutBucketACLOutput)); } catch (Exception e) { Console.WriteLine(e.Message); } Assert.AreEqual(outmodel.GetType().Name, typeof(Bucket.PutBucketACLOutput).Name); }
private void onOkhttpFailure(String message, ResponseCallBack callBack) { try { if (callBack != null) { OutputModel m = QSParamInvokeUtil.getOutputModel(callBack); fillResponseCallbackModel(QSConstant.REQUEST_ERROR_CODE, message, m); callBack.onAPIResponse(m); } } catch (Exception ee) { logger.Fatal(ee.Message); throw new Exception(ee.Message); } }
public void testParam() { ParamTestModel instancesInput = new ParamTestModel(); List <String> imgs = new List <String>(); imgs.Add("test-0001"); imgs.Add("test-0002"); instancesInput.setImageID(imgs); instancesInput.setAction("serch_word_test"); Dictionary <Object, Object> queryParam = QSParamInvokeUtil.getRequestParams(instancesInput, QSConstant.PARAM_TYPE_QUERY); Dictionary <Object, Object> bodyParam = QSParamInvokeUtil.getRequestParams( instancesInput, QSConstant.PARAM_TYPE_BODYINPUTSTREAM); Assert.AreEqual(queryParam["action"], "serch_word_test"); Assert.AreEqual(((List <String>)queryParam["image_id"])[1], "test-0002"); Assert.AreEqual(queryParam.Count, 2); Assert.AreEqual(bodyParam.Count, 0); }
/*private HttpWebResponse getRequestCall(Boolean bSafe,HttpWebRequest request) * { * if (bSafe) * { * return client * } else { * return this.unsafeClient.newCall(request); * } * }*/ public OutputModel requestAction(HttpWebRequest request, Boolean bSafe, Type outputClass) { HttpWebResponse response = null; try { OutputModel model = (OutputModel)QSParamInvokeUtil.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); }
public void testParamInvokeCapitalize() { String capitalize = QSParamInvokeUtil.capitalize("tttTtest"); Assert.AreEqual(capitalize, "TttTtest"); }
private HttpWebRequest buildRequest(Dictionary <object, object> context, RequestInputModel Params) { EvnContext evnContext = (EvnContext)context[QSConstant.EVN_CONTEXT_KEY]; string zone = (string)context[QSConstant.PARAM_KEY_REQUEST_ZONE]; Dictionary <object, object> paramsQuery = QSParamInvokeUtil.getRequestParams(Params, QSConstant.PARAM_TYPE_QUERY); Dictionary <object, object> paramsBody = QSParamInvokeUtil.getRequestParams(Params, QSConstant.PARAM_TYPE_BODY); Dictionary <object, object> paramsHeaders = QSParamInvokeUtil.getRequestParams(Params, QSConstant.PARAM_TYPE_HEADER); if (context.ContainsKey(QSConstant.PARAM_KEY_USER_AGENT)) { paramsHeaders.Add(QSConstant.PARAM_KEY_USER_AGENT, context[QSConstant.PARAM_KEY_USER_AGENT]); } String requestApi = (String)context[QSConstant.PARAM_KEY_REQUEST_APINAME]; //string FileBody = GetBodyFile(context[QSConstant.PARAM_KEY_OBJECT_NAME].ToString()).ToString(); paramsHeaders = initHeadContentMd5(requestApi, paramsBody, paramsHeaders); string method = (string)context[QSConstant.PARAM_KEY_REQUEST_METHOD]; string bucketName = (string)context[QSConstant.PARAM_KEY_BUCKET_NAME]; string requestPath = (string)context[QSConstant.PARAM_KEY_REQUEST_PATH]; string objectName = ""; if (context.ContainsKey(QSConstant.PARAM_KEY_OBJECT_NAME)) { objectName = context[QSConstant.PARAM_KEY_OBJECT_NAME].ToString(); } if (!paramsHeaders.ContainsKey(QSConstant.HEADER_PARAM_KEY_CONTENTTYPE)) { paramsHeaders.Add(QSConstant.HEADER_PARAM_KEY_CONTENTTYPE, MimeMapping.GetMimeMapping(objectName)); } if (context.ContainsKey(QSConstant.PARAM_KEY_OBJECT_NAME)) { requestPath = requestPath.Replace(QSConstant.BUCKET_NAME_REPLACE, bucketName); requestPath = requestPath.Replace(QSConstant.OBJECT_NAME_REPLACE, QSStringUtil.urlCharactersEncoding(objectName)); } else { requestPath = requestPath.Replace(QSConstant.BUCKET_NAME_REPLACE, bucketName + "/"); } string authSign = QSSignatureUtil.getAuth( evnContext.getAccessKey(), evnContext.getAccessSecret(), method, requestPath, paramsQuery, paramsHeaders); string requestSuffixPath = getRequestSuffixPath((string)context[QSConstant.PARAM_KEY_REQUEST_PATH], bucketName, objectName); paramsHeaders.Add("Authorization", authSign); logger.Info(authSign); string singedUrl = getSignedUrl( evnContext.getRequestUrl(), zone, bucketName, paramsQuery, requestSuffixPath); if (singedUrl.IndexOf("&upload_id") != -1)//?part_number=0&upload_id=1asfdsf { if (singedUrl.IndexOf("upload_id") > singedUrl.IndexOf("part_number")) { String temp1 = singedUrl.Substring(singedUrl.IndexOf("part_number"), singedUrl.IndexOf("&upload_id") - singedUrl.IndexOf("part_number")); String temp2 = singedUrl.Substring(singedUrl.IndexOf("upload_id"), singedUrl.Length - singedUrl.IndexOf("upload_id")); singedUrl = singedUrl.Substring(0, singedUrl.IndexOf("?") + 1) + temp2 + "&" + temp1; //singedUrl.Replace(temp1, temp2).Replace(temp2,temp1); } } logger.Info(singedUrl); if (QSConstant.PARAM_KEY_REQUEST_API_MULTIPART.Equals(requestApi)) { HttpWebRequest request = QSHttpRequestClient.getInstance() .buildStorMultiUpload( method, paramsBody, singedUrl, paramsHeaders, paramsQuery); return(request); } else { //System.Console.WriteLine(singedUrl); HttpWebRequest request = QSHttpRequestClient.getInstance() .buildStorRequest(method, paramsBody, singedUrl, paramsHeaders); return(request); } }