Search in sources :

Example 51 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class BaseSyncClientHandler method doExecute.

private <InputT extends SdkRequest, OutputT, ReturnT> ReturnT doExecute(ClientExecutionParams<InputT, OutputT> executionParams, ExecutionContext executionContext, HttpResponseHandler<Response<ReturnT>> responseHandler) {
    InputT inputT = (InputT) executionContext.interceptorContext().request();
    InterceptorContext sdkHttpFullRequestContext = finalizeSdkHttpFullRequest(executionParams, executionContext, inputT, clientConfiguration);
    SdkHttpFullRequest marshalled = (SdkHttpFullRequest) sdkHttpFullRequestContext.httpRequest();
    // TODO Pass requestBody as separate arg to invoke
    Optional<RequestBody> requestBody = sdkHttpFullRequestContext.requestBody();
    if (requestBody.isPresent()) {
        marshalled = marshalled.toBuilder().contentStreamProvider(requestBody.get().contentStreamProvider()).build();
    }
    return invoke(marshalled, inputT, executionContext, responseHandler);
}
Also used : SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) InterceptorContext(software.amazon.awssdk.core.interceptor.InterceptorContext) RequestBody(software.amazon.awssdk.core.sync.RequestBody)

Example 52 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class SigningStage method signRequest.

/**
 * Sign the request if the signer if provided and credentials are present.
 */
private SdkHttpFullRequest signRequest(SdkHttpFullRequest request, RequestExecutionContext context) throws Exception {
    updateInterceptorContext(request, context.executionContext());
    Signer signer = context.signer();
    MetricCollector metricCollector = context.attemptMetricCollector();
    if (shouldSign(signer)) {
        adjustForClockSkew(context.executionAttributes());
        Pair<SdkHttpFullRequest, Duration> measuredSign = MetricUtils.measureDuration(() -> signer.sign(request, context.executionAttributes()));
        metricCollector.reportMetric(CoreMetric.SIGNING_DURATION, measuredSign.right());
        SdkHttpFullRequest signedRequest = measuredSign.left();
        if (signer instanceof AsyncRequestBodySigner) {
            // Transform request body provider with signing operator
            AsyncRequestBody transformedRequestProvider = ((AsyncRequestBodySigner) signer).signAsyncRequestBody(signedRequest, context.requestProvider(), context.executionAttributes());
            context.requestProvider(transformedRequestProvider);
        }
        updateInterceptorContext(signedRequest, context.executionContext());
        return signedRequest;
    }
    return request;
}
Also used : AsyncRequestBodySigner(software.amazon.awssdk.core.signer.AsyncRequestBodySigner) Signer(software.amazon.awssdk.core.signer.Signer) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) AsyncRequestBody(software.amazon.awssdk.core.async.AsyncRequestBody) Duration(java.time.Duration) AsyncRequestBodySigner(software.amazon.awssdk.core.signer.AsyncRequestBodySigner)

Example 53 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class MetricReportingTest method newRequest.

private HttpExecuteRequest newRequest(MetricCollector collector) {
    final SdkHttpFullRequest sdkRequest = SdkHttpFullRequest.builder().method(SdkHttpMethod.HEAD).host("amazonaws.com").protocol("https").build();
    HttpExecuteRequest executeRequest = HttpExecuteRequest.builder().request(sdkRequest).metricCollector(collector).build();
    return executeRequest;
}
Also used : HttpExecuteRequest(software.amazon.awssdk.http.HttpExecuteRequest) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest)

Example 54 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class ApacheHttpClientWireMockTest method overrideDnsResolver.

