Exemple #1
0
        public void ListPresetsMarshallTest()
        {
            var operation = service_model.FindOperation("ListPresets");

            var request    = InstantiateClassGenerator.Execute <ListPresetsRequest>();
            var marshaller = new ListPresetsRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            RequestValidator.Validate("ListPresets", request, internalRequest, service_model);

            var webResponse = new WebResponseData
            {
                Headers =
                {
                    { "x-amzn-RequestId", Guid.NewGuid().ToString() },
                    { "x-amz-crc32",      "0"                       }
                }
            };

            var payloadResponse = new JsonSampleGenerator(service_model, operation.ResponseStructure).Execute();

            webResponse.Headers.Add("Content-Length", UTF8Encoding.UTF8.GetBytes(payloadResponse).Length.ToString());
            var context = new JsonUnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, webResponse);
            ResponseUnmarshaller unmarshaller = ListPresetsResponseUnmarshaller.Instance;
            var response = unmarshaller.Unmarshall(context)
                           as ListPresetsResponse;

            InstantiateClassGenerator.ValidateObjectFullyInstantiated(response);
        }
        private bool HandleSuppressed404(IExecutionContext executionContext, IWebResponseData httpErrorResponse)
        {
            IRequestContext  requestContext  = executionContext.RequestContext;
            IResponseContext responseContext = executionContext.ResponseContext;

            if (httpErrorResponse != null && httpErrorResponse.StatusCode == HttpStatusCode.NotFound && requestContext.Request.Suppress404Exceptions)
            {
                using (httpErrorResponse.ResponseBody)
                {
                    ResponseUnmarshaller unmarshaller = requestContext.Unmarshaller;
                    bool readEntireResponse           = requestContext.ClientConfig.LogResponse || AWSConfigs.LoggingConfig.LogResponses != ResponseLoggingOption.Never;
                    UnmarshallerContext input         = unmarshaller.CreateContext(httpErrorResponse, readEntireResponse, httpErrorResponse.ResponseBody.OpenResponse(), requestContext.Metrics);
                    try
                    {
                        responseContext.Response = unmarshaller.Unmarshall(input);
                        responseContext.Response.ContentLength  = httpErrorResponse.ContentLength;
                        responseContext.Response.HttpStatusCode = httpErrorResponse.StatusCode;
                        return(true);
                    }
                    catch (Exception exception)
                    {
                        base.Logger.Debug(exception, "Failed to unmarshall 404 response when it was supressed.");
                    }
                }
            }
            return(false);
        }
        public void SynthesizeSpeechMarshallTest()
        {
            var operation = service_model.FindOperation("SynthesizeSpeech");

            var request    = InstantiateClassGenerator.Execute <SynthesizeSpeechRequest>();
            var marshaller = new SynthesizeSpeechRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            RequestValidator.Validate("SynthesizeSpeech", request, internalRequest, service_model);

            var webResponse = new WebResponseData
            {
                Headers =
                {
                    { "Content-Type",             "Content-Type_Value"                                },
                    { "x-amzn-RequestCharacters", int.MaxValue.ToString(CultureInfo.InvariantCulture) },
                    { "x-amzn-RequestId",         Guid.NewGuid().ToString()                           },
                    { "x-amz-crc32",              "0"                                                 }
                }
            };

            var payloadResponse = new JsonSampleGenerator(service_model, operation.ResponseStructure).Execute();

            webResponse.Headers.Add("Content-Length", UTF8Encoding.UTF8.GetBytes(payloadResponse).Length.ToString());
            var context = new JsonUnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, webResponse);
            ResponseUnmarshaller unmarshaller = SynthesizeSpeechResponseUnmarshaller.Instance;
            var response = unmarshaller.Unmarshall(context)
                           as SynthesizeSpeechResponse;

            InstantiateClassGenerator.ValidateObjectFullyInstantiated(response);
        }
