private static String getRequestId(SdkHttpFullResponse response) { return response.firstMatchingHeader(X_AMZN_REQUEST_ID_HEADER).orElse(null); }
private static Optional<Long> getCrc32Checksum(SdkHttpFullResponse httpResponse) { return httpResponse.firstMatchingHeader("x-amz-crc32") .map(Long::valueOf); }
private static String getRequestId(SdkHttpFullResponse response) { return response.firstMatchingHeader(X_AMZN_REQUEST_ID_HEADER).orElse(null); }
@Override public SdkPojo apply(SdkHttpFullResponse sdkHttpFullResponse) { String eventType = sdkHttpFullResponse.firstMatchingHeader(":event-type").orElse(null); return pojoSuppliers.getOrDefault(eventType, defaultPojoSupplier).get(); }
private static boolean shouldDecompress(SdkHttpFullResponse httpResponse) { return httpResponse.firstMatchingHeader("Content-Encoding") .filter(e -> e.equals("gzip")) .isPresent(); }
/** * Parse the error message from the response. * * @return Error Code of exceptional response or null if it can't be determined */ @Override public String parseErrorMessage(SdkHttpFullResponse httpResponse, SdkJsonNode jsonNode) { String headerMessage = httpResponse.firstMatchingHeader(X_AMZN_ERROR_MESSAGE).orElse(null); if (headerMessage != null) { return headerMessage; } String eventHeaderMessage = httpResponse.firstMatchingHeader(EVENT_ERROR_MESSAGE).orElse(null); if (eventHeaderMessage != null) { return eventHeaderMessage; } return errorMessageParser.parseErrorMessage(httpResponse, jsonNode); }
/** * Parse the error message from the response. * * @return Error Code of exceptional response or null if it can't be determined */ @Override public String parseErrorMessage(SdkHttpFullResponse httpResponse, SdkJsonNode jsonNode) { String headerMessage = httpResponse.firstMatchingHeader(X_AMZN_ERROR_MESSAGE).orElse(null); if (headerMessage != null) { return headerMessage; } String eventHeaderMessage = httpResponse.firstMatchingHeader(EVENT_ERROR_MESSAGE).orElse(null); if (eventHeaderMessage != null) { return eventHeaderMessage; } return errorMessageParser.parseErrorMessage(httpResponse, jsonNode); }
/** * Returns the difference between the client's clock time and the service clock time in unit * of seconds. */ public static int parseClockSkewOffset(SdkHttpFullResponse httpResponse) { Optional<String> dateHeader = httpResponse.firstMatchingHeader("Date"); try { Instant serverDate = dateHeader .filter(h -> !h.isEmpty()) .map(DateUtils::parseRfc1123Date) .orElseThrow(() -> new RuntimeException( "Unable to parse clock skew offset from response. Server Date header missing")); long diff = Duration.between(Instant.now(), serverDate).getSeconds(); return (int) diff; } catch (RuntimeException e) { log.warn("Unable to parse clock skew offset from response: " + dateHeader.orElse(""), e); return 0; } } }
@Override public T unmarshall(JsonUnmarshallerContext context, SdkJsonNode jsonContent, SdkField<T> field) { return context.response().firstMatchingHeader(field.locationName()) .map(s -> stringToValue.convert(s, field)) .orElse(null); } }
@Override public T unmarshall(JsonUnmarshallerContext context, SdkJsonNode jsonContent, SdkField<T> field) { return context.response().firstMatchingHeader(field.locationName()) .map(s -> stringToValue.convert(s, field)) .orElse(null); } }
@Override public T unmarshall(XmlUnmarshallerContext context, List<XmlElement> content, SdkField<T> field) { return context.response().firstMatchingHeader(field.locationName()) .map(s -> stringToValue.convert(s, field)) .orElse(null); } }
@Override public T unmarshall(XmlUnmarshallerContext context, List<XmlElement> content, SdkField<T> field) { return context.response().firstMatchingHeader(field.locationName()) .map(s -> stringToValue.convert(s, field)) .orElse(null); } }
/** * Extracts the request ID from the XML document. Request ID is a top level element * for all protocols, it may be RequestId or RequestID depending on the service. * * @param document Root XML document. * @return Request ID string or null if not present. */ private String getRequestId(SdkHttpFullResponse response, XmlElement document) { XmlElement requestId = document.getOptionalElementByName("RequestId") .orElse(document.getElementByName("RequestID")); return requestId != null ? requestId.textContent() : response.firstMatchingHeader(X_AMZN_REQUEST_ID_HEADER).orElse(null); }
/** * Extracts the request ID from the XML document. Request ID is a top level element * for all protocols, it may be RequestId or RequestID depending on the service. * * @param document Root XML document. * @return Request ID string or null if not present. */ private String getRequestId(SdkHttpFullResponse response, XmlElement document) { XmlElement requestId = document.getOptionalElementByName("RequestId") .orElse(document.getElementByName("RequestID")); return requestId != null ? requestId.textContent() : response.firstMatchingHeader(X_AMZN_REQUEST_ID_HEADER).orElse(null); }
/** * @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)); } } }
/** * @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)); } } }