|
| 1 | +/* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +using Amazon.Runtime; |
| 17 | +using Amazon.Runtime.Internal; |
| 18 | +using Amazon.Runtime.Internal.Transform; |
| 19 | +using Amazon.Runtime.Internal.Util; |
| 20 | +using Amazon.Util; |
| 21 | +using System; |
| 22 | +using System.Collections.Generic; |
| 23 | +using System.Formats.Cbor; |
| 24 | +using System.IO; |
| 25 | +using System.Net; |
| 26 | + |
| 27 | +namespace AWSSDK.Extensions.CborProtocol.Internal.Transform |
| 28 | +{ |
| 29 | + public abstract class CborResponseUnmarshaller : ResponseUnmarshaller |
| 30 | + { |
| 31 | + public override AmazonWebServiceResponse Unmarshall(UnmarshallerContext input) |
| 32 | + { |
| 33 | + CborUnmarshallerContext context = input as CborUnmarshallerContext; |
| 34 | + if (context == null) |
| 35 | + throw new InvalidOperationException("Unsupported UnmarshallerContext"); |
| 36 | + |
| 37 | + string requestId = context.ResponseData.GetHeaderValue(HeaderKeys.RequestIdHeader); |
| 38 | + try |
| 39 | + { |
| 40 | + var response = Unmarshall(context); |
| 41 | + response.ResponseMetadata = new ResponseMetadata(); |
| 42 | + response.ResponseMetadata.RequestId = requestId; |
| 43 | + return response; |
| 44 | + } |
| 45 | + catch (Exception e) |
| 46 | + { |
| 47 | + throw new AmazonUnmarshallingException(requestId, context.CurrentPath, e, context.ResponseData.StatusCode); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + public override AmazonServiceException UnmarshallException(UnmarshallerContext input, Exception innerException, HttpStatusCode statusCode) |
| 52 | + { |
| 53 | + CborUnmarshallerContext context = input as CborUnmarshallerContext; |
| 54 | + if (context == null) |
| 55 | + throw new InvalidOperationException("Unsupported UnmarshallerContext"); |
| 56 | + var responseException = UnmarshallException(context, innerException, statusCode); |
| 57 | + responseException.RequestId = context.ResponseData.GetHeaderValue(HeaderKeys.RequestIdHeader); |
| 58 | + return responseException; |
| 59 | + } |
| 60 | + |
| 61 | + public abstract AmazonWebServiceResponse Unmarshall(CborUnmarshallerContext input); |
| 62 | + |
| 63 | + public abstract AmazonServiceException UnmarshallException(CborUnmarshallerContext input, Exception innerException, HttpStatusCode statusCode); |
| 64 | + |
| 65 | + protected override UnmarshallerContext ConstructUnmarshallerContext(Stream responseStream, bool maintainResponseBody, IWebResponseData response, bool isException) |
| 66 | + { |
| 67 | + return new CborUnmarshallerContext(responseStream, maintainResponseBody, response, isException, null); |
| 68 | + } |
| 69 | + |
| 70 | + protected override UnmarshallerContext ConstructUnmarshallerContext(Stream responseStream, bool maintainResponseBody, IWebResponseData response, bool isException, IRequestContext requestContext) |
| 71 | + { |
| 72 | + return new CborUnmarshallerContext(responseStream, maintainResponseBody, response, isException, requestContext); |
| 73 | + } |
| 74 | + } |
| 75 | +} |
0 commit comments