Exemple #4
0
        public void InvokeEndpointMarshallTest()
        {
            var operation = service_model.FindOperation("InvokeEndpoint");

            var request    = InstantiateClassGenerator.Execute <InvokeEndpointRequest>();
            var marshaller = new InvokeEndpointRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            TestTools.RequestValidator.Validate("InvokeEndpoint", request, internalRequest, service_model);

            var webResponse = new WebResponseData
            {
                Headers =
                {
                    { "Content-Type",                       "Content-Type_Value"                       },
                    { "X-Amzn-SageMaker-Custom-Attributes", "X-Amzn-SageMaker-Custom-Attributes_Value" },
                    { "x-Amzn-Invoked-Production-Variant",  "x-Amzn-Invoked-Production-Variant_Value"  },
                    { "x-amzn-RequestId",                   Guid.NewGuid().ToString()                  },
                    { "x-amz-crc32",                        "0"                                        }
                }
            };

            var payloadResponse = new JsonSampleGenerator(service_model, operation.ResponseStructure).Execute();

            webResponse.Headers["Content-Length"] = UTF8Encoding.UTF8.GetBytes(payloadResponse).Length.ToString();
            var context = new JsonUnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, webResponse);
            ResponseUnmarshaller unmarshaller = InvokeEndpointResponseUnmarshaller.Instance;
            var response = unmarshaller.Unmarshall(context) as InvokeEndpointResponse;

            InstantiateClassGenerator.ValidateObjectFullyInstantiated(response);
        }
        internal WebRequestState(IRequest request, ResponseUnmarshaller unmarshaller, AbstractAWSSigner signer)
        {
            this.Request      = request;
            this.Unmarshaller = unmarshaller;
            this.Signer       = signer;

            this._stopWatch = Stopwatch.StartNew();
            this._stopWatch.Start();

            this.Metrics = new RequestMetrics();
        }
        internal WebRequestState(IRequest request, ResponseUnmarshaller unmarshaller, AbstractAWSSigner signer)
        {
            this.Request = request;
            this.Unmarshaller = unmarshaller;
            this.Signer = signer;

            this._stopWatch = Stopwatch.StartNew();
            this._stopWatch.Start();

            this.Metrics = new RequestMetrics();
        }
        protected System.Threading.Tasks.Task <TResponse> InvokeAsync <TRequest, TResponse>(
            TRequest request,
            IMarshaller <IRequest, AmazonWebServiceRequest> marshaller,
            ResponseUnmarshaller unmarshaller,
            System.Threading.CancellationToken cancellationToken)
            where TRequest : AmazonWebServiceRequest
            where TResponse : AmazonWebServiceResponse, new()
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = marshaller;
            options.ResponseUnmarshaller = unmarshaller;
            return(InvokeAsync <TResponse>(request, options, cancellationToken));
        }
Exemple #8
0
        // Constructor
        internal AsyncResult(IRequest request, AsyncCallback callback, object state, bool completeSynchronized, AbstractAWSSigner signer, ResponseUnmarshaller unmarshaller)
        {
            this.Request = request;
            this.Callback = callback;
            this.State = state;
            this.CompletedSynchronously = completeSynchronized;
            this.Signer = signer;
            this.Unmarshaller = unmarshaller;
            this.RequestName = request.OriginalRequest.GetType().Name;

            this._lockObj = new object();

            this._stopWatch = Stopwatch.StartNew();
            this._stopWatch.Start();
        }
        public override bool HandleException(IExecutionContext executionContext, HttpErrorResponseException exception)
        {
            IRequestContext  requestContext = executionContext.RequestContext;
            IWebResponseData response       = exception.Response;

            if (HandleSuppressed404(executionContext, response))
            {
                return(false);
            }
            requestContext.Metrics.AddProperty(Metric.StatusCode, response.StatusCode);
            AmazonServiceException ex = null;

            try
            {
                using (response.ResponseBody)
                {
                    ResponseUnmarshaller unmarshaller       = requestContext.Unmarshaller;
                    bool readEntireResponse                 = true;
                    UnmarshallerContext unmarshallerContext = unmarshaller.CreateContext(response, readEntireResponse, response.ResponseBody.OpenResponse(), requestContext.Metrics);
                    try
                    {
                        ex = unmarshaller.UnmarshallException(unmarshallerContext, exception, response.StatusCode);
                    }
                    catch (Exception ex2)
                    {
                        if (ex2 is AmazonServiceException || ex2 is AmazonClientException)
                        {
                            throw;
                        }
                        string headerValue  = response.GetHeaderValue("x-amzn-RequestId");
                        string responseBody = unmarshallerContext.ResponseBody;
                        throw new AmazonUnmarshallingException(headerValue, null, responseBody, ex2);
                    }
                    requestContext.Metrics.AddProperty(Metric.AWSRequestID, ex.RequestId);
                    requestContext.Metrics.AddProperty(Metric.AWSErrorCode, ex.ErrorCode);
                    if (requestContext.ClientConfig.LogResponse || AWSConfigs.LoggingConfig.LogResponses != 0)
                    {
                        base.Logger.Error(ex, "Received error response: [{0}]", unmarshallerContext.ResponseBody);
                    }
                }
            }
            catch (Exception exception2)
            {
                base.Logger.Error(exception2, "Failed to unmarshall a service error response.");
                throw;
            }
            throw ex;
        }
