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);
}
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;
}
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;
}
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());
}
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();
}
Aggregations