Skip to content

Commit d9616a5

Browse files
committed
Update only host instead of entire uri to make sure other uri params are unchanged.
1 parent 59cb5af commit d9616a5

File tree

7 files changed

+124
-201
lines changed

7 files changed

+124
-201
lines changed

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

Lines changed: 91 additions & 105 deletions
Large diffs are not rendered by default.

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain;
2828
import software.amazon.awssdk.core.interceptor.InterceptorContext;
2929
import software.amazon.awssdk.core.interceptor.SdkExecutionAttribute;
30-
import software.amazon.awssdk.core.internal.util.UriResourcePathUtils;
3130
import software.amazon.awssdk.http.SdkHttpFullRequest;
3231
import software.amazon.awssdk.utils.StringUtils;
3332

@@ -51,7 +50,7 @@ static <InputT extends SdkRequest, OutputT> InterceptorContext finalizeSdkHttpFu
5150

5251
runBeforeMarshallingInterceptors(executionContext);
5352
SdkHttpFullRequest request = executionParams.getMarshaller().marshall(inputT);
54-
request = modifyEndpointIfNeeded(request, clientConfiguration, executionParams.hostPrefixExpression());
53+
request = modifyEndpointHostIfNeeded(request, clientConfiguration, executionParams.hostPrefixExpression());
5554

5655
addHttpRequest(executionContext, request);
5756
runAfterMarshallingInterceptors(executionContext);
@@ -77,19 +76,19 @@ private static void runBeforeMarshallingInterceptors(ExecutionContext executionC
7776
}
7877

