public void Process(IHttpResponse webResponse, RestOperation operation) { try { using (var responseStream = webResponse.GetResponseStream()) { if (IsGzippedReponse(webResponse.Headers["Content-Encoding"])) { using (var gzipResponseStream = new GZipStream(responseStream, CompressionMode.Decompress)) { ProcessResponseStream(webResponse, gzipResponseStream, operation); } } else { ProcessResponseStream(webResponse, responseStream, operation); } } } catch(Exception e) { operation.Complete(null, new WebException(e.Message, e), webResponse.StatusCode, webResponse.StatusDescription, webResponse.Headers); } }
public void Process(IHttpResponse webResponse, RestOperation operation) { try { var responseStream = webResponse.GetResponseStream(); if (_builder.ServiceType == RestService.Binary) { ProcessResponseStream(webResponse, responseStream, operation); } else { using (responseStream) { if (IsGzippedReponse(webResponse.Headers["Content-Encoding"])) { using (var gzipResponseStream = new GZipStream(responseStream, CompressionMode.Decompress)) { ProcessResponseStream(webResponse, gzipResponseStream, operation); } } else { ProcessResponseStream(webResponse, responseStream, operation); } } } } catch (Exception e) { operation.Complete(null, new WebException(e.Message, e), webResponse.StatusCode, webResponse.StatusDescription, webResponse.Headers, null); } }
private void ProcessResponseStream(IHttpResponse webResponse, Stream responseStream, RestOperation operation) { if (webResponse.StatusCode == HttpStatusCode.OK || webResponse.StatusCode == HttpStatusCode.Created) { object result = _builder.ProcessResponse(responseStream); operation.Complete(result, null, webResponse.StatusCode, webResponse.StatusDescription, webResponse.Headers); } else { object result = _builder.ProcessResponse(responseStream); operation.Complete(result, new WebException(webResponse.StatusDescription), webResponse.StatusCode, webResponse.StatusDescription, webResponse.Headers); } }
private RestOperation PerformOperationAsync(string operationName, IProcessResponses responseProcessor, params object[] args) { JsonObject argsObject = null; if ((args != null) && (args.Length != 0)) { argsObject = (JsonObject)args[0]; } var operation = new RestOperation(); IHttpRequest webRequest = _requestBuilder.CreateRequest(operationName, argsObject); webRequest.BeginGetResponse(ar => InterpretResponse(responseProcessor, operation, () => webRequest.EndGetResponse(ar)), null); return(operation); }
private RestOperation PerformOperationAsync(string operationName, params object[] args) { JsonObject argsObject = null; if ((args != null) && (args.Length != 0)) { argsObject = (JsonObject)args[0]; } RestOperation operation = new RestOperation(); HttpWebRequest webRequest = CreateRequest(operationName, argsObject); webRequest.BeginGetResponse((ar) => { try { HttpWebResponse webResponse = (HttpWebResponse)webRequest.EndGetResponse(ar); if (webResponse.StatusCode == HttpStatusCode.OK) { Stream responseStream = webResponse.GetResponseStream(); try { object result = ProcessResponse(responseStream); operation.Complete(result, webResponse.StatusCode, webResponse.StatusDescription); } catch (Exception e) { operation.Complete(new WebException(e.Message, e), webResponse.StatusCode, webResponse.StatusDescription); } } else { operation.Complete(new WebException(webResponse.StatusDescription), webResponse.StatusCode, webResponse.StatusDescription); } } catch (WebException webException) { HttpWebResponse response = (HttpWebResponse)webException.Response; operation.Complete(webException, response.StatusCode, response.StatusDescription); } }, null); return(operation); }
private void InterpretResponse(IProcessResponses responseProcessor, RestOperation operation, Func <IHttpResponse> returnsResponse) { try { var webResponse = returnsResponse(); responseProcessor.Process(webResponse, operation); _responseHeaders.Add(webResponse.Headers); } catch (WebException webException) { if (webException.Status != WebExceptionStatus.ProtocolError) { throw; } var response = (HttpWebResponse)webException.Response; var responseWrapper = new HttpWebResponseWrapper(response); responseProcessor.Process(responseWrapper, operation); _responseHeaders.Add(response.Headers); } }
private RestOperation PerformOperationAsync(string operationName, params object[] args) { JsonObject argsObject = null; if ((args != null) && (args.Length != 0)) { argsObject = (JsonObject)args[0]; } RestOperation operation = new RestOperation(); Uri requestUri = CreateRequestUri(operationName, argsObject); HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(requestUri); webRequest.BeginGetResponse((ar) => { HttpWebResponse webResponse = (HttpWebResponse)webRequest.EndGetResponse(ar); if (webResponse.StatusCode == HttpStatusCode.OK) { Stream responseStream = webResponse.GetResponseStream(); try { object result = ProcessResponse(responseStream); operation.Complete(result, webResponse.StatusCode, webResponse.StatusDescription); } catch (Exception e) { operation.Complete(new WebException(e.Message, e), webResponse.StatusCode, webResponse.StatusDescription); } } else { operation.Complete(new WebException(webResponse.StatusDescription), webResponse.StatusCode, webResponse.StatusDescription); } }, null); return operation; }
private RestOperation PerformOperation(string operationName, params object[] args) { JsonObject argsObject = null; if ((args != null) && (args.Length != 0)) { argsObject = (JsonObject)args[0]; } RestOperation operation = new RestOperation(); IHttpRequest webRequest = CreateRequest(operationName, argsObject); try { IHttpResponse webResponse = webRequest.GetResponse(); _responseHeaders = webResponse.Headers; if (webResponse.StatusCode == HttpStatusCode.OK || webResponse.StatusCode == HttpStatusCode.Created) { Stream responseStream = webResponse.GetResponseStream(); try { object result = ProcessResponse(responseStream); operation.Complete(result, webResponse.StatusCode, webResponse.StatusDescription); } catch (Exception e) { operation.Complete(new WebException(e.Message, e), webResponse.StatusCode, webResponse.StatusDescription); } } else { operation.Complete(new WebException(webResponse.StatusDescription), webResponse.StatusCode, webResponse.StatusDescription); } } catch (WebException webException) { HttpWebResponse response = (HttpWebResponse)webException.Response; operation.Complete(webException, response.StatusCode, response.StatusDescription); } return operation; }
private RestOperation PerformOperationAsync(string operationName, IProcessResponses responseProcessor, params object[] args) { JsonObject argsObject = null; if ((args != null) && (args.Length != 0)) { argsObject = (JsonObject)args[0]; } var operation = new RestOperation(); IHttpRequest webRequest = _requestBuilder.CreateRequest(operationName, argsObject); webRequest.BeginGetResponse(ar => InterpretResponse(responseProcessor, operation, () => webRequest.EndGetResponse(ar)), null); return operation; }
private void InterpretResponse(IProcessResponses responseProcessor, RestOperation operation, Func<IHttpResponse> returnsResponse) { try { var webResponse = returnsResponse(); responseProcessor.Process(webResponse, operation); _responseHeaders.Add(webResponse.Headers); } catch (WebException webException) { if (webException.Status != WebExceptionStatus.ProtocolError) { throw; } var response = (HttpWebResponse) webException.Response; var responseWrapper = new HttpWebResponseWrapper(response); responseProcessor.Process(responseWrapper, operation); _responseHeaders.Add(response.Headers); } }
public FolderFactory(RestOperation response) { _response = response; }
private void ProcessResponseStream(IHttpResponse webResponse, Stream responseStream, RestOperation operation) { if (webResponse.StatusCode == HttpStatusCode.OK || webResponse.StatusCode == HttpStatusCode.Created) { BuilderResponse result = _builder.ProcessResponse(responseStream); operation.Complete(result.Result, null, webResponse.StatusCode, webResponse.StatusDescription, webResponse.Headers, result.ResponseText); } else { BuilderResponse result = _builder.ProcessResponse(responseStream); operation.Complete(result.Result, new WebException(webResponse.StatusDescription), webResponse.StatusCode, webResponse.StatusDescription, webResponse.Headers, result.ResponseText); } }
private RestOperation PerformOperation(string operationName, params object[] args) { JsonObject argsObject = null; if ((args != null) && (args.Length != 0)) { argsObject = (JsonObject)args[0]; } RestOperation operation = new RestOperation(); Uri requestUri = CreateRequestUri(operationName, argsObject); HttpWebRequest webRequest = CreateWebRequest(requestUri); try { HttpWebResponse webResponse = (HttpWebResponse)webRequest. GetResponse(); if (webResponse.StatusCode == HttpStatusCode.OK) { Stream responseStream = webResponse.GetResponseStream(); try { object result = ProcessResponse(responseStream); operation.Complete(result, webResponse.StatusCode, webResponse.StatusDescription); } catch (Exception e) { operation.Complete(new WebException(e.Message, e), webResponse.StatusCode, webResponse.StatusDescription); } } else { operation.Complete(new WebException(webResponse.StatusDescription), webResponse.StatusCode, webResponse.StatusDescription); } } catch (WebException e) { HttpWebResponse response = (HttpWebResponse)e.Response; if (e.Response != null) { operation.Complete(e, response.StatusCode, response.StatusDescription); } else { operation.Complete(e, HttpStatusCode.NotImplemented, "Unknown client error"); } } return operation; }