Exemple #10
0
        public void PostContentMarshallTest()
        {
            var operation = service_model.FindOperation("PostContent");

            var request    = InstantiateClassGenerator.Execute <PostContentRequest>();
            var marshaller = new PostContentRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            TestTools.RequestValidator.Validate("PostContent", request, internalRequest, service_model);

            var webResponse = new WebResponseData
            {
                Headers =
                {
                    { "Content-Type",                 "Content-Type_Value"                                                                 },
                    { "x-amz-lex-dialog-state",       "x-amz-lex-dialog-state_Value"                                                       },
                    { "x-amz-lex-input-transcript",   "x-amz-lex-input-transcript_Value"                                                   },
                    { "x-amz-lex-intent-name",        "x-amz-lex-intent-name_Value"                                                        },
                    { "x-amz-lex-message",            "x-amz-lex-message_Value"                                                            },
                    { "x-amz-lex-message-format",     "x-amz-lex-message-format_Value"                                                     },
                    { "x-amz-lex-sentiment",          "x-amz-lex-sentiment_Value"                                                          },
                    { "x-amz-lex-session-attributes", Convert.ToBase64String(Encoding.UTF8.GetBytes("x-amz-lex-session-attributes_Value")) },
                    { "x-amz-lex-session-id",         "x-amz-lex-session-id_Value"                                                         },
                    { "x-amz-lex-slots",              Convert.ToBase64String(Encoding.UTF8.GetBytes("x-amz-lex-slots_Value"))              },
                    { "x-amz-lex-slot-to-elicit",     "x-amz-lex-slot-to-elicit_Value"                                                     },
                    { "x-amzn-RequestId",             Guid.NewGuid().ToString()                                                            },
                    { "x-amz-crc32",                  "0"                                                                                  }
                }
            };

            var payloadResponse = new JsonSampleGenerator(service_model, operation.ResponseStructure).Execute();

            webResponse.Headers["Content-Length"] = UTF8Encoding.UTF8.GetBytes(payloadResponse).Length.ToString();
            var context = new JsonUnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, webResponse);
            ResponseUnmarshaller unmarshaller = PostContentResponseUnmarshaller.Instance;
            var response = unmarshaller.Unmarshall(context)
                           as PostContentResponse;

            InstantiateClassGenerator.ValidateObjectFullyInstantiated(response);
        }
        public void AddEventSourceMarshallTestForDataTypeCustomization()
        {
            var operation = service_model.FindOperation("AddEventSource");

            var request    = InstantiateClassGenerator.Execute <AddEventSourceRequest>();
            var marshaller = new AddEventSourceRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            RequestValidator.Validate("AddEventSource", request, internalRequest, service_model);

            var webResponse = new WebResponseData
            {
                Headers =
                {
                    { "x-amzn-RequestId", Guid.NewGuid().ToString() },
                    { "x-amz-crc32",      "0"                       }
                }
            };

            var payloadResponse = new JsonSampleGenerator(service_model, operation.ResponseStructure).Execute();

            // The service returns IsActive as a string and it's unmarshalled as a bool to set the
            // AddEventSourceResponse.IsActive bool property.
            if (payloadResponse.Contains("\"IsActive\"     : true"))
            {
                payloadResponse = payloadResponse.Replace("\"IsActive\"     : true", "\"IsActive\"     : \"true\"");
            }
            else
            {
                throw new InvalidOperationException("Could not replace json in sample response");
            }

            webResponse.Headers.Add("Content-Length", UTF8Encoding.UTF8.GetBytes(payloadResponse).Length.ToString());
            var context = new JsonUnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, webResponse);
            ResponseUnmarshaller unmarshaller = AddEventSourceResponseUnmarshaller.Instance;
            var response = unmarshaller.Unmarshall(context)
                           as AddEventSourceResponse;

            InstantiateClassGenerator.ValidateObjectFullyInstantiated(response);
        }
