Skip to content

Commit cdc4f97

Browse files
committed
Update proxy configuration properties settings for Netty and CRT httpclients
1 parent 2388e64 commit cdc4f97

File tree

4 files changed

+70
-9
lines changed

4 files changed

+70
-9
lines changed

http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/ProxyConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public interface Builder extends CopyableBuilder<Builder, ProxyConfiguration> {
196196
* options are not provided during building the {@link ProxyConfiguration} object. To disable this behaviour, set this
197197
* value to false.
198198
*
199-
* @param useSystemPropertyValues The option whether to use system proerpty values
199+
* @param useSystemPropertyValues The option whether to use system property values
200200
* @return This object for method chaining.
201201
*/
202202
Builder useSystemPropertyValues(Boolean useSystemPropertyValues);

http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/ProxyConfigurationTest.java

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.lang.reflect.Method;
2121
import java.util.Random;
2222
import java.util.stream.Stream;
23+
import org.junit.AfterClass;
24+
import org.junit.Before;
2325
import org.junit.Test;
2426

2527
/**
@@ -32,14 +34,36 @@ public class ProxyConfigurationTest {
3234
private static final String TEST_USER = "testuser";
3335
private static final String TEST_PASSWORD = "123";
3436

37+
@Before
38+
public void setup() {
39+
clearProxyProperties();
40+
}
41+
42+
@AfterClass
43+
public static void cleanup() {
44+
clearProxyProperties();
45+
}
46+
3547
@Test
3648
public void build_setsAllProperties() {
3749
verifyAllPropertiesSet(allPropertiesSetConfig());
3850
}
3951

52+
@Test
53+
public void build_systemPropertyDefault() {
54+
setProxyProperties();
55+
ProxyConfiguration config = ProxyConfiguration.builder().build();
56+
57+
assertThat(config.host()).isEqualTo(TEST_HOST);
58+
assertThat(config.port()).isEqualTo(TEST_PORT);
59+
assertThat(config.username()).isEqualTo(TEST_USER);
60+
assertThat(config.password()).isEqualTo(TEST_PASSWORD);
61+
assertThat(config.scheme()).isNull();
62+
}
63+
4064
@Test
4165
public void build_systemPropertyEnabled() {
42-
setSystemProperty();
66+
setProxyProperties();
4367
ProxyConfiguration config = ProxyConfiguration.builder().useSystemPropertyValues(true).build();
4468

4569
assertThat(config.host()).isEqualTo(TEST_HOST);
@@ -51,7 +75,7 @@ public void build_systemPropertyEnabled() {
5175

5276
@Test
5377
public void build_systemPropertyDisabled() {
54-
setSystemProperty();
78+
setProxyProperties();
5579
ProxyConfiguration config = ProxyConfiguration.builder()
5680
.host("localhost")
5781
.port(8888)
@@ -110,7 +134,7 @@ private void setRandomValue(Object o, Method setter) throws InvocationTargetExce
110134
} else if (int.class.equals(paramClass)) {
111135
setter.invoke(o, RNG.nextInt());
112136
} else if (Boolean.class.equals(paramClass)) {
113-
setter.invoke(o, Boolean.FALSE);
137+
setter.invoke(o, RNG.nextBoolean());
114138
} else {
115139
throw new RuntimeException("Don't know how create random value for type " + paramClass);
116140
}
@@ -144,10 +168,17 @@ private String randomString() {
144168
return sb.toString();
145169
}
146170

147-
private void setSystemProperty() {
171+
private void setProxyProperties() {
148172
System.setProperty("http.proxyHost", TEST_HOST);
149173
System.setProperty("http.proxyPort", Integer.toString(TEST_PORT));
150174
System.setProperty("http.proxyUser", TEST_USER);
151175
System.setProperty("http.proxyPassword", TEST_PASSWORD);
152176
}
177+
178+
private static void clearProxyProperties() {
179+
System.clearProperty("http.proxyHost");
180+
System.clearProperty("http.proxyPort");
181+
System.clearProperty("http.proxyUser");
182+
System.clearProperty("http.proxyPassword");
183+
}
153184
}

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/ProxyConfiguration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public String password() {
100100
* system property os returned. If system property is also not set, an unmodifiable empty set is returned.
101101
*/
102102
public Set<String> nonProxyHosts() {
103-
Set<String> hosts = nonProxyHosts == null && useSystemPropertyValues ? parseNonProxyHostProperty()
103+
Set<String> hosts = nonProxyHosts == null && useSystemPropertyValues ? parseNonProxyHostsProperty()
104104
: nonProxyHosts;
105105
return Collections.unmodifiableSet(hosts != null ? hosts : Collections.emptySet());
106106
}
@@ -219,7 +219,7 @@ public interface Builder extends CopyableBuilder<Builder, ProxyConfiguration> {
219219
* options are not provided during building the {@link ProxyConfiguration} object. To disable this behaviour, set this
220220
* value to false.
221221
*
222-
* @param useSystemPropertyValues The option whether to use system proerpty values
222+
* @param useSystemPropertyValues The option whether to use system property values
223223
* @return This object for method chaining.
224224
*/
225225
Builder useSystemPropertyValues(Boolean useSystemPropertyValues);
@@ -243,7 +243,7 @@ private String resolveValue(String value, ProxySystemSetting systemSetting) {
243243
: value;
244244
}
245245

246-
private Set<String> parseNonProxyHostProperty() {
246+
private Set<String> parseNonProxyHostsProperty() {
247247
String nonProxyHosts = ProxySystemSetting.NON_PROXY_HOSTS.getStringValue().orElse(null);
248248

249249
if (!StringUtils.isEmpty(nonProxyHosts)) {

http-clients/netty-nio-client/src/test/java/software/amazon/awssdk/http/nio/netty/ProxyConfigurationTest.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.Random;
2424
import java.util.Set;
2525
import java.util.stream.Stream;
26+
import org.junit.AfterClass;
27+
import org.junit.Before;
2628
import org.junit.Test;
2729

2830
/**
@@ -35,12 +37,33 @@ public class ProxyConfigurationTest {
3537
private static final String TEST_USER = "testuser";
3638
private static final String TEST_PASSWORD = "123";
3739

40+
@Before
41+
public void setup() {
42+
clearProxyProperties();
43+
}
44+
45+
@AfterClass
46+
public static void cleanup() {
47+
clearProxyProperties();
48+
}
3849

3950
@Test
4051
public void build_setsAllProperties() {
4152
verifyAllPropertiesSet(allPropertiesSetConfig());
4253
}
4354

55+
@Test
56+
public void build_systemPropertyDefault() {
57+
setSystemProperty();
58+
ProxyConfiguration config = ProxyConfiguration.builder().build();
59+
60+
assertThat(config.host()).isEqualTo(TEST_HOST);
61+
assertThat(config.port()).isEqualTo(TEST_PORT);
62+
assertThat(config.username()).isEqualTo(TEST_USER);
63+
assertThat(config.password()).isEqualTo(TEST_PASSWORD);
64+
assertThat(config.scheme()).isNull();
65+
}
66+
4467
@Test
4568
public void build_systemPropertyEnabled() {
4669
setSystemProperty();
@@ -125,7 +148,7 @@ private void setRandomValue(Object o, Method setter) throws InvocationTargetExce
125148
} else if (Set.class.isAssignableFrom(paramClass)) {
126149
setter.invoke(o, randomSet());
127150
} else if (Boolean.class.equals(paramClass)) {
128-
setter.invoke(o, Boolean.FALSE);
151+
setter.invoke(o, RNG.nextBoolean());
129152
} else {
130153
throw new RuntimeException("Don't know how create random value for type " + paramClass);
131154
}
@@ -173,4 +196,11 @@ private void setSystemProperty() {
173196
System.setProperty("http.proxyUser", TEST_USER);
174197
System.setProperty("http.proxyPassword", TEST_PASSWORD);
175198
}
199+
200+
private static void clearProxyProperties() {
201+
System.clearProperty("http.proxyHost");
202+
System.clearProperty("http.proxyPort");
203+
System.clearProperty("http.proxyUser");
204+
System.clearProperty("http.proxyPassword");
205+
}
176206
}

0 commit comments

Comments
 (0)