/// <summary> /// Gets the response and modify the headers. /// </summary> /// <returns>The response.</returns> /// <param name="request">Request.</param> public override WebResponse getResponse(WebRequest request) { WebResponse response = base.getResponse(request); // // Only if Url matches // if (request.getUrl().toExternalForm().Contains("mb.aspx")) { string content = response.getContentAsString("UTF-8"); java.util.ArrayList newheaders = new java.util.ArrayList(); java.util.List headers = response.getResponseHeaders(); java.util.Iterator it = headers.iterator(); // // Remove the 'Access-Control-Allow-Origin' header // while (it.hasNext()) { com.gargoylesoftware.htmlunit.util.NameValuePair o = (com.gargoylesoftware.htmlunit.util.NameValuePair)it.next(); if (o.getName().Equals("Access-Control-Allow-Origin")) { string value = response.getResponseHeaderValue("Access-Control-Allow-Origin"); Console.WriteLine("Found header 'Access-Control-Allow-Origin' = \"{0}\" and stripping it from new headers for response", value); continue; //headers.remove(o); } newheaders.add(o); } byte[] utf = System.Text.Encoding.UTF8.GetBytes(content); WebResponseData data = new WebResponseData(utf, response.getStatusCode(), response.getStatusMessage(), newheaders); response = new WebResponse(data, request, response.getLoadTime()); return response; } return response; }
public void DeleteResourceShareMarshallTest() { var operation = service_model.FindOperation("DeleteResourceShare"); var request = InstantiateClassGenerator.Execute <DeleteResourceShareRequest>(); var marshaller = new DeleteResourceShareRequestMarshaller(); var internalRequest = marshaller.Marshall(request); TestTools.RequestValidator.Validate("DeleteResourceShare", 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["Content-Length"] = UTF8Encoding.UTF8.GetBytes(payloadResponse).Length.ToString(); var context = new JsonUnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, webResponse); ResponseUnmarshaller unmarshaller = DeleteResourceShareResponseUnmarshaller.Instance; var response = unmarshaller.Unmarshall(context) as DeleteResourceShareResponse; InstantiateClassGenerator.ValidateObjectFullyInstantiated(response); }
public void UpdateShardCountMarshallTest() { var request = InstantiateClassGenerator.Execute <UpdateShardCountRequest>(); var marshaller = new UpdateShardCountRequestMarshaller(); var internalRequest = marshaller.Marshall(request); var jsonRequest = UTF8Encoding.UTF8.GetString(internalRequest.Content); Comparer.CompareObjectToJson <UpdateShardCountRequest>(request, jsonRequest); var webResponse = new WebResponseData { Headers = { { "x-amzn-RequestId", Guid.NewGuid().ToString() }, { "x-amz-crc32", "0" } } }; var jsonResponse = new JsonSampleGenerator(service_model, service_model.FindOperation("UpdateShardCount").ResponseStructure).Execute(); webResponse.Headers.Add("Content-Length", UTF8Encoding.UTF8.GetBytes(jsonResponse).Length.ToString()); UnmarshallerContext context = new JsonUnmarshallerContext(Utils.CreateStreamFromString(jsonResponse), false, webResponse); var response = UpdateShardCountResponseUnmarshaller.Instance.Unmarshall(context) as UpdateShardCountResponse; InstantiateClassGenerator.ValidateObjectFullyInstantiated(response); }
public void DescribeAcceleratorOfferings_BadRequestExceptionMarshallTest() { var operation = service_model.FindOperation("DescribeAcceleratorOfferings"); var request = InstantiateClassGenerator.Execute <DescribeAcceleratorOfferingsRequest>(); var marshaller = new DescribeAcceleratorOfferingsRequestMarshaller(); var internalRequest = marshaller.Marshall(request); TestTools.RequestValidator.Validate("DescribeAcceleratorOfferings", request, internalRequest, service_model); var exception = operation.Exceptions.First(e => e.Name.Equals("BadRequestException")); var webResponse = new WebResponseData { Headers = { { "x-amzn-RequestId", Guid.NewGuid().ToString() }, { "x-amz-crc32", "0" }, { "x-amzn-ErrorType", "BadRequestException" }, } }; var payloadResponse = new JsonSampleGenerator(service_model, exception).Execute(); webResponse.Headers["Content-Length"] = UTF8Encoding.UTF8.GetBytes(payloadResponse).Length.ToString(); var context = new JsonUnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), true, webResponse, true); var response = DescribeAcceleratorOfferingsResponseUnmarshaller.Instance.UnmarshallException(context, null, System.Net.HttpStatusCode.OK); InstantiateClassGenerator.ValidateObjectFullyInstantiated(response); }
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); }
public void CloseTunnel_ResourceNotFoundExceptionMarshallTest() { var operation = service_model.FindOperation("CloseTunnel"); var request = InstantiateClassGenerator.Execute <CloseTunnelRequest>(); var marshaller = new CloseTunnelRequestMarshaller(); var internalRequest = marshaller.Marshall(request); var jsonRequest = UTF8Encoding.UTF8.GetString(internalRequest.Content); Comparer.CompareObjectToJson <CloseTunnelRequest>(request, jsonRequest); var exception = operation.Exceptions.First(e => e.Name.Equals("ResourceNotFoundException")); var jsonResponse = new JsonSampleGenerator(service_model, exception).Execute(); var webResponse = new WebResponseData { Headers = { { "x-amzn-RequestId", Guid.NewGuid().ToString() }, { "x-amz-crc32", "0" }, { "x-amzn-ErrorType", "ResourceNotFoundException" }, { "Content-Length", UTF8Encoding.UTF8.GetBytes(jsonResponse).Length.ToString() } } }; var context = new JsonUnmarshallerContext(Utils.CreateStreamFromString(jsonResponse), true, webResponse, true); var response = CloseTunnelResponseUnmarshaller.Instance.UnmarshallException(context, null, System.Net.HttpStatusCode.OK); InstantiateClassGenerator.ValidateObjectFullyInstantiated(response); }
public void UnmarshallJsonWithForwardSlashes() { string jsonResponse = @" { ""Cluster"": { ""Configurations"": [ { ""Classification"": ""value1"", ""Properties"": { ""/"": ""xyz"" } }, { ""Classification"": ""value2"", ""Properties"": { ""the/name"": ""true"" } }, { ""Classification"": ""value3"", ""Properties"": { ""name"": ""true"" } }, ] } }"; var webResponse = new WebResponseData { Headers = { { "x-amzn-RequestId", Guid.NewGuid().ToString() }, { "x-amz-crc32", "0" } } }; webResponse.Headers.Add("Content-Length", UTF8Encoding.UTF8.GetBytes(jsonResponse).Length.ToString()); UnmarshallerContext context = new JsonUnmarshallerContext(Utils.CreateStreamFromString(jsonResponse), false, webResponse); var unmarshaller = DescribeClusterResponseUnmarshaller.Instance; var response = unmarshaller.Unmarshall(context) as DescribeClusterResponse; Assert.IsNotNull(response); Assert.IsNotNull(response.Cluster); var configurations = response.Cluster.Configurations; Assert.IsNotNull(configurations); Assert.AreEqual(3, configurations.Count); Assert.IsTrue(configurations[0].Properties.ContainsKey("/")); Assert.IsTrue(configurations[1].Properties.ContainsKey("the/name")); Assert.IsTrue(configurations[2].Properties.ContainsKey("name")); }
public void ResponseChecksumSelection_NoChecksumsReturned() { var operationSupportedChecksums = new List <CoreChecksumAlgorithm> { CoreChecksumAlgorithm.CRC32, CoreChecksumAlgorithm.CRC32C }; var responseData = new WebResponseData(); // No checksum headers on the response, so we cannot choose one to validate Assert.AreEqual(CoreChecksumAlgorithm.NONE, ChecksumUtils.SelectChecksumForResponseValidation(operationSupportedChecksums, responseData)); }
private ErrorResponse GetXmlErrorResponse(string body) { body = body == null ? string.Empty : body; var webResponse = new WebResponseData { StatusCode = HttpStatusCode.ServiceUnavailable, }; webResponse.Headers.Add("Content-Length", UTF8Encoding.UTF8.GetBytes(body).Length.ToString()); var context = new XmlUnmarshallerContext(AWSSDK_DotNet35.UnitTests.Utils.CreateStreamFromString(body), true, webResponse); return(new ErrorResponseUnmarshaller().Unmarshall(context)); }
public void GetObjectMetadataUnmarshallerTest(string metadataKey, string metadataValue, string escapedMetadataValue) { var metadataKeyHeader = $"x-amz-meta-{metadataKey}"; var responseData = new WebResponseData() { Headers = new Dictionary <string, string> { { metadataKeyHeader, escapedMetadataValue } } }; var context = new XmlUnmarshallerContext(new MemoryStream(), false, responseData); var response = (GetObjectMetadataResponse) GetObjectMetadataResponseUnmarshaller.Instance.Unmarshall(context); Assert.AreEqual(response.Metadata[metadataKeyHeader], metadataValue); }
public void TestResponseChecksumSelection_UnsupportedChecksum() { var operationSupportedChecksums = new List <CoreChecksumAlgorithm> { CoreChecksumAlgorithm.SHA256, CoreChecksumAlgorithm.CRC32 }; var responseData = new WebResponseData(); responseData.Headers = new Dictionary <string, string> { { "x-amz-checksum-crc64", "checksum" } }; // CRC64 is not currently supported by the SDK Assert.AreEqual(CoreChecksumAlgorithm.NONE, ChecksumUtils.SelectChecksumForResponseValidation(operationSupportedChecksums, responseData)); }
public void ResponseChecksumSelection_SingleChecksum() { var operationSupportedChecksums = new List <CoreChecksumAlgorithm> { CoreChecksumAlgorithm.SHA256, CoreChecksumAlgorithm.CRC32 }; var responseData = new WebResponseData(); responseData.Headers = new Dictionary <string, string> { { "x-amz-checksum-sha256", "checksum" } }; // Even though CRC32 is supported and comes first in priority order, only SHA256 is returned from service Assert.AreEqual(CoreChecksumAlgorithm.SHA256, ChecksumUtils.SelectChecksumForResponseValidation(operationSupportedChecksums, responseData)); }
public void TestResponseChecksumSelection_Priority() { var operationSupportedChecksums = new List <CoreChecksumAlgorithm> { CoreChecksumAlgorithm.SHA256, CoreChecksumAlgorithm.CRC32 }; var responseData = new WebResponseData(); responseData.Headers = new Dictionary <string, string> { { "x-amz-checksum-sha256", "checksum" }, { "x-amz-checksum-crc32", "checksum" } }; // CRC32 should take priority over SHA256 when both are returned Assert.AreEqual(CoreChecksumAlgorithm.CRC32, ChecksumUtils.SelectChecksumForResponseValidation(operationSupportedChecksums, responseData)); }
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); }
private ErrorResponse GetJsonErrorResponse(string body, string xAmzErrorTypeValue, string xAmznErrorMessageValue) { body = body ?? string.Empty; var webResponse = new WebResponseData { StatusCode = HttpStatusCode.ServiceUnavailable, }; if (xAmzErrorTypeValue != null) { webResponse.Headers.Add(HeaderKeys.XAmzErrorType, xAmzErrorTypeValue); } if (xAmznErrorMessageValue != null) { webResponse.Headers.Add(HeaderKeys.XAmznErrorMessage, xAmznErrorMessageValue); } webResponse.Headers.Add("Content-Length", UTF8Encoding.UTF8.GetBytes(body).Length.ToString()); var context = new JsonUnmarshallerContext(AWSSDK_DotNet35.UnitTests.Utils.CreateStreamFromString(body), true, webResponse); return(new JsonErrorResponseUnmarshaller().Unmarshall(context)); }
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); }