private void overrideDnsResolver(String hostName, boolean nullifyResolver) throws IOException {
    DnsResolver dnsResolver = new SystemDefaultDnsResolver() {

        @Override
        public InetAddress[] resolve(final String host) throws UnknownHostException {
            if (host.equalsIgnoreCase("magic.local.host")) {
                return new InetAddress[] { InetAddress.getByName("127.0.0.1") };
            } else {
                return super.resolve(host);
            }
        }
    };
    if (nullifyResolver) {
        dnsResolver = null;
    }
    SdkHttpClient client = ApacheHttpClient.builder().dnsResolver(dnsResolver).buildWithDefaults(AttributeMap.builder().put(TRUST_ALL_CERTIFICATES, Boolean.TRUE).build());
    mockProxyServer.resetToDefaultMappings();
    mockProxyServer.stubFor(any(urlPathEqualTo("/")).willReturn(aResponse().withStatus(HttpURLConnection.HTTP_OK)));
    URI uri = URI.create("https://" + hostName + ":" + mockProxyServer.httpsPort());
    SdkHttpFullRequest req = SdkHttpFullRequest.builder().uri(uri).method(SdkHttpMethod.POST).putHeader("Host", uri.getHost()).build();
    client.prepareRequest(HttpExecuteRequest.builder().request(req).contentStreamProvider(req.contentStreamProvider().orElse(null)).build()).call();
    mockProxyServer.verify(1, RequestPatternBuilder.allRequests());
}
Also used : DnsResolver(org.apache.http.conn.DnsResolver) SystemDefaultDnsResolver(org.apache.http.impl.conn.SystemDefaultDnsResolver) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) SdkHttpClient(software.amazon.awssdk.http.SdkHttpClient) SystemDefaultDnsResolver(org.apache.http.impl.conn.SystemDefaultDnsResolver) InetAddress(java.net.InetAddress) URI(java.net.URI)

Example 55 with SdkHttpFullRequest

use of software.amazon.awssdk.http.SdkHttpFullRequest in project aws-sdk-java-v2 by aws.

the class RdsPresignInterceptor method modifyHttpRequest.

@Override
public final SdkHttpRequest modifyHttpRequest(Context.ModifyHttpRequest context, ExecutionAttributes executionAttributes) {
    SdkHttpRequest request = context.httpRequest();
    SdkRequest originalRequest = context.request();
    if (!requestClassToPreSign.isInstance(originalRequest)) {
        return request;
    }
    if (request.rawQueryParameters().containsKey(PARAM_PRESIGNED_URL)) {
        return request;
    }
    PresignableRequest presignableRequest = adaptRequest(requestClassToPreSign.cast(originalRequest));
    String sourceRegion = presignableRequest.getSourceRegion();
    if (sourceRegion == null) {
        return request;
    }
    String destinationRegion = executionAttributes.getAttribute(AwsSignerExecutionAttribute.SIGNING_REGION).id();
    URI endpoint = createEndpoint(sourceRegion, SERVICE_NAME, executionAttributes);
    SdkHttpFullRequest.Builder marshalledRequest = presignableRequest.marshall().toBuilder().uri(endpoint);
    SdkHttpFullRequest requestToPresign = marshalledRequest.method(SdkHttpMethod.GET).putRawQueryParameter(PARAM_DESTINATION_REGION, destinationRegion).removeQueryParameter(PARAM_SOURCE_REGION).build();
    requestToPresign = presignRequest(requestToPresign, executionAttributes, sourceRegion);
    String presignedUrl = requestToPresign.getUri().toString();
    return request.toBuilder().putRawQueryParameter(PARAM_PRESIGNED_URL, presignedUrl).removeQueryParameter(PARAM_SOURCE_REGION).build();
}
Also used : SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) SdkRequest(software.amazon.awssdk.core.SdkRequest) URI(java.net.URI)

Aggregations

SdkHttpFullRequest (software.amazon.awssdk.http.SdkHttpFullRequest)178 Test (org.junit.Test)70 Test (org.junit.jupiter.api.Test)50 ExecutionAttributes (software.amazon.awssdk.core.interceptor.ExecutionAttributes)43 URI (java.net.URI)25 SigningTestCase (software.amazon.awssdk.authcrt.signer.SigningTestCase)23 ByteArrayInputStream (java.io.ByteArrayInputStream)18 SdkHttpRequest (software.amazon.awssdk.http.SdkHttpRequest)16 List (java.util.List)13 AwsCredentials (software.amazon.awssdk.auth.credentials.AwsCredentials)13 RequestExecutionContext (software.amazon.awssdk.core.internal.http.RequestExecutionContext)12 ByteBuffer (java.nio.ByteBuffer)11 AsyncRequestBody (software.amazon.awssdk.core.async.AsyncRequestBody)11 Map (java.util.Map)10 ContentStreamProvider (software.amazon.awssdk.http.ContentStreamProvider)10 Instant (java.time.Instant)9 AwsBasicCredentials (software.amazon.awssdk.auth.credentials.AwsBasicCredentials)9 Aws4SignerParams (software.amazon.awssdk.auth.signer.params.Aws4SignerParams)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8