Skip to content

Commit ac58e0c

Browse files
committed
Cleaning up interceptors and HTTP SPI
1 parent f699849 commit ac58e0c

File tree

22 files changed

+156
-145
lines changed

22 files changed

+156
-145
lines changed

core/aws-core/src/main/java/software/amazon/awssdk/awscore/AwsExecutionAttribute.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
package software.amazon.awssdk.awscore;
1717

18-
import software.amazon.awssdk.annotations.SdkProtectedApi;
19-
import software.amazon.awssdk.auth.signer.AwsSignerExecutionAttribute;
18+
import software.amazon.awssdk.annotations.SdkPublicApi;
19+
import software.amazon.awssdk.auth.signer.internal.AwsSignerExecutionAttribute;
2020
import software.amazon.awssdk.core.interceptor.ExecutionAttribute;
2121
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
2222
import software.amazon.awssdk.core.interceptor.SdkExecutionAttribute;
@@ -25,7 +25,7 @@
2525
/**
2626
* AWS-specific attributes attached to the execution. This information is available to {@link ExecutionInterceptor}s.
2727
*/
28-
@SdkProtectedApi
28+
@SdkPublicApi
2929
public final class AwsExecutionAttribute extends SdkExecutionAttribute {
3030
/**
3131
* The AWS {@link Region} the client was configured with. This is not always same as the

core/aws-core/src/main/java/software/amazon/awssdk/awscore/internal/client/handler/AwsClientHandlerUtils.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import software.amazon.awssdk.awscore.client.config.AwsAdvancedClientOption;
3030
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
3131
import software.amazon.awssdk.core.Request;
32-
import software.amazon.awssdk.core.RequestOverrideConfiguration;
3332
import software.amazon.awssdk.core.SdkRequest;
3433
import software.amazon.awssdk.core.SdkResponse;
3534
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
@@ -71,10 +70,6 @@ public static <InputT extends SdkRequest, OutputT extends SdkResponse> Execution
7170
ExecutionAttributes executionAttributes = new ExecutionAttributes()
7271
.putAttribute(AwsSignerExecutionAttribute.SERVICE_CONFIG, clientConfig.option(SdkClientOption.SERVICE_CONFIGURATION))
7372
.putAttribute(AwsSignerExecutionAttribute.AWS_CREDENTIALS, credentials)
74-
.putAttribute(AwsSignerExecutionAttribute.REQUEST_CONFIG,
75-
originalRequest.overrideConfiguration()
76-
.map(c -> (RequestOverrideConfiguration) c)
77-
.orElse(AwsRequestOverrideConfiguration.builder().build()))
7873
.putAttribute(AwsSignerExecutionAttribute.SERVICE_SIGNING_NAME,
7974
clientConfig.option(AwsClientOption.SERVICE_SIGNING_NAME))
8075
.putAttribute(AwsExecutionAttribute.AWS_REGION, clientConfig.option(AwsClientOption.AWS_REGION))

core/sdk-core/src/it/java/software/amazon/awssdk/core/http/timers/client/AbortedExceptionClientExecutionTimerIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public class AbortedExceptionClientExecutionTimerIntegrationTest extends MockSer
7171

7272
@Before
7373
public void setup() throws Exception {
74-
when(sdkHttpClient.prepareRequest(any(), any())).thenReturn(abortableCallable);
74+
when(sdkHttpClient.prepareRequest(any())).thenReturn(abortableCallable);
7575
httpClient = HttpTestUtils.testClientBuilder().httpClient(sdkHttpClient).build();
7676
when(abortableCallable.call()).thenReturn(SdkHttpFullResponse.builder()
7777
.statusCode(200)

core/sdk-core/src/main/java/software/amazon/awssdk/core/client/builder/SdkDefaultClientBuilder.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,9 @@
5656
import software.amazon.awssdk.core.internal.util.UserAgentUtils;
5757
import software.amazon.awssdk.core.retry.RetryPolicy;
5858
import software.amazon.awssdk.http.AbortableCallable;
59+
import software.amazon.awssdk.http.ExecuteRequest;
5960
import software.amazon.awssdk.http.SdkHttpClient;
60-
import software.amazon.awssdk.http.SdkHttpConfigurationOption;
61-
import software.amazon.awssdk.http.SdkHttpFullRequest;
6261
import software.amazon.awssdk.http.SdkHttpFullResponse;
63-
import software.amazon.awssdk.http.SdkRequestContext;
6462
import software.amazon.awssdk.http.async.AsyncExecuteRequest;
6563
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
6664
import software.amazon.awssdk.utils.AttributeMap;
@@ -368,14 +366,8 @@ private NonManagedSdkHttpClient(SdkHttpClient delegate) {
368366
}
369367

370368
@Override
371-
public AbortableCallable<SdkHttpFullResponse> prepareRequest(SdkHttpFullRequest request,
372-
SdkRequestContext requestContext) {
373-
return delegate.prepareRequest(request, requestContext);
374-
}
375-
376-
@Override
377-
public <T> Optional<T> getConfigurationValue(SdkHttpConfigurationOption<T> key) {
378-
return delegate.getConfigurationValue(key);
369+
public AbortableCallable<SdkHttpFullResponse> prepareRequest(ExecuteRequest request) {
370+
return delegate.prepareRequest(request);
379371
}
380372

381373
@Override
@@ -402,11 +394,6 @@ public CompletableFuture<Void> execute(AsyncExecuteRequest request) {
402394
return delegate.execute(request);
403395
}
404396

405-
@Override
406-
public <T> Optional<T> getConfigurationValue(SdkHttpConfigurationOption<T> key) {
407-
return delegate.getConfigurationValue(key);
408-
}
409-
410397
@Override
411398
public void close() {
412399
// Do nothing, this client is managed by the customer.

core/sdk-core/src/main/java/software/amazon/awssdk/core/client/handler/BaseClientHandler.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717

1818
import software.amazon.awssdk.annotations.SdkProtectedApi;
1919
import software.amazon.awssdk.core.Request;
20-
import software.amazon.awssdk.core.RequestOverrideConfiguration;
2120
import software.amazon.awssdk.core.SdkRequest;
22-
import software.amazon.awssdk.core.SdkRequestOverrideConfiguration;
2321
import software.amazon.awssdk.core.SdkResponse;
2422
import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption;
2523
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
@@ -133,18 +131,8 @@ protected <InputT extends SdkRequest, OutputT extends SdkResponse> ExecutionCont
133131

134132
SdkRequest originalRequest = params.getInput();
135133
ExecutionAttributes executionAttributes = new ExecutionAttributes()
136-
.putAttribute(SdkExecutionAttribute.REQUEST_CONFIG, originalRequest.overrideConfiguration()
137-
.filter(c -> c instanceof
138-
SdkRequestOverrideConfiguration)
139-
.map(c -> (RequestOverrideConfiguration) c)
140-
.orElse(SdkRequestOverrideConfiguration.builder()
141-
.build()))
142134
.putAttribute(SdkExecutionAttribute.SERVICE_CONFIG,
143-
clientConfiguration.option(SdkClientOption.SERVICE_CONFIGURATION))
144-
.putAttribute(SdkExecutionAttribute.REQUEST_CONFIG, originalRequest.overrideConfiguration()
145-
.map(c -> (SdkRequestOverrideConfiguration) c)
146-
.orElse(SdkRequestOverrideConfiguration.builder()
147-
.build()));
135+
clientConfiguration.option(SdkClientOption.SERVICE_CONFIGURATION));
148136

149137
ExecutionInterceptorChain interceptorChain =
150138
new ExecutionInterceptorChain(clientConfiguration.option(SdkClientOption.EXECUTION_INTERCEPTORS));

core/sdk-core/src/main/java/software/amazon/awssdk/core/interceptor/SdkExecutionAttribute.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,17 @@
1515

1616
package software.amazon.awssdk.core.interceptor;
1717

18-
import software.amazon.awssdk.annotations.SdkProtectedApi;
19-
import software.amazon.awssdk.core.RequestOverrideConfiguration;
18+
import software.amazon.awssdk.annotations.SdkPublicApi;
2019
import software.amazon.awssdk.core.ServiceConfiguration;
2120
import software.amazon.awssdk.core.signer.Signer;
2221

2322
/**
2423
* Contains attributes attached to the execution. This information is available to {@link ExecutionInterceptor}s and
2524
* {@link Signer}s.
2625
*/
27-
@SdkProtectedApi
26+
@SdkPublicApi
2827
public class SdkExecutionAttribute {
2928

30-
/**
31-
* The key under which the request config is stored.
32-
*/
33-
public static final ExecutionAttribute<RequestOverrideConfiguration> REQUEST_CONFIG =
34-
new ExecutionAttribute<>("RequestConfig");
35-
3629
/**
3730
* Handler context key for advanced configuration.
3831
*/

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/http/pipeline/stages/MakeHttpRequestStage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
import software.amazon.awssdk.core.internal.http.RequestExecutionContext;
2323
import software.amazon.awssdk.core.internal.http.pipeline.RequestPipeline;
2424
import software.amazon.awssdk.http.AbortableCallable;
25+
import software.amazon.awssdk.http.ExecuteRequest;
2526
import software.amazon.awssdk.http.SdkHttpClient;
2627
import software.amazon.awssdk.http.SdkHttpFullRequest;
2728
import software.amazon.awssdk.http.SdkHttpFullResponse;
28-
import software.amazon.awssdk.http.SdkRequestContext;
2929
import software.amazon.awssdk.utils.Pair;
3030

3131
/**
@@ -53,7 +53,7 @@ public Pair<SdkHttpFullRequest, SdkHttpFullResponse> execute(SdkHttpFullRequest
5353

5454
private SdkHttpFullResponse executeHttpRequest(SdkHttpFullRequest request, RequestExecutionContext context) throws Exception {
5555
final AbortableCallable<SdkHttpFullResponse> requestCallable = sdkHttpClient
56-
.prepareRequest(request, SdkRequestContext.builder().build());
56+
.prepareRequest(ExecuteRequest.builder().request(request).build());
5757

5858
return requestCallable.call();
5959
}

core/sdk-core/src/test/java/software/amazon/awssdk/core/client/handler/SyncClientHandlerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void failedExecutionCallsErrorResponseHandler() throws Exception {
120120

121121
private void expectRetrievalFromMocks() {
122122
when(marshaller.marshall(request)).thenReturn(marshalledRequest);
123-
when(httpClient.prepareRequest(any(), any())).thenReturn(httpClientCall);
123+
when(httpClient.prepareRequest(any())).thenReturn(httpClientCall);
124124
}
125125

126126
private ClientExecutionParams<SdkRequest, SdkResponse> clientExecutionParams() {

core/sdk-core/src/test/java/software/amazon/awssdk/core/http/AmazonHttpClientTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient;
4040
import software.amazon.awssdk.core.internal.http.timers.ClientExecutionAndRequestTimerTestUtils;
4141
import software.amazon.awssdk.http.AbortableCallable;
42+
import software.amazon.awssdk.http.ExecuteRequest;
4243
import software.amazon.awssdk.http.SdkHttpClient;
4344
import software.amazon.awssdk.http.SdkHttpFullRequest;
4445
import software.amazon.awssdk.http.SdkHttpFullResponse;
@@ -60,7 +61,7 @@ public class AmazonHttpClientTest {
6061
public void setUp() throws Exception {
6162
BasicConfigurator.configure();
6263
client = HttpTestUtils.testClientBuilder().httpClient(sdkHttpClient).build();
63-
when(sdkHttpClient.prepareRequest(any(), any())).thenReturn(abortableCallable);
64+
when(sdkHttpClient.prepareRequest(any())).thenReturn(abortableCallable);
6465
stubSuccessfulResponse();
6566
}
6667

@@ -85,7 +86,7 @@ public void testRetryIoExceptionFromExecute() throws Exception {
8586
}
8687

8788
// Verify that we called execute 4 times.
88-
verify(sdkHttpClient, times(4)).prepareRequest(any(), any());
89+
verify(sdkHttpClient, times(4)).prepareRequest(any());
8990
}
9091

9192
@Test
@@ -137,10 +138,10 @@ public void testUserAgentPrefixAndSuffixAreAdded() throws Exception {
137138
.executionContext(ClientExecutionAndRequestTimerTestUtils.executionContext(null))
138139
.execute(handler);
139140

140-
ArgumentCaptor<SdkHttpFullRequest> httpRequestCaptor = ArgumentCaptor.forClass(SdkHttpFullRequest.class);
141-
verify(sdkHttpClient).prepareRequest(httpRequestCaptor.capture(), any());
141+
ArgumentCaptor<ExecuteRequest> httpRequestCaptor = ArgumentCaptor.forClass(ExecuteRequest.class);
142+
verify(sdkHttpClient).prepareRequest(httpRequestCaptor.capture());
142143

143-
final String userAgent = httpRequestCaptor.getValue().firstMatchingHeader("User-Agent")
144+
final String userAgent = httpRequestCaptor.getValue().httpRequest().firstMatchingHeader("User-Agent")
144145
.orElseThrow(() -> new AssertionError("User-Agent header was not found"));
145146

146147
Assert.assertTrue(userAgent.startsWith(prefix));

http-client-spi/src/main/java/software/amazon/awssdk/http/ConfigurationProvider.java

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.http;
17+
18+
import software.amazon.awssdk.annotations.SdkPublicApi;
19+
20+
/**
21+
* Request object containing the parameters necessary to make a synchronous HTTP request.
22+
*
23+
* @see SdkHttpClient
24+
*/
25+
@SdkPublicApi
26+
public final class ExecuteRequest {
27+
28+
private final SdkHttpFullRequest request;
29+
private final boolean isFullDuplex;
30+
31+
private ExecuteRequest(BuilderImpl builder) {
32+
this.request = builder.request;
33+
this.isFullDuplex = builder.isFullDuplex;
34+
}
35+
36+
/**
37+
* @return The HTTP request.
38+
*/
39+
public SdkHttpFullRequest httpRequest() {
40+
return request;
41+
}
42+
43+
public boolean fullDuplex() {
44+
return isFullDuplex;
45+
}
46+
47+
public static Builder builder() {
48+
return new BuilderImpl();
49+
}
50+
51+
public interface Builder {
52+
/**
53+
* Set the HTTP request to be executed by the client.
54+
*
55+
* @param request The request.
56+
* @return This builder for method chaining.
57+
*/
58+
Builder request(SdkHttpFullRequest request);
59+
60+
/**
61+
* Option to indicate if the request is for a full duplex operation ie., request and response are sent/received at
62+
* the same time.
63+
* <p>
64+
* This can be used to set http configuration like ReadTimeouts as soon as request has begin sending data instead of
65+
* waiting for the entire request to be sent.
66+
*
67+
* @return True if the operation this request belongs to is full duplex. Otherwise false.
68+
*/
69+
Builder fullDuplex(boolean fullDuplex);
70+
71+
ExecuteRequest build();
72+
}
73+
74+
private static class BuilderImpl implements Builder {
75+
private SdkHttpFullRequest request;
76+
private boolean isFullDuplex;
77+
78+
@Override
79+
public Builder request(SdkHttpFullRequest request) {
80+
this.request = request;
81+
return this;
82+
}
83+
84+
@Override
85+
public Builder fullDuplex(boolean fullDuplex) {
86+
isFullDuplex = fullDuplex;
87+
return this;
88+
}
89+
90+
@Override
91+
public ExecuteRequest build() {
92+
return new ExecuteRequest(this);
93+
}
94+
}
95+
}

http-client-spi/src/main/java/software/amazon/awssdk/http/SdkHttpClient.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@
3232
@Immutable
3333
@ThreadSafe
3434
@SdkProtectedApi
35-
public interface SdkHttpClient extends SdkAutoCloseable, ConfigurationProvider {
35+
public interface SdkHttpClient extends SdkAutoCloseable {
3636
/**
3737
* Create a {@link AbortableCallable} that can be used to execute the HTTP request.
3838
*
3939
* @param request Representation of an HTTP request.
40-
* @param requestContext Contains any extra dependencies needed.
4140
* @return Task that can execute an HTTP request and can be aborted.
4241
*/
43-
AbortableCallable<SdkHttpFullResponse> prepareRequest(SdkHttpFullRequest request, SdkRequestContext requestContext);
42+
AbortableCallable<SdkHttpFullResponse> prepareRequest(ExecuteRequest request);
4443

4544
/**
4645
* Interface for creating an {@link SdkHttpClient} with service specific defaults applied.

http-client-spi/src/main/java/software/amazon/awssdk/http/async/SdkAsyncHttpClient.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import software.amazon.awssdk.annotations.Immutable;
2121
import software.amazon.awssdk.annotations.SdkProtectedApi;
2222
import software.amazon.awssdk.annotations.ThreadSafe;
23-
import software.amazon.awssdk.http.ConfigurationProvider;
2423
import software.amazon.awssdk.utils.AttributeMap;
2524
import software.amazon.awssdk.utils.SdkAutoCloseable;
2625
import software.amazon.awssdk.utils.builder.SdkBuilder;
@@ -36,7 +35,7 @@
3635
@Immutable
3736
@ThreadSafe
3837
@SdkProtectedApi
39-
public interface SdkAsyncHttpClient extends SdkAutoCloseable, ConfigurationProvider {
38+
public interface SdkAsyncHttpClient extends SdkAutoCloseable {
4039

4140
/**
4241
* Execute the request.

0 commit comments

Comments
 (0)