private static HttpMethod toNettyHttpMethod(SdkHttpMethod method) { return HttpMethod.valueOf(method.name()); } }
@Override public SdkHttpMethod deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { return SdkHttpMethod.fromValue(p.getText()); } }
/** * @param value Raw string representing value of enum * @return HttpMethodName enum or null if value is not present. * @throws IllegalArgumentException If value does not represent a known enum value. */ public static SdkHttpMethod fromValue(String value) { if (value == null || value.isEmpty()) { return null; } String upperCaseValue = value.toUpperCase(Locale.ENGLISH); return Stream.of(values()) .filter(h -> h.name().equals(upperCaseValue)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Unsupported HTTP method name " + value)); }
/** * Step 1 of the AWS Signature version 4 calculation. Refer to * http://docs.aws * .amazon.com/general/latest/gr/sigv4-create-canonical-request.html to * generate the canonical request. */ private String createCanonicalRequest(SdkHttpFullRequest.Builder request, String contentSha256, boolean doubleUrlEncode) { String canonicalRequest = request.method().toString() + SignerConstant.LINE_SEPARATOR + // This would optionally double url-encode the resource path getCanonicalizedResourcePath(request.encodedPath(), doubleUrlEncode) + SignerConstant.LINE_SEPARATOR + getCanonicalizedQueryString(request.rawQueryParameters()) + SignerConstant.LINE_SEPARATOR + getCanonicalizedHeaderString(request.headers()) + SignerConstant.LINE_SEPARATOR + getSignedHeadersString(request.headers()) + SignerConstant.LINE_SEPARATOR + contentSha256; LOG.trace(() -> "AWS4 Canonical Request: " + canonicalRequest); return canonicalRequest; }
/** * Step 1 of the AWS Signature version 4 calculation. Refer to * http://docs.aws * .amazon.com/general/latest/gr/sigv4-create-canonical-request.html to * generate the canonical request. */ private String createCanonicalRequest(SdkHttpFullRequest.Builder request, String contentSha256, boolean doubleUrlEncode) { String canonicalRequest = request.method().toString() + SignerConstant.LINE_SEPARATOR + // This would optionally double url-encode the resource path getCanonicalizedResourcePath(request.encodedPath(), doubleUrlEncode) + SignerConstant.LINE_SEPARATOR + getCanonicalizedQueryString(request.rawQueryParameters()) + SignerConstant.LINE_SEPARATOR + getCanonicalizedHeaderString(request.headers()) + SignerConstant.LINE_SEPARATOR + getSignedHeadersString(request.headers()) + SignerConstant.LINE_SEPARATOR + contentSha256; LOG.trace(() -> "AWS4 Canonical Request: " + canonicalRequest); return canonicalRequest; }
private static HttpMethod toNettyHttpMethod(SdkHttpMethod method) { return HttpMethod.valueOf(method.name()); } }
/** * @param value Raw string representing value of enum * @return HttpMethodName enum or null if value is not present. * @throws IllegalArgumentException If value does not represent a known enum value. */ public static SdkHttpMethod fromValue(String value) { if (value == null || value.isEmpty()) { return null; } String upperCaseValue = value.toUpperCase(Locale.ENGLISH); return Stream.of(values()) .filter(h -> h.name().equals(upperCaseValue)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Unsupported HTTP method name " + value)); }
@Override protected void doAssert(LoggedRequest actual) { assertEquals(expectedMethodName.name(), actual.getMethod().value()); } }
private HttpURLConnection createAndConfigureConnection(HttpExecuteRequest request) { HttpURLConnection connection = connectionFactory.createConnection(request.httpRequest().getUri()); request.httpRequest() .headers() .forEach((key, values) -> values.forEach(value -> connection.setRequestProperty(key, value))); invokeSafely(() -> connection.setRequestMethod(request.httpRequest().method().name())); if (request.contentStreamProvider().isPresent()) { connection.setDoOutput(true); } // Disable following redirects since it breaks SDK error handling and matches Apache. // See: https://github.com/aws/aws-sdk-java-v2/issues/975 connection.setInstanceFollowRedirects(false); return connection; }
private void validateResponse(HttpExecuteResponse response, int returnCode, SdkHttpMethod method) throws IOException { RequestMethod requestMethod = RequestMethod.fromString(method.name()); RequestPatternBuilder patternBuilder = RequestPatternBuilder.newRequestPattern(requestMethod, urlMatching("/")) .withHeader("Host", containing("localhost")) .withHeader("User-Agent", equalTo("hello-world!")); if (method == SdkHttpMethod.HEAD) { patternBuilder.withRequestBody(equalTo("")); } else { patternBuilder.withRequestBody(equalTo("Body")); } verify(1, patternBuilder); if (method == SdkHttpMethod.HEAD) { assertThat(response.responseBody()).isEmpty(); } else { assertThat(IoUtils.toUtf8String(response.responseBody().orElse(null))).isEqualTo("hello"); } assertThat(response.httpResponse().firstMatchingHeader("Some-Header")).contains("With Value"); assertThat(response.httpResponse().statusCode()).isEqualTo(returnCode); mockServer.resetMappings(); }