Exemple #12
0
        private void Unmarshall(IExecutionContext executionContext)
        {
            IRequestContext  requestContext  = executionContext.RequestContext;
            IResponseContext responseContext = executionContext.ResponseContext;

            using (requestContext.Metrics.StartEvent(Metric.ResponseProcessingTime))
            {
                ResponseUnmarshaller unmarshaller = requestContext.Unmarshaller;
                try
                {
                    bool supportsResponseLogging            = _supportsResponseLogging;
                    UnmarshallerContext unmarshallerContext = unmarshaller.CreateContext(responseContext.HttpResponse, supportsResponseLogging, responseContext.HttpResponse.ResponseBody.OpenResponse(), requestContext.Metrics);
                    try
                    {
                        AmazonWebServiceResponse amazonWebServiceResponse2 = responseContext.Response = UnmarshallResponse(unmarshallerContext, requestContext);
                    }
                    catch (Exception ex)
                    {
                        if (ex is AmazonServiceException || ex is AmazonClientException)
                        {
                            throw;
                        }
                        string headerValue  = responseContext.HttpResponse.GetHeaderValue("x-amzn-RequestId");
                        string responseBody = unmarshallerContext.ResponseBody;
                        throw new AmazonUnmarshallingException(headerValue, null, responseBody, ex);
                    }
                }
                finally
                {
                    if (!unmarshaller.HasStreamingProperty)
                    {
                        responseContext.HttpResponse.ResponseBody.Dispose();
                    }
                }
            }
        }
        public void GetObjectMarshallTest()
        {
            var operation = service_model.FindOperation("GetObject");

            var request    = InstantiateClassGenerator.Execute <GetObjectRequest>();
            var marshaller = new GetObjectRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            TestTools.RequestValidator.Validate("GetObject", request, internalRequest, service_model);

            var webResponse = new WebResponseData
            {
                Headers =
                {
                    { "Cache-Control",    "Cache-Control_Value"                                },
                    { "Content-Length",   long.MaxValue.ToString(CultureInfo.InvariantCulture) },
                    { "Content-Range",    "Content-Range_Value"                                },
                    { "Content-Type",     "Content-Type_Value"                                 },
                    { "ETag",             "ETag_Value"                                         },
                    { "Last-Modified",    ValidatorUtils.GetTestDate(TimestampFormat.RFC822)   },
                    { "x-amzn-RequestId", Guid.NewGuid().ToString()                            },
                    { "x-amz-crc32",      "0"                                                  }
                }
            };

            var payloadResponse = new JsonSampleGenerator(service_model, operation.ResponseStructure).Execute();

            webResponse.Headers["Content-Length"] = UTF8Encoding.UTF8.GetBytes(payloadResponse).Length.ToString();
            var context = new JsonUnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, webResponse);
            ResponseUnmarshaller unmarshaller = GetObjectResponseUnmarshaller.Instance;
            var response = unmarshaller.Unmarshall(context)
                           as GetObjectResponse;

            InstantiateClassGenerator.ValidateObjectFullyInstantiated(response);
        }
        protected TResponse Invoke <TRequest, TResponse>(TRequest request,
                                                         IMarshaller <IRequest, AmazonWebServiceRequest> marshaller, ResponseUnmarshaller unmarshaller)
            where TRequest : AmazonWebServiceRequest
            where TResponse : AmazonWebServiceResponse
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = marshaller;
            options.ResponseUnmarshaller = unmarshaller;
            return(Invoke <TResponse>(request, options));
        }
