Skip to content

Commit b74843d

Browse files
committed
Address pr comments
1 parent deb7561 commit b74843d

File tree

6 files changed

+28
-22
lines changed

6 files changed

+28
-22
lines changed

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-async-client-class.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,11 @@ public final String serviceName() {
146146
@Override
147147
public CompletableFuture<APostOperationResponse> aPostOperation(APostOperationRequest aPostOperationRequest) {
148148
try {
149-
<<<<<<< 69e57a64e16ab9b10a1294d60262502f8d3ac6d8
150-
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
151-
.isPayloadJson(true).build();
152-
=======
153149
String hostPrefix = "{StringMember}-foo.";
154150
Validate.paramNotBlank(aPostOperationRequest.stringMember(), "StringMember");
155151
String resolvedHostExpression = String.format("%s-foo.", aPostOperationRequest.stringMember());
156-
>>>>>>> Add support for endpoint trait
152+
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
153+
.isPayloadJson(true).build();
157154

158155
HttpResponseHandler<APostOperationResponse> responseHandler = protocolFactory.createResponseHandler(
159156
operationMetadata, APostOperationResponse::builder);

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-client-class.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,21 @@ public final String serviceName() {
101101
*/
102102
@Override
103103
public APostOperationResponse aPostOperation(APostOperationRequest aPostOperationRequest) throws InvalidInputException,
104+
<<<<<<< 9794a317c00310db05768dd9b8fa7599ef3c55db
104105
AwsServiceException, SdkClientException, JsonException {
105106
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
106107
.isPayloadJson(true).build();
107108
String hostPrefix = "{StringMember}-foo.";
108109
Validate.paramNotBlank(aPostOperationRequest.stringMember(), "StringMember");
109110
String resolvedHostExpression = String.format("%s-foo.", aPostOperationRequest.stringMember());
111+
=======
112+
AwsServiceException, SdkClientException, JsonException {
113+
String hostPrefix = "{StringMember}-foo.";
114+
Validate.paramNotBlank(aPostOperationRequest.stringMember(), "StringMember");
115+
String resolvedHostExpression = String.format("%s-foo.", aPostOperationRequest.stringMember());
116+
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
117+
.isPayloadJson(true).build();
118+
>>>>>>> Address pr comments
110119

111120
HttpResponseHandler<APostOperationResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata,
112121
APostOperationResponse::builder);

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
package software.amazon.awssdk.core.client.handler;
1717

18-
import java.net.URI;
1918
import software.amazon.awssdk.annotations.SdkProtectedApi;
2019
import software.amazon.awssdk.core.SdkRequest;
2120
import software.amazon.awssdk.core.SdkResponse;
@@ -28,7 +27,7 @@
2827
import software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain;
2928
import software.amazon.awssdk.core.interceptor.InterceptorContext;
3029
import software.amazon.awssdk.core.interceptor.SdkExecutionAttribute;
31-
import software.amazon.awssdk.core.util.UriResourcePathUtils;
30+
import software.amazon.awssdk.core.internal.util.UriResourcePathUtils;
3231
import software.amazon.awssdk.http.SdkHttpFullRequest;
3332
import software.amazon.awssdk.utils.StringUtils;
3433

@@ -52,6 +51,7 @@ static <InputT extends SdkRequest, OutputT> InterceptorContext finalizeSdkHttpFu
5251

5352
runBeforeMarshallingInterceptors(executionContext);
5453
SdkHttpFullRequest request = executionParams.getMarshaller().marshall(inputT);
54+
request = modifyEndpointIfNeeded(request, clientConfiguration, executionParams.hostPrefixExpression());
5555

5656
addHttpRequest(executionContext, request);
5757
runAfterMarshallingInterceptors(executionContext);
@@ -77,19 +77,20 @@ private static void runBeforeMarshallingInterceptors(ExecutionContext executionC
7777
}
7878

7979
/**
80-
* Returns a new URI to be used for making the API call using the original URI and
81-
* the hostPrefixExpression from the endpoint trait.
80+
* Modifies the given {@link SdkHttpFullRequest} with new endpoint if host prefix is enabled and set.
8281
*/
83-
private static URI resolveEndpoint(SdkClientConfiguration clientConfiguration, String hostPrefix) {
84-
URI originalEndpoint = clientConfiguration.option(SdkClientOption.ENDPOINT);
85-
82+
private static SdkHttpFullRequest modifyEndpointIfNeeded(SdkHttpFullRequest originalRequest,
83+
SdkClientConfiguration clientConfiguration,
84+
String hostPrefix) {
8685
Boolean disableHostPrefixInjection = clientConfiguration.option(SdkAdvancedClientOption.DISABLE_HOST_PREFIX_INJECTION);
8786
if ((disableHostPrefixInjection != null && disableHostPrefixInjection.equals(Boolean.TRUE)) ||
8887
StringUtils.isEmpty(hostPrefix)) {
89-
return originalEndpoint;
88+
return originalRequest;
9089
}
9190

92-
return UriResourcePathUtils.updateUriHost(originalEndpoint, hostPrefix);
91+
return originalRequest.toBuilder()
92+
.uri(UriResourcePathUtils.updateUriHost(originalRequest.getUri(), hostPrefix))
93+
.build();
9394
}
9495

9596
private static void addHttpRequest(ExecutionContext executionContext, SdkHttpFullRequest request) {

core/sdk-core/src/main/java/software/amazon/awssdk/core/util/UriResourcePathUtils.java renamed to core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/util/UriResourcePathUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
package software.amazon.awssdk.core.util;
16+
package software.amazon.awssdk.core.internal.util;
1717

1818
import java.net.URI;
1919
import java.net.URISyntaxException;
20-
import software.amazon.awssdk.annotations.SdkProtectedApi;
20+
import software.amazon.awssdk.annotations.SdkInternalApi;
2121

22-
@SdkProtectedApi
22+
@SdkInternalApi
2323
public final class UriResourcePathUtils {
2424

2525
private UriResourcePathUtils() {

core/sdk-core/src/test/java/software/amazon/awssdk/core/util/UriResourcePathUtilsTest.java renamed to core/sdk-core/src/test/java/software/amazon/awssdk/core/internal/util/UriResourcePathUtilsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
package software.amazon.awssdk.core.util;
16+
package software.amazon.awssdk.core.internal.util;
1717

1818
import static org.hamcrest.CoreMatchers.equalTo;
19-
import static software.amazon.awssdk.core.util.UriResourcePathUtils.updateUriHost;
19+
import static software.amazon.awssdk.core.internal.util.UriResourcePathUtils.updateUriHost;
2020

2121
import java.net.URI;
2222
import java.net.URISyntaxException;

test/protocol-tests/src/test/java/software/amazon/awssdk/protocol/tests/endpoint/EndpointTraitTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@
3333
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
3434
import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption;
3535
import software.amazon.awssdk.core.exception.SdkClientException;
36-
import software.amazon.awssdk.http.AbortableCallable;
3736
import software.amazon.awssdk.http.ExecuteRequest;
37+
import software.amazon.awssdk.http.InvokeableHttpRequest;
3838
import software.amazon.awssdk.http.SdkHttpClient;
39-
import software.amazon.awssdk.http.SdkHttpFullResponse;
4039
import software.amazon.awssdk.http.SdkHttpRequest;
4140
import software.amazon.awssdk.regions.Region;
4241
import software.amazon.awssdk.services.protocoljsonendpointtrait.ProtocolJsonEndpointTraitClient;
@@ -51,7 +50,7 @@ public class EndpointTraitTest {
5150
private SdkHttpClient mockHttpClient;
5251

5352
@Mock
54-
private AbortableCallable<SdkHttpFullResponse> abortableCallable;
53+
private InvokeableHttpRequest abortableCallable;
5554

5655
private ProtocolJsonEndpointTraitClient client;
5756

0 commit comments

Comments
 (0)