Skip to content

Commit 4d2e472

Browse files
committed
made changes for URL client
1 parent 296dbc1 commit 4d2e472

File tree

3 files changed

+61
-5
lines changed

3 files changed

+61
-5
lines changed

http-clients/url-connection-client/src/main/java/software/amazon/awssdk/http/urlconnection/UrlConnectionHttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ public interface Builder extends SdkHttpClient.Builder<UrlConnectionHttpClient.B
503503

504504
private static final class DefaultBuilder implements Builder {
505505
private final AttributeMap.Builder standardOptions = AttributeMap.builder();
506-
private ProxyConfiguration proxyConfiguration;
506+
private ProxyConfiguration proxyConfiguration = ProxyConfiguration.builder().build();
507507

508508
private DefaultBuilder() {
509509
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 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.urlconnection;
17+
18+
import java.io.IOException;
19+
import software.amazon.awssdk.http.SdkHttpClient;
20+
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
21+
import software.amazon.awssdk.http.proxy.HttpClientDefaultPoxyConfigTest;
22+
23+
public class UrlClientProxyConfigurationTest extends HttpClientDefaultPoxyConfigTest {
24+
@Override
25+
protected boolean isSyncClient() {
26+
return true;
27+
}
28+
29+
@Override
30+
protected SdkAsyncHttpClient createHttpClientWithDefaultProxy() {
31+
throw new UnsupportedOperationException("Async client not supported");
32+
}
33+
34+
@Override
35+
protected SdkHttpClient createSyncHttpClientWithDefaultProxy() {
36+
return UrlConnectionHttpClient.create();
37+
}
38+
39+
@Override
40+
protected Class<? extends Exception> getProxyFailedExceptionType() {
41+
return IOException.class;
42+
}
43+
44+
@Override
45+
protected Class<? extends Exception> getProxyFailedCauseExceptionType() {
46+
return null;
47+
}
48+
}

test/http-client-tests/src/main/java/software/amazon/awssdk/http/proxy/HttpClientDefaultPoxyConfigTest.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Collections;
3131
import java.util.List;
3232
import java.util.Map;
33+
import java.util.Random;
3334
import java.util.concurrent.CompletableFuture;
3435
import java.util.concurrent.ThreadLocalRandom;
3536
import java.util.concurrent.TimeUnit;
@@ -61,6 +62,8 @@
6162

6263
public abstract class HttpClientDefaultPoxyConfigTest {
6364

65+
static Random random = new Random();
66+
6467
private static final EnvironmentVariableHelper ENVIRONMENT_VARIABLE_HELPER = new EnvironmentVariableHelper();
6568

6669
protected WireMockServer mockProxy = new WireMockServer(new WireMockConfiguration()
@@ -206,9 +209,14 @@ public void defaultProxyConfigurationSyncHttp(SdkHttpClient client, Class<? exte
206209
.request(request)
207210
.build());
208211

209-
if (exceptionType != null && proxyFailedCauseExceptionType != null) {
210-
assertThatExceptionOfType(exceptionType).isThrownBy(() -> executableHttpRequest.call())
211-
.withCauseInstanceOf(proxyFailedCauseExceptionType);
212+
if (exceptionType != null) {
213+
if (proxyFailedCauseExceptionType != null) {
214+
assertThatExceptionOfType(exceptionType).isThrownBy(() -> executableHttpRequest.call())
215+
.withCauseInstanceOf(proxyFailedCauseExceptionType);
216+
} else {
217+
218+
assertThatExceptionOfType(exceptionType).isThrownBy(() -> executableHttpRequest.call());
219+
}
212220
} else {
213221
HttpExecuteResponse executeResponse = executableHttpRequest.call();
214222
assertThat(error.get()).isNull();
@@ -284,7 +292,7 @@ static SdkHttpFullRequest createRequest(URI endpoint,
284292
private int getRandomPort(int currentPort) {
285293
int randomPort;
286294
do {
287-
randomPort = ThreadLocalRandom.current().nextInt(65535);
295+
randomPort = random.nextInt(65535);
288296
} while (randomPort == currentPort);
289297
return randomPort;
290298
}

0 commit comments

Comments
 (0)