Exemple #15
0
        protected IAsyncResult BeginInvoke <TRequest>(TRequest request,
                                                      IMarshaller <IRequest, AmazonWebServiceRequest> marshaller, ResponseUnmarshaller unmarshaller,
                                                      AsyncCallback callback, object state)
            where TRequest : AmazonWebServiceRequest
        {
            ThrowIfDisposed();

            var executionContext = new AsyncExecutionContext(
                new AsyncRequestContext(this.Config.LogMetrics, Signer)
            {
                ClientConfig    = this.Config,
                Marshaller      = marshaller,
                OriginalRequest = request,
                Unmarshaller    = unmarshaller,
                Callback        = callback,
                State           = state,
                IsAsync         = true,
                ServiceMetaData = this.ServiceMetadata
            },
                new AsyncResponseContext()
                );

            SetupCSMHandler(executionContext.RequestContext);
            var asyncResult = this.RuntimePipeline.InvokeAsync(executionContext);

            return(asyncResult);
        }
Exemple #16
0
        protected IAsyncResult BeginInvoke <TRequest>(TRequest request,
                                                      IMarshaller <IRequest, AmazonWebServiceRequest> marshaller, ResponseUnmarshaller unmarshaller, AsyncOptions asyncOptions,
                                                      Action <AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper)
            where TRequest : AmazonWebServiceRequest
        {
            ThrowIfDisposed();

            asyncOptions = asyncOptions ?? new AsyncOptions();
            var executionContext = new AsyncExecutionContext(
                new AsyncRequestContext(this.Config.LogMetrics, Signer)
            {
                ClientConfig    = this.Config,
                Marshaller      = marshaller,
                OriginalRequest = request,
                Unmarshaller    = unmarshaller,
                Action          = callbackHelper,
                AsyncOptions    = asyncOptions,
                IsAsync         = true,
                ServiceMetaData = this.ServiceMetadata
            },
                new AsyncResponseContext()
                );

            return(this.RuntimePipeline.InvokeAsync(executionContext));
        }
Exemple #17
0
        protected TResponse Invoke <TRequest, TResponse>(TRequest request,
                                                         IMarshaller <IRequest, AmazonWebServiceRequest> marshaller, ResponseUnmarshaller unmarshaller)
            where TRequest : AmazonWebServiceRequest
            where TResponse : AmazonWebServiceResponse
        {
            ThrowIfDisposed();

            var executionContext = new ExecutionContext(
                new RequestContext(this.Config.LogMetrics, Signer)
            {
                ClientConfig    = this.Config,
                Marshaller      = marshaller,
                OriginalRequest = request,
                Unmarshaller    = unmarshaller,
                IsAsync         = false,
                ServiceMetaData = this.ServiceMetadata
            },
                new ResponseContext()
                );

            SetupCSMHandler(executionContext.RequestContext);
            var response = (TResponse)this.RuntimePipeline.InvokeSync(executionContext).Response;

            return(response);
        }
        protected virtual IExecutionContext CreateTestContext(AbstractAWSSigner signer, ResponseUnmarshaller responseUnmarshaller, ClientConfig config)
        {
            var putObjectRequest = new PutObjectRequest
            {
                Key         = "TestKey",
                BucketName  = "TestBucket",
                ContentBody = "Test Content"
            };

            if (responseUnmarshaller == null)
            {
                responseUnmarshaller = PutObjectResponseUnmarshaller.Instance;
            }

            var requestContext = new RequestContext(true, signer == null ? new NullSigner() : signer)
            {
                OriginalRequest = putObjectRequest,
                Request         = new PutObjectRequestMarshaller().Marshall(putObjectRequest),
                Unmarshaller    = responseUnmarshaller,
                ClientConfig    = config ?? new AmazonS3Config
                {
                    RegionEndpoint = RegionEndpoint.USEast1
                }
            };

            requestContext.Request.Endpoint = new Uri("https://s3.amazonaws.com");

            var putObjectResponse = MockWebResponse.CreateFromResource("PutObjectResponse.txt")
                                    as HttpWebResponse;

            return(new Amazon.Runtime.Internal.ExecutionContext(requestContext,
                                                                new ResponseContext
            {
                HttpResponse = new HttpWebRequestResponseData(putObjectResponse)
            }));
        }
 protected virtual IExecutionContext CreateTestContext(AbstractAWSSigner signer, ResponseUnmarshaller responseUnmarshaller)
 {
     return(CreateTestContext(signer, responseUnmarshaller, null));
 }
 public AmazonSecurityTokenServiceException() : base(ResponseUnmarshaller.GetDefaultErrorMessage <AmazonSecurityTokenServiceException>())
 {
 }
