Skip to content

Commit d78d481

Browse files
author
Stephane Landelle
committed
Merge pull request AsyncHttpClient#645 from salilsurendran/master
Added the typesafe config to read default config values
2 parents cdd9574 + b175f06 commit d78d481

File tree

8 files changed

+307
-76
lines changed

8 files changed

+307
-76
lines changed

api/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
</build>
3232

3333
<dependencies>
34+
<dependency>
35+
<groupId>com.typesafe</groupId>
36+
<artifactId>config</artifactId>
37+
<version>1.2.1</version>
38+
</dependency>
3439
<dependency>
3540
<groupId>org.slf4j</groupId>
3641
<artifactId>slf4j-api</artifactId>

api/src/main/java/org/asynchttpclient/AsyncHttpClientConfigDefaults.java

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
*/
1313
package org.asynchttpclient;
1414

15-
import static org.asynchttpclient.util.MiscUtils.getBoolean;
15+
import org.asynchttpclient.util.AsyncPropertiesHelper;
16+
import org.asynchttpclient.util.DefaultHostnameVerifier;
17+
18+
import javax.net.ssl.HostnameVerifier;
1619

1720
public final class AsyncHttpClientConfigDefaults {
1821

@@ -22,106 +25,106 @@ private AsyncHttpClientConfigDefaults() {
2225
public static final String ASYNC_CLIENT = AsyncHttpClientConfig.class.getName() + ".";
2326

2427
public static int defaultMaxConnections() {
25-
return Integer.getInteger(ASYNC_CLIENT + "maxConnections", -1);
28+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getInt(ASYNC_CLIENT + "maxConnections");
2629
}
2730

2831
public static int defaultMaxConnectionsPerHost() {
29-
return Integer.getInteger(ASYNC_CLIENT + "maxConnectionsPerHost", -1);
32+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getInt(ASYNC_CLIENT + "maxConnectionsPerHost");
3033
}
3134

3235
public static int defaultConnectionTimeout() {
33-
return Integer.getInteger(ASYNC_CLIENT + "connectionTimeout", 60 * 1000);
36+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getInt(ASYNC_CLIENT + "connectionTimeout");
3437
}
3538

3639
public static int defaultPooledConnectionIdleTimeout() {
37-
return Integer.getInteger(ASYNC_CLIENT + "pooledConnectionIdleTimeout", 60 * 1000);
40+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getInt(ASYNC_CLIENT + "pooledConnectionIdleTimeout");
3841
}
3942

4043
public static int defaultReadTimeout() {
41-
return Integer.getInteger(ASYNC_CLIENT + "readTimeout", 60 * 1000);
44+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getInt(ASYNC_CLIENT + "readTimeout");
4245
}
4346

4447
public static int defaultRequestTimeout() {
45-
return Integer.getInteger(ASYNC_CLIENT + "requestTimeout", 60 * 1000);
48+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getInt(ASYNC_CLIENT + "requestTimeout");
4649
}
4750

4851
public static int defaultWebSocketTimeout() {
49-
return Integer.getInteger(ASYNC_CLIENT + "webSocketTimeout", 15 * 60 * 1000);
52+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getInt(ASYNC_CLIENT + "webSocketTimeout");
5053
}
5154

5255
public static int defaultConnectionTTL() {
53-
return Integer.getInteger(ASYNC_CLIENT + "connectionTTL", -1);
56+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getInt(ASYNC_CLIENT + "connectionTTL");
5457
}
5558

5659
public static boolean defaultFollowRedirect() {
57-
return Boolean.getBoolean(ASYNC_CLIENT + "followRedirect");
60+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getBoolean(ASYNC_CLIENT + "followRedirect");
5861
}
5962

6063
public static int defaultMaxRedirects() {
61-
return Integer.getInteger(ASYNC_CLIENT + "maxRedirects", 5);
64+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getInt(ASYNC_CLIENT + "maxRedirects");
6265
}
6366

6467
public static boolean defaultCompressionEnforced() {
65-
return Boolean.getBoolean(ASYNC_CLIENT + "compressionEnforced");
68+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getBoolean(ASYNC_CLIENT + "compressionEnforced");
6669
}
6770

6871
public static String defaultUserAgent() {
69-
return System.getProperty(ASYNC_CLIENT + "userAgent", "AHC/2.0");
72+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getString(ASYNC_CLIENT + "userAgent");
7073
}
7174

7275
public static int defaultIoThreadMultiplier() {
73-
return Integer.getInteger(ASYNC_CLIENT + "ioThreadMultiplier", 2);
76+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getInt(ASYNC_CLIENT + "ioThreadMultiplier");
7477
}
7578

7679
public static boolean defaultUseProxySelector() {
77-
return Boolean.getBoolean(ASYNC_CLIENT + "useProxySelector");
80+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getBoolean(ASYNC_CLIENT + "useProxySelector");
7881
}
7982

8083
public static boolean defaultUseProxyProperties() {
81-
return Boolean.getBoolean(ASYNC_CLIENT + "useProxyProperties");
84+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getBoolean(ASYNC_CLIENT + "useProxyProperties");
8285
}
8386

8487
public static boolean defaultStrict302Handling() {
85-
return Boolean.getBoolean(ASYNC_CLIENT + "strict302Handling");
88+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getBoolean(ASYNC_CLIENT + "strict302Handling");
8689
}
8790

8891
public static boolean defaultAllowPoolingConnections() {
89-
return getBoolean(ASYNC_CLIENT + "allowPoolingConnections", true);
92+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getBoolean(ASYNC_CLIENT + "allowPoolingConnections");
9093
}
9194

9295
public static boolean defaultUseRelativeURIsWithConnectProxies() {
93-
return getBoolean(ASYNC_CLIENT + "useRelativeURIsWithConnectProxies", true);
94-
}
96+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getBoolean(ASYNC_CLIENT + "useRelativeURIsWithConnectProxies");
97+
}
9598

9699
public static int defaultMaxRequestRetry() {
97-
return Integer.getInteger(ASYNC_CLIENT + "maxRequestRetry", 5);
100+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getInt(ASYNC_CLIENT + "maxRequestRetry");
98101
}
99102

100103
public static boolean defaultAllowPoolingSslConnections() {
101-
return getBoolean(ASYNC_CLIENT + "allowPoolingSslConnections", true);
104+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getBoolean(ASYNC_CLIENT + "allowPoolingSslConnections");
102105
}
103106

104107
public static boolean defaultDisableUrlEncodingForBoundRequests() {
105-
return Boolean.getBoolean(ASYNC_CLIENT + "disableUrlEncodingForBoundRequests");
108+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getBoolean(ASYNC_CLIENT + "disableUrlEncodingForBoundRequests");
106109
}
107110

108111
public static boolean defaultRemoveQueryParamOnRedirect() {
109-
return getBoolean(ASYNC_CLIENT + "removeQueryParamOnRedirect", true);
112+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getBoolean(ASYNC_CLIENT + "removeQueryParamOnRedirect");
110113
}
111114

112115
public static boolean defaultSpdyEnabled() {
113-
return Boolean.getBoolean(ASYNC_CLIENT + "spdyEnabled");
116+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getBoolean(ASYNC_CLIENT + "spdyEnabled");
114117
}
115118

116119
public static int defaultSpdyInitialWindowSize() {
117-
return Integer.getInteger(ASYNC_CLIENT + "spdyInitialWindowSize", 10 * 1024 * 1024);
120+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getInt(ASYNC_CLIENT + "spdyInitialWindowSize");
118121
}
119122

120123
public static int defaultSpdyMaxConcurrentStreams() {
121-
return Integer.getInteger(ASYNC_CLIENT + "spdyMaxConcurrentStreams", 100);
124+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getInt(ASYNC_CLIENT + "spdyMaxConcurrentStreams");
122125
}
123126

124127
public static boolean defaultAcceptAnyCertificate() {
125-
return getBoolean(ASYNC_CLIENT + "acceptAnyCertificate", false);
128+
return AsyncPropertiesHelper.getAsyncHttpClientConfig().getBoolean(ASYNC_CLIENT + "acceptAnyCertificate");
126129
}
127130
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.asynchttpclient.util;
2+
3+
import com.typesafe.config.Config;
4+
import com.typesafe.config.ConfigFactory;
5+
6+
public class AsyncPropertiesHelper {
7+
8+
public static final String ASYNC_HTTP_CLIENT_IMPL_PROPERTIES_FILE = "ahc.properties";
9+
public static final String DEFAULTAHC_PROPERTIES = "ahc-default.properties";
10+
11+
public static Config getAsyncHttpClientConfig(){
12+
return ConfigFactory.load(ASYNC_HTTP_CLIENT_IMPL_PROPERTIES_FILE)
13+
.withFallback(ConfigFactory.load(DEFAULTAHC_PROPERTIES));
14+
}
15+
16+
/**
17+
* This method invalidates the property caches. So if a system property has been changed and the
18+
* effect of this change is to be seen then call reloadProperties() and then getAsyncHttpClientConfig()
19+
* to get the new property values.
20+
*/
21+
public static void reloadProperties(){
22+
ConfigFactory.invalidateCaches();
23+
}
24+
25+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
org.asynchttpclient.AsyncHttpClientConfig.maxConnections=-1
2+
org.asynchttpclient.AsyncHttpClientConfig.maxConnectionsPerHost=-1
3+
org.asynchttpclient.AsyncHttpClientConfig.connectionTimeout=60000
4+
org.asynchttpclient.AsyncHttpClientConfig.pooledConnectionIdleTimeout=60000
5+
org.asynchttpclient.AsyncHttpClientConfig.readTimeout=60000
6+
org.asynchttpclient.AsyncHttpClientConfig.requestTimeout=60000
7+
org.asynchttpclient.AsyncHttpClientConfig.webSocketTimeout=900000
8+
org.asynchttpclient.AsyncHttpClientConfig.connectionTTL=-1
9+
org.asynchttpclient.AsyncHttpClientConfig.followRedirect=false
10+
org.asynchttpclient.AsyncHttpClientConfig.maxRedirects=5
11+
org.asynchttpclient.AsyncHttpClientConfig.compressionEnforced=false
12+
org.asynchttpclient.AsyncHttpClientConfig.userAgent=NING/1.0
13+
org.asynchttpclient.AsyncHttpClientConfig.ioThreadMultiplier=2
14+
org.asynchttpclient.AsyncHttpClientConfig.useProxySelector=false
15+
org.asynchttpclient.AsyncHttpClientConfig.useProxyProperties=false
16+
org.asynchttpclient.AsyncHttpClientConfig.strict302Handling=false
17+
org.asynchttpclient.AsyncHttpClientConfig.allowPoolingConnections=true
18+
org.asynchttpclient.AsyncHttpClientConfig.useRelativeURIsWithConnectProxies=true
19+
org.asynchttpclient.AsyncHttpClientConfig.requestCompressionLevel=-1
20+
org.asynchttpclient.AsyncHttpClientConfig.maxRequestRetry=5
21+
org.asynchttpclient.AsyncHttpClientConfig.allowPoolingSslConnections=true
22+
org.asynchttpclient.AsyncHttpClientConfig.disableUrlEncodingForBoundRequests=false
23+
org.asynchttpclient.AsyncHttpClientConfig.removeQueryParamOnRedirect=true
24+
org.asynchttpclient.AsyncHttpClientConfig.spdyEnabled=false
25+
org.asynchttpclient.AsyncHttpClientConfig.spdyInitialWindowSize=10485760
26+
org.asynchttpclient.AsyncHttpClientConfig.spdyMaxConcurrentStreams=100
27+
org.asynchttpclient.AsyncHttpClientConfig.acceptAnyCertificate=false

0 commit comments

Comments
 (0)