/** * Buffers the response content into an {@link SdkBytes} object. Used to fill the {@link AwsErrorDetails}. If * an {@link IOException} occurs then this will return {@link #emptyXmlBytes()} so that unmarshalling can proceed. * * @param response HTTP response. * @return Raw bytes of response. */ private SdkBytes getResponseBytes(SdkHttpFullResponse response) { try { return response.content() .map(SdkBytes::fromInputStream) .orElseGet(this::emptyXmlBytes); } catch (Exception e) { return emptyXmlBytes(); } }
/** * Buffers the response content into an {@link SdkBytes} object. Used to fill the {@link AwsErrorDetails}. If * an {@link IOException} occurs then this will return {@link #emptyXmlBytes()} so that unmarshalling can proceed. * * @param response HTTP response. * @return Raw bytes of response. */ private SdkBytes getResponseBytes(SdkHttpFullResponse response) { try { return response.content() .map(SdkBytes::fromInputStream) .orElseGet(this::emptyXmlBytes); } catch (Exception e) { return emptyXmlBytes(); } }
/** * Static factory method to create a JsonContent object from the contents of the HttpResponse * provided */ public static JsonContent createJsonContent(SdkHttpFullResponse httpResponse, JsonFactory jsonFactory) { byte[] rawJsonContent = httpResponse.content().map(c -> { try { return IoUtils.toByteArray(c); } catch (IOException e) { LOG.debug("Unable to read HTTP response content", e); } return null; }).orElse(null); return new JsonContent(rawJsonContent, jsonFactory); }
private void closeStream(SdkHttpFullResponse response) { response.content().ifPresent(i -> { try { i.close(); } catch (IOException e) { log.warn(() -> "Error closing HTTP content.", e); } }); }
private void closeStream(SdkHttpFullResponse response) { response.content().ifPresent(i -> { try { i.close(); } catch (IOException e) { log.warn(() -> "Error closing HTTP content.", e); } }); }
/** * Static factory method to create a JsonContent object from the contents of the HttpResponse * provided */ public static JsonContent createJsonContent(SdkHttpFullResponse httpResponse, JsonFactory jsonFactory) { byte[] rawJsonContent = httpResponse.content().map(c -> { try { return IoUtils.toByteArray(c); } catch (IOException e) { LOG.debug("Unable to read HTTP response content", e); } return null; }).orElse(null); return new JsonContent(rawJsonContent, jsonFactory); }
public static SdkHttpFullResponse validate(boolean calculateCrc32FromCompressedData, SdkHttpFullResponse httpResponse) { if (!httpResponse.content().isPresent()) { return httpResponse; } return httpResponse.toBuilder().content( process(calculateCrc32FromCompressedData, httpResponse, httpResponse.content().get())).build(); }
@Override public ReturnT handle(SdkHttpFullResponse response, ExecutionAttributes executionAttributes) throws Exception { OutputT resp = httpResponseHandler.handle(response, executionAttributes); return transformResponse(resp, response.content().get()); }
@Override public T handle(SdkHttpFullResponse response, ExecutionAttributes executionAttributes) throws Exception { try { return unmarshallResponse(response); } finally { response.content().ifPresent(i -> { try { i.close(); } catch (IOException e) { log.warn(() -> "Error closing HTTP content.", e); } }); } }
@Override public T handle(SdkHttpFullResponse response, ExecutionAttributes executionAttributes) throws Exception { try { return unmarshallResponse(response); } finally { response.content().ifPresent(i -> { try { i.close(); } catch (IOException e) { log.warn(() -> "Error closing HTTP content.", e); } }); } }
/** * @see HttpResponseHandler#handle(SdkHttpFullResponse, ExecutionAttributes) */ public T handle(SdkHttpFullResponse response, ExecutionAttributes executionAttributes) throws Exception { SdkStandardLogger.REQUEST_LOGGER.trace(() -> "Parsing service response JSON."); SdkStandardLogger.REQUEST_ID_LOGGER.debug(() -> X_AMZN_REQUEST_ID_HEADER + " : " + response.firstMatchingHeader(X_AMZN_REQUEST_ID_HEADER) .orElse("not available")); try { T result = unmarshaller.unmarshall(pojoSupplier.apply(response), response); // Make sure we read all the data to get an accurate CRC32 calculation. // See https://github.com/aws/aws-sdk-java/issues/1018 if (shouldParsePayloadAsJson() && response.content().isPresent()) { IoUtils.drainInputStream(response.content().get()); } SdkStandardLogger.REQUEST_LOGGER.trace(() -> "Done parsing service response."); return result; } finally { if (!needsConnectionLeftOpen) { response.content().ifPresent(i -> FunctionalUtils.invokeSafely(i::close)); } } }
public <TypeT extends SdkPojo> Pair<TypeT, Map<String, String>> unmarshall(SdkPojo sdkPojo, SdkHttpFullResponse response) { XmlElement document = response.content().map(XmlDomParser::parse).orElse(XmlElement.empty()); XmlElement resultRoot = hasResultWrapper ? document.getFirstChild() : document; return Pair.of(unmarshall(sdkPojo, resultRoot, response), parseMetadata(document)); }
public <TypeT extends SdkPojo> Pair<TypeT, Map<String, String>> unmarshall(SdkPojo sdkPojo, SdkHttpFullResponse response) { XmlElement document = response.content().map(XmlDomParser::parse).orElse(XmlElement.empty()); XmlElement resultRoot = hasResultWrapper ? document.getFirstChild() : document; return Pair.of(unmarshall(sdkPojo, resultRoot, response), parseMetadata(document)); }
public <TypeT extends SdkPojo> TypeT unmarshall(SdkPojo sdkPojo, SdkHttpFullResponse response) throws IOException { if (hasPayloadMembers(sdkPojo) && !hasExplicitBlobPayloadMember(sdkPojo)) { SdkJsonNode jsonNode = parser.parse(ReleasableInputStream.wrap(response.content().orElse(null)).disableClose()); return unmarshall(sdkPojo, response, jsonNode); } else { return unmarshall(sdkPojo, response, null); } }
public <TypeT extends SdkPojo> TypeT unmarshall(SdkPojo sdkPojo, SdkHttpFullResponse response) throws IOException { if (hasPayloadMembers(sdkPojo) && !hasExplicitBlobPayloadMember(sdkPojo)) { SdkJsonNode jsonNode = parser.parse(ReleasableInputStream.wrap(response.content().orElse(null)).disableClose()); return unmarshall(sdkPojo, response, jsonNode); } else { return unmarshall(sdkPojo, response, null); } }
@SuppressWarnings("unchecked") private static <TypeT extends SdkPojo> TypeT unmarshallStructured(SdkPojo sdkPojo, SdkJsonNode jsonContent, JsonUnmarshallerContext context) { for (SdkField<?> field : sdkPojo.sdkFields()) { if (isExplicitPayloadMember(field) && field.marshallingType() == MarshallingType.SDK_BYTES) { field.set(sdkPojo, SdkBytes.fromInputStream(context.response().content().orElse(null))); } else { SdkJsonNode jsonFieldContent = getSdkJsonNode(jsonContent, field); JsonUnmarshaller<Object> unmarshaller = context.getUnmarshaller(field.location(), field.marshallingType()); field.set(sdkPojo, unmarshaller.unmarshall(context, jsonFieldContent, (SdkField<Object>) field)); } } return (TypeT) ((Buildable) sdkPojo).build(); }
@SuppressWarnings("unchecked") private static <TypeT extends SdkPojo> TypeT unmarshallStructured(SdkPojo sdkPojo, SdkJsonNode jsonContent, JsonUnmarshallerContext context) { for (SdkField<?> field : sdkPojo.sdkFields()) { if (isExplicitPayloadMember(field) && field.marshallingType() == MarshallingType.SDK_BYTES) { field.set(sdkPojo, SdkBytes.fromInputStream(context.response().content().orElse(null))); } else { SdkJsonNode jsonFieldContent = getSdkJsonNode(jsonContent, field); JsonUnmarshaller<Object> unmarshaller = context.getUnmarshaller(field.location(), field.marshallingType()); field.set(sdkPojo, unmarshaller.unmarshall(context, jsonFieldContent, (SdkField<Object>) field)); } } return (TypeT) ((Buildable) sdkPojo).build(); }
context.executionContext().interceptorContext().copy(b -> b.httpResponse(input.right()) .responseBody(input.right() .content() .orElse(null)));