Exemple #21
0
        // Constructor
        internal AsyncResult(IRequest request, AmazonWebServiceRequest originalRequest, AmazonServiceCallback callback, object state, AbstractAWSSigner signer, ResponseUnmarshaller unmarshaller)
        {
            this.Request  = request;
            this.Callback = callback;
            //this.State = state;
            //this.CompletedSynchronously = completeSynchronized;
            this.Signer       = signer;
            this.Unmarshaller = unmarshaller;

            if (request != null)
            {
                this.RequestName = request.OriginalRequest.GetType().Name;
            }

            this.Metrics = new RequestMetrics();

            //this._lockObj = new object();

            this._stopWatch = Stopwatch.StartNew();
            this._stopWatch.Start();
            this.ServiceResult = new AmazonServiceResult(originalRequest, state);
        }
        internal TResponse Invoke <TRequest, TResponse>(TRequest request,
                                                        IMarshaller <IRequest, WebServiceRequest> marshaller, ResponseUnmarshaller unmarshaller)
            where TRequest : WebServiceRequest
            where TResponse : WebServiceResponse
        {
            ThrowIfDisposed();

            var executionContext = new ExecutionContext(
                new RequestContext()
            {
                ClientConfig    = this.Config,
                Marshaller      = marshaller,
                OriginalRequest = request,
                Signer          = Signer,
                Unmarshaller    = unmarshaller,
                IsAsync         = false
            },
                new ResponseContext()
                );

            var response = (TResponse)this.RuntimePipeline.InvokeSync(executionContext).Response;

            return(response);
        }
Exemple #23
0
        protected IAsyncResult BeginInvoke <TRequest>(TRequest request,
                                                      IMarshaller <IRequest, AmazonWebServiceRequest> marshaller, ResponseUnmarshaller unmarshaller, AsyncOptions asyncOptions,
                                                      Action <AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper)
            where TRequest : AmazonWebServiceRequest
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = marshaller;
            options.ResponseUnmarshaller = unmarshaller;
            return(BeginInvoke(request, options, asyncOptions, callbackHelper));
        }
Exemple #24
0
        protected IAsyncResult Invoke <T, R>(R request, AsyncCallback callback, object state, bool synchronized, IMarshaller <T, R> marshaller, ResponseUnmarshaller unmarshaller, AbstractAWSSigner signer)
            where T : IRequest
            where R : AmazonWebServiceRequest
        {
            ProcessPreRequestHandlers(request);

            IRequest    irequest = marshaller.Marshall(request);
            AsyncResult result   = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller);

            Invoke(result);
            return(result);
        }
        protected Task <Res> Invoke <T, Req, Res>(Req request, IMarshaller <T, Req> marshaller, ResponseUnmarshaller unmarshaller, AbstractAWSSigner signer, CancellationToken cancellationToken = default(CancellationToken))
            where T : IRequest
            where Req : AmazonWebServiceRequest
            where Res : AmazonWebServiceResponse
        {
            ProcessPreRequestHandlers(request);

            IRequest irequest = marshaller.Marshall(request);

            WebRequestState state = new WebRequestState(irequest, unmarshaller, signer);

            state.Metrics.StartEvent(Metric.ClientExecuteTime);

            irequest.Endpoint = DetermineEndpoint(irequest);
            if (Config.LogMetrics)
            {
                state.Metrics.IsEnabled = true;
                state.Metrics.AddProperty(Metric.ServiceName, irequest.ServiceName);
                state.Metrics.AddProperty(Metric.ServiceEndpoint, irequest.Endpoint);
                state.Metrics.AddProperty(Metric.MethodName, irequest.RequestName);
            }
            ConfigureRequest(state);
            return(InvokeHelper <Res>(state, cancellationToken));
        }
