public GenericApiGatewayResponse(HttpResponse httpResponse) throws IOException { this.httpResponse = httpResponse; if(httpResponse.getContent() != null) { this.body = IOUtils.toString(httpResponse.getContent()); }else { this.body = null; } }
public AmazonWebServiceResponse<String> handle(HttpResponse response) throws Exception { AmazonWebServiceResponse<String> awsResponse = parseResponseMetadata(response); int bytesRead; byte[] buffer = new byte[1024]; StringBuilder builder = new StringBuilder(); InputStream content = response.getContent(); while ((bytesRead = content.read(buffer)) > 0) { builder.append(new String(buffer, 0, bytesRead, StringUtils.UTF8)); } awsResponse.setResult(builder.toString()); return awsResponse; }
/** * Static factory method to create a JsonContent object from the contents of the HttpResponse * provided */ public static JsonContent createJsonContent(HttpResponse httpResponse, JsonFactory jsonFactory) { byte[] rawJsonContent = null; try { if (httpResponse.getContent() != null) { rawJsonContent = IOUtils.toByteArray(httpResponse.getContent()); } } catch (Exception e) { LOG.debug("Unable to read HTTP response content", e); } return new JsonContent(rawJsonContent, new ObjectMapper(jsonFactory) .configure(JsonParser.Feature.ALLOW_COMMENTS, true)); }
/** * @see com.amazonaws.http.HttpResponseHandler#handle(com.amazonaws.http.HttpResponse) */ public AmazonWebServiceResponse<T> handle(HttpResponse response) throws Exception { AmazonWebServiceResponse<T> awsResponse = parseResponseMetadata(response); responseHeaders = response.getHeaders(); if (responseUnmarshaller != null) { log.trace("Beginning to parse service response XML"); T result = responseUnmarshaller.unmarshall(response.getContent()); log.trace("Done parsing service response XML"); awsResponse.setResult(result); } return awsResponse; }
@Override public RawResult unmarshall(JsonUnmarshallerContext in) throws IOException { HttpResponse response = in.getHttpResponse(); RawResult result = new RawResult(); result.sdkResponseMetadata(new SdkResponseMetadata(SdkHttpMetadata.from(response))); try { resultContentConsumer.consume(result, response.getContent()); } finally { response.getContent().close(); } return result; } }
public PutMediaResult unmarshall(JsonUnmarshallerContext context) throws Exception { PutMediaResult putMediaResult = new PutMediaResult(); putMediaResult.setPayload(context.getHttpResponse().getContent()); return putMediaResult; }
public GetIntrospectionSchemaResult unmarshall(JsonUnmarshallerContext context) throws Exception { GetIntrospectionSchemaResult getIntrospectionSchemaResult = new GetIntrospectionSchemaResult(); java.io.InputStream is = context.getHttpResponse().getContent(); if (is != null) { try { getIntrospectionSchemaResult.setSchema(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is))); } finally { com.amazonaws.util.IOUtils.closeQuietly(is, null); } } return getIntrospectionSchemaResult; }
public DeleteThingShadowResult unmarshall(JsonUnmarshallerContext context) throws Exception { DeleteThingShadowResult deleteThingShadowResult = new DeleteThingShadowResult(); java.io.InputStream is = context.getHttpResponse().getContent(); if (is != null) { try { deleteThingShadowResult.setPayload(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is))); } finally { com.amazonaws.util.IOUtils.closeQuietly(is, null); } } return deleteThingShadowResult; }
public GetThingShadowResult unmarshall(JsonUnmarshallerContext context) throws Exception { GetThingShadowResult getThingShadowResult = new GetThingShadowResult(); java.io.InputStream is = context.getHttpResponse().getContent(); if (is != null) { try { getThingShadowResult.setPayload(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is))); } finally { com.amazonaws.util.IOUtils.closeQuietly(is, null); } } return getThingShadowResult; }
public UpdateThingShadowResult unmarshall(JsonUnmarshallerContext context) throws Exception { UpdateThingShadowResult updateThingShadowResult = new UpdateThingShadowResult(); java.io.InputStream is = context.getHttpResponse().getContent(); if (is != null) { try { updateThingShadowResult.setPayload(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is))); } finally { com.amazonaws.util.IOUtils.closeQuietly(is, null); } } return updateThingShadowResult; }
private AmazonServiceException createAse(HttpResponse errorResponse) throws Exception { // Try to parse the error response as XML final Document document = documentFromContent(errorResponse.getContent(), idString(errorResponse)); /* * We need to select which exception unmarshaller is the correct one to * use from all the possible exceptions this operation can throw. * Currently we rely on the unmarshallers to return null if they can't * unmarshall the response, but we might need something a little more * sophisticated in the future. */ for (Unmarshaller<AmazonServiceException, Node> unmarshaller : unmarshallerList) { AmazonServiceException ase = unmarshaller.unmarshall(document); if (ase != null) { ase.setStatusCode(errorResponse.getStatusCode()); return ase; } } return null; }
public GetMediaResult unmarshall(JsonUnmarshallerContext context) throws Exception { GetMediaResult getMediaResult = new GetMediaResult(); if (context.isStartOfDocument()) { if (context.getHeader("Content-Type") != null) { context.setCurrentHeader("Content-Type"); getMediaResult.setContentType(context.getUnmarshaller(String.class).unmarshall(context)); } } getMediaResult.setPayload(context.getHttpResponse().getContent()); return getMediaResult; }
public GetMediaForFragmentListResult unmarshall(JsonUnmarshallerContext context) throws Exception { GetMediaForFragmentListResult getMediaForFragmentListResult = new GetMediaForFragmentListResult(); if (context.isStartOfDocument()) { if (context.getHeader("Content-Type") != null) { context.setCurrentHeader("Content-Type"); getMediaForFragmentListResult.setContentType(context.getUnmarshaller(String.class).unmarshall(context)); } } getMediaForFragmentListResult.setPayload(context.getHttpResponse().getContent()); return getMediaForFragmentListResult; }
/** * @see com.amazonaws.http.HttpResponseHandler#handle(com.amazonaws.http.HttpResponse) */ public AmazonWebServiceResponse<S3Object> handle(HttpResponse response) throws Exception { /* * TODO: It'd be nice to set the bucket name and key here, but the information isn't easy to * pull out of the response/request currently. */ S3Object object = new S3Object(); AmazonWebServiceResponse<S3Object> awsResponse = parseResponseMetadata(response); if (response.getHeaders().get(Headers.REDIRECT_LOCATION) != null) { object.setRedirectLocation(response.getHeaders().get(Headers.REDIRECT_LOCATION)); } // If the requester is charged when downloading a object from an // Requester Pays bucket, then this header is set. if (response.getHeaders().get(Headers.REQUESTER_CHARGED_HEADER) != null) { object.setRequesterCharged(true); } if (response.getHeaders().get(Headers.S3_TAGGING_COUNT) != null) { object.setTaggingCount(Integer.parseInt(response.getHeaders().get(Headers.S3_TAGGING_COUNT))); } ObjectMetadata metadata = object.getObjectMetadata(); populateObjectMetadata(response, metadata); object.setObjectContent(new S3ObjectInputStream(response.getContent(), response.getHttpRequest())); awsResponse.setResult(object); return awsResponse; }
public SynthesizeSpeechResult unmarshall(JsonUnmarshallerContext context) throws Exception { SynthesizeSpeechResult synthesizeSpeechResult = new SynthesizeSpeechResult(); if (context.isStartOfDocument()) { if (context.getHeader("Content-Type") != null) { context.setCurrentHeader("Content-Type"); synthesizeSpeechResult.setContentType(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.getHeader("x-amzn-RequestCharacters") != null) { context.setCurrentHeader("x-amzn-RequestCharacters"); synthesizeSpeechResult.setRequestCharacters(context.getUnmarshaller(Integer.class).unmarshall(context)); } } synthesizeSpeechResult.setAudioStream(context.getHttpResponse().getContent()); return synthesizeSpeechResult; }
public GetSdkResult unmarshall(JsonUnmarshallerContext context) throws Exception { GetSdkResult getSdkResult = new GetSdkResult(); if (context.isStartOfDocument()) { if (context.getHeader("Content-Type") != null) { context.setCurrentHeader("Content-Type"); getSdkResult.setContentType(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.getHeader("Content-Disposition") != null) { context.setCurrentHeader("Content-Disposition"); getSdkResult.setContentDisposition(context.getUnmarshaller(String.class).unmarshall(context)); } } java.io.InputStream is = context.getHttpResponse().getContent(); if (is != null) { try { getSdkResult.setBody(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is))); } finally { com.amazonaws.util.IOUtils.closeQuietly(is, null); } } return getSdkResult; }
public GetExportResult unmarshall(JsonUnmarshallerContext context) throws Exception { GetExportResult getExportResult = new GetExportResult(); if (context.isStartOfDocument()) { if (context.getHeader("Content-Type") != null) { context.setCurrentHeader("Content-Type"); getExportResult.setContentType(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.getHeader("Content-Disposition") != null) { context.setCurrentHeader("Content-Disposition"); getExportResult.setContentDisposition(context.getUnmarshaller(String.class).unmarshall(context)); } } java.io.InputStream is = context.getHttpResponse().getContent(); if (is != null) { try { getExportResult.setBody(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is))); } finally { com.amazonaws.util.IOUtils.closeQuietly(is, null); } } return getExportResult; }
public InvokeEndpointResult unmarshall(JsonUnmarshallerContext context) throws Exception { InvokeEndpointResult invokeEndpointResult = new InvokeEndpointResult(); if (context.isStartOfDocument()) { if (context.getHeader("Content-Type") != null) { context.setCurrentHeader("Content-Type"); invokeEndpointResult.setContentType(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.getHeader("x-Amzn-Invoked-Production-Variant") != null) { context.setCurrentHeader("x-Amzn-Invoked-Production-Variant"); invokeEndpointResult.setInvokedProductionVariant(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.getHeader("X-Amzn-SageMaker-Custom-Attributes") != null) { context.setCurrentHeader("X-Amzn-SageMaker-Custom-Attributes"); invokeEndpointResult.setCustomAttributes(context.getUnmarshaller(String.class).unmarshall(context)); } } java.io.InputStream is = context.getHttpResponse().getContent(); if (is != null) { try { invokeEndpointResult.setBody(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is))); } finally { com.amazonaws.util.IOUtils.closeQuietly(is, null); } } return invokeEndpointResult; }
public InvokeResult unmarshall(JsonUnmarshallerContext context) throws Exception { InvokeResult invokeResult = new InvokeResult(); if (context.isStartOfDocument()) { if (context.getHeader("X-Amz-Function-Error") != null) { context.setCurrentHeader("X-Amz-Function-Error"); invokeResult.setFunctionError(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.getHeader("X-Amz-Log-Result") != null) { context.setCurrentHeader("X-Amz-Log-Result"); invokeResult.setLogResult(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.getHeader("X-Amz-Executed-Version") != null) { context.setCurrentHeader("X-Amz-Executed-Version"); invokeResult.setExecutedVersion(context.getUnmarshaller(String.class).unmarshall(context)); } } invokeResult.setStatusCode(context.getHttpResponse().getStatusCode()); java.io.InputStream is = context.getHttpResponse().getContent(); if (is != null) { try { invokeResult.setPayload(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is))); } finally { com.amazonaws.util.IOUtils.closeQuietly(is, null); } } return invokeResult; }
public GetJobOutputResult unmarshall(JsonUnmarshallerContext context) throws Exception { GetJobOutputResult getJobOutputResult = new GetJobOutputResult(); if (context.isStartOfDocument()) { if (context.getHeader("x-amz-sha256-tree-hash") != null) { context.setCurrentHeader("x-amz-sha256-tree-hash"); getJobOutputResult.setChecksum(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.getHeader("Content-Range") != null) { context.setCurrentHeader("Content-Range"); getJobOutputResult.setContentRange(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.getHeader("Accept-Ranges") != null) { context.setCurrentHeader("Accept-Ranges"); getJobOutputResult.setAcceptRanges(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.getHeader("Content-Type") != null) { context.setCurrentHeader("Content-Type"); getJobOutputResult.setContentType(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.getHeader("x-amz-archive-description") != null) { context.setCurrentHeader("x-amz-archive-description"); getJobOutputResult.setArchiveDescription(context.getUnmarshaller(String.class).unmarshall(context)); } } getJobOutputResult.setStatus(context.getHttpResponse().getStatusCode()); getJobOutputResult.setBody(context.getHttpResponse().getContent()); return getJobOutputResult; }