7978
/**
80-
* Modifies the given {@link SdkHttpFullRequest} with new endpoint if host prefix is enabled and set.
79+
* Modifies the given {@link SdkHttpFullRequest} with new host if host prefix is enabled and set.
8180
*/
82-
private static SdkHttpFullRequest modifyEndpointIfNeeded(SdkHttpFullRequest originalRequest,
83-
SdkClientConfiguration clientConfiguration,
84-
String hostPrefix) {
81+
private static SdkHttpFullRequest modifyEndpointHostIfNeeded(SdkHttpFullRequest originalRequest,
82+
SdkClientConfiguration clientConfiguration,
83+
String hostPrefix) {
8584
Boolean disableHostPrefixInjection = clientConfiguration.option(SdkAdvancedClientOption.DISABLE_HOST_PREFIX_INJECTION);
8685
if ((disableHostPrefixInjection != null && disableHostPrefixInjection.equals(Boolean.TRUE)) ||
8786
StringUtils.isEmpty(hostPrefix)) {
8887
return originalRequest;
8988
}
9089

9190
return originalRequest.toBuilder()
92-
.uri(UriResourcePathUtils.updateUriHost(originalRequest.getUri(), hostPrefix))
91+
.host(hostPrefix + originalRequest.host())
9392
.build();
9493
}
9594

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

Lines changed: 0 additions & 41 deletions
This file was deleted.

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

Lines changed: 0 additions & 36 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public Optional<ContentStreamProvider> contentStreamProvider() {
139139

140140
@Override
141141
public SdkHttpFullRequest.Builder toBuilder() {
142-
return (SdkHttpFullRequest.Builder) new Builder()
142+
return new Builder()
143143
.contentStreamProvider(contentStreamProvider)
144144
.protocol(protocol)
145145
.host(host)

test/protocol-tests/src/main/resources/codegen-resources/endpoint/json/service-2.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"name":"EndpointTraitTwo",
3030
"http":{
3131
"method":"POST",
32-
"requestUri":"/"
32+
"requestUri":"/{PathParam}"
3333
},
3434
"endpoint": {
3535
"hostPrefix": "{StringMember}-"
@@ -53,6 +53,13 @@
5353
"StringMember":{
5454
"shape":"String",
5555
"hostLabel": true
56+
},
57+
"PathIdempotentToken":{
58+
"shape":"String",
59+
"idempotencyToken":true,
60+
"location":"uri",
61+
"locationName":"PathParam",
62+
"hostLabel": true
5663
}
5764
}
5865
},

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.mockito.Mockito.when;
2222

2323
import java.net.URI;
24+
import java.net.URISyntaxException;
2425
import org.junit.Assert;
2526
import org.junit.Before;
2627
import org.junit.Test;
@@ -33,8 +34,8 @@
3334
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
3435
import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption;
3536
import software.amazon.awssdk.core.exception.SdkClientException;
36-
import software.amazon.awssdk.http.ExecuteRequest;
37-
import software.amazon.awssdk.http.InvokeableHttpRequest;
37+
import software.amazon.awssdk.http.ExecutableHttpRequest;
38+
import software.amazon.awssdk.http.HttpExecuteRequest;
3839
import software.amazon.awssdk.http.SdkHttpClient;
3940
import software.amazon.awssdk.http.SdkHttpRequest;
4041
import software.amazon.awssdk.regions.Region;
@@ -50,7 +51,7 @@ public class EndpointTraitTest {
5051
private SdkHttpClient mockHttpClient;
5152

5253
@Mock
53-
private InvokeableHttpRequest abortableCallable;
54+
private ExecutableHttpRequest abortableCallable;
5455

5556
private ProtocolJsonEndpointTraitClient client;
5657

@@ -71,32 +72,39 @@ public void setup() throws Exception {
7172
}
7273

7374
@Test
74-
public void hostExpression_withoutInputMemberLabel() {
75+
public void hostExpression_withoutInputMemberLabel() throws URISyntaxException {
7576
try {
7677
client.endpointTraitOne(EndpointTraitOneRequest.builder().build());
7778
Assert.fail("Expected an exception");
7879
} catch (SdkClientException exception) {
79-
ArgumentCaptor<ExecuteRequest> httpRequestCaptor = ArgumentCaptor.forClass(ExecuteRequest.class);
80+
ArgumentCaptor<HttpExecuteRequest> httpRequestCaptor = ArgumentCaptor.forClass(HttpExecuteRequest.class);
8081
verify(mockHttpClient).prepareRequest(httpRequestCaptor.capture());
8182

8283
SdkHttpRequest request = httpRequestCaptor.getAllValues().get(0).httpRequest();
8384
assertThat(request.host()).isEqualTo("data.localhost.com");
85+
assertThat(request.port()).isEqualTo(443);
86+
assertThat(request.encodedPath()).isEqualTo("/");
87+
assertThat(request.getUri()).isEqualTo(new URI("http://data.localhost.com:443/"));
8488
}
8589
}
8690

8791
@Test
88-
public void hostExpression_withInputMemberLabel() {
92+
public void hostExpression_withInputMemberLabel() throws URISyntaxException {
8993
try {
9094
client.endpointTraitTwo(EndpointTraitTwoRequest.builder()
9195
.stringMember("123456")
96+
.pathIdempotentToken("dummypath")
9297
.build());
9398
Assert.fail("Expected an exception");
9499
} catch (SdkClientException exception) {
95-
ArgumentCaptor<ExecuteRequest> httpRequestCaptor = ArgumentCaptor.forClass(ExecuteRequest.class);
100+
ArgumentCaptor<HttpExecuteRequest> httpRequestCaptor = ArgumentCaptor.forClass(HttpExecuteRequest.class);
96101
verify(mockHttpClient).prepareRequest(httpRequestCaptor.capture());
97102

98103
SdkHttpRequest request = httpRequestCaptor.getAllValues().get(0).httpRequest();
99104
assertThat(request.host()).isEqualTo("123456-localhost.com");
105+
assertThat(request.port()).isEqualTo(443);
106+
assertThat(request.encodedPath()).isEqualTo("/dummypath");
107+
assertThat(request.getUri()).isEqualTo(new URI("http://123456-localhost.com:443/dummypath"));
100108
}
101109
}
102110

@@ -116,7 +124,7 @@ public void clientWithDisabledHostPrefix_withoutInputMemberLabel_usesOriginalUri
116124
clientWithDisabledHostPrefix.endpointTraitOne(EndpointTraitOneRequest.builder().build());
117125
Assert.fail("Expected an exception");
118126
} catch (SdkClientException exception) {
119-
ArgumentCaptor<ExecuteRequest> httpRequestCaptor = ArgumentCaptor.forClass(ExecuteRequest.class);
127+
ArgumentCaptor<HttpExecuteRequest> httpRequestCaptor = ArgumentCaptor.forClass(HttpExecuteRequest.class);
120128
verify(mockHttpClient).prepareRequest(httpRequestCaptor.capture());
121129

122130
SdkHttpRequest request = httpRequestCaptor.getAllValues().get(0).httpRequest();
@@ -132,7 +140,7 @@ public void clientWithDisabledHostPrefix_withInputMemberLabel_usesOriginalUri()
132140
.build());
133141
Assert.fail("Expected an exception");
134142
} catch (SdkClientException exception) {
135-
ArgumentCaptor<ExecuteRequest> httpRequestCaptor = ArgumentCaptor.forClass(ExecuteRequest.class);
143+
ArgumentCaptor<HttpExecuteRequest> httpRequestCaptor = ArgumentCaptor.forClass(HttpExecuteRequest.class);
136144
verify(mockHttpClient).prepareRequest(httpRequestCaptor.capture());
137145

138146
SdkHttpRequest request = httpRequestCaptor.getAllValues().get(0).httpRequest();
@@ -145,7 +153,7 @@ private StaticCredentialsProvider mockCredentials() {
145153
}
146154

147155
private String getEndpoint() {
148-
return "http://localhost.com";
156+
return "http://localhost.com:443";
149157
}
150158

151159
private ProtocolJsonEndpointTraitClientBuilder clientBuilder() {

0 commit comments

Comments
 (0)