Exemple #26
0
 public AmazonCognitoSyncException() : base(ResponseUnmarshaller.GetDefaultErrorMessage <AmazonCognitoSyncException>())
 {
 }
        protected IAsyncResult BeginInvoke <TRequest>(TRequest request,
                                                      IMarshaller <IRequest, AmazonWebServiceRequest> marshaller, ResponseUnmarshaller unmarshaller,
                                                      AsyncCallback callback, object state)
            where TRequest : AmazonWebServiceRequest
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = marshaller;
            options.ResponseUnmarshaller = unmarshaller;
            return(BeginInvoke(request, options, callback, state));
        }
        protected TResponse Invoke <TRequest, TResponse>(TRequest request, IMarshaller <IRequest, AmazonWebServiceRequest> marshaller, ResponseUnmarshaller unmarshaller) where TRequest : AmazonWebServiceRequest where TResponse : AmazonWebServiceResponse
        {
            ThrowIfDisposed();
            ExecutionContext executionContext = new ExecutionContext(new RequestContext(Config.LogMetrics)
            {
                ClientConfig    = Config,
                Marshaller      = marshaller,
                OriginalRequest = request,
                Signer          = Signer,
                Unmarshaller    = unmarshaller,
                IsAsync         = false
            }, new ResponseContext());

            return((TResponse)RuntimePipeline.InvokeSync(executionContext).Response);
        }
        protected System.Threading.Tasks.Task <TResponse> InvokeAsync <TRequest, TResponse>(TRequest request,
                                                                                            IMarshaller <IRequest, AmazonWebServiceRequest> marshaller, ResponseUnmarshaller unmarshaller,
                                                                                            System.Threading.CancellationToken cancellationToken)
            where TRequest : AmazonWebServiceRequest
            where TResponse : AmazonWebServiceResponse, new()
        {
            ThrowIfDisposed();

            var executionContext = new ExecutionContext(
                new RequestContext(this.Config.LogMetrics)
            {
                ClientConfig      = this.Config,
                Marshaller        = marshaller,
                OriginalRequest   = request,
                Signer            = Signer,
                Unmarshaller      = unmarshaller,
                IsAsync           = true,
                CancellationToken = cancellationToken
            },
                new ResponseContext()
                );

            return(this.RuntimePipeline.InvokeAsync <TResponse>(executionContext));
        }
        protected IAsyncResult BeginInvoke <TRequest>(TRequest request, IMarshaller <IRequest, AmazonWebServiceRequest> marshaller, ResponseUnmarshaller unmarshaller, AsyncCallback callback, object state) where TRequest : AmazonWebServiceRequest
        {
            ThrowIfDisposed();
            AsyncExecutionContext executionContext = new AsyncExecutionContext(new AsyncRequestContext(Config.LogMetrics)
            {
                ClientConfig    = Config,
                Marshaller      = marshaller,
                OriginalRequest = request,
                Signer          = Signer,
                Unmarshaller    = unmarshaller,
                Callback        = callback,
                State           = state,
                IsAsync         = true
            }, new AsyncResponseContext());

            return(RuntimePipeline.InvokeAsync(executionContext));
        }
        internal IAsyncResult BeginInvoke <TRequest>(TRequest request,
                                                     IMarshaller <IRequest, WebServiceRequest> marshaller, ResponseUnmarshaller unmarshaller,
                                                     AsyncCallback callback, object state)
            where TRequest : WebServiceRequest
        {
            ThrowIfDisposed();

            var executionContext = new AsyncExecutionContext(
                new AsyncRequestContext()
            {
                ClientConfig    = this.Config,
                Marshaller      = marshaller,
                OriginalRequest = request,
                Signer          = Signer,
                Unmarshaller    = unmarshaller,
                Callback        = callback,
                State           = state,
                IsAsync         = true
            },
                new AsyncResponseContext()
                );

            var asyncResult = this.RuntimePipeline.InvokeAsync(executionContext);

            return(asyncResult);
        }
Exemple #32
0
            // Constructor
            internal AsyncResult(IRequest request, AsyncCallback callback, object state, bool completeSynchronized, AbstractAWSSigner signer, ResponseUnmarshaller unmarshaller)
            {
                this.Request  = request;
                this.Callback = callback;
                this.State    = state;
                this.CompletedSynchronously = completeSynchronized;
                this.Signer       = signer;
                this.Unmarshaller = unmarshaller;
                this.RequestName  = request.OriginalRequest.GetType().Name;

                this._lockObj = new object();
            }