Skip to content

Commit 831f9e9

Browse files
committed
Address pr comments
1 parent 8dde988 commit 831f9e9

File tree

6 files changed

+21
-28
lines changed

6 files changed

+21
-28
lines changed

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

Lines changed: 2 additions & 6 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);
@@ -832,4 +829,3 @@ private HttpResponseHandler<AwsServiceException> createErrorResponseHandler(Base
832829
return protocolFactory.createErrorResponseHandler(operationMetadata);
833830
}
834831
}
835-

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,11 @@ public final String serviceName() {
102102
@Override
103103
public APostOperationResponse aPostOperation(APostOperationRequest aPostOperationRequest) throws InvalidInputException,
104104
AwsServiceException, SdkClientException, JsonException {
105-
<<<<<<< 69e57a64e16ab9b10a1294d60262502f8d3ac6d8
106-
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
107-
.isPayloadJson(true).build();
108-
=======
109105
String hostPrefix = "{StringMember}-foo.";
110106
Validate.paramNotBlank(aPostOperationRequest.stringMember(), "StringMember");
111107
String resolvedHostExpression = String.format("%s-foo.", aPostOperationRequest.stringMember());
112-
>>>>>>> Add support for endpoint trait
108+
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
109+
.isPayloadJson(true).build();
113110

114111
HttpResponseHandler<APostOperationResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata,
115112
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> SdkHttpFullRequest finalizeSdkHttpFu
5251

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

5656
executionContext.executionAttributes().putAttribute(SdkExecutionAttribute.SERVICE_NAME,
5757
clientConfiguration.option(SdkClientOption.SERVICE_NAME));
@@ -80,19 +80,20 @@ private static void runBeforeMarshallingInterceptors(ExecutionContext executionC
8080
}
8181

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

95-
return UriResourcePathUtils.updateUriHost(originalEndpoint, hostPrefix);
94+
return originalRequest.toBuilder()
95+
.uri(UriResourcePathUtils.updateUriHost(originalRequest.getUri(), hostPrefix))
96+
.build();
9697
}
9798

9899
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)