Skip to content

Commit b11c7e3

Browse files
author
Stephane Landelle
committed
Revert "Pick up default config values from asynchttpclient.properties file"
1 parent 65579bd commit b11c7e3

File tree

7 files changed

+35
-294
lines changed

7 files changed

+35
-294
lines changed

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

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

15+
import static org.asynchttpclient.util.MiscUtil.getBoolean;
1516

16-
17-
import static org.asynchttpclient.util.MiscUtil.getBooleanValue;
18-
import static org.asynchttpclient.util.MiscUtil.getIntValue;
1917
import org.asynchttpclient.util.DefaultHostnameVerifier;
2018

2119
import javax.net.ssl.HostnameVerifier;
2220

23-
24-
2521
public final class AsyncHttpClientConfigDefaults {
2622

27-
2823
private AsyncHttpClientConfigDefaults() {
2924
}
3025

3126
public static final String ASYNC_CLIENT = AsyncHttpClientConfig.class.getName() + ".";
3227

3328
public static int defaultMaxTotalConnections() {
34-
return getIntValue(ASYNC_CLIENT + "maxTotalConnections", -1);
29+
return Integer.getInteger(ASYNC_CLIENT + "maxTotalConnections", -1);
3530
}
3631

3732
public static int defaultMaxConnectionPerHost() {
38-
return getIntValue(ASYNC_CLIENT + "maxConnectionsPerHost", -1);
33+
return Integer.getInteger(ASYNC_CLIENT + "maxConnectionsPerHost", -1);
3934
}
4035

4136
public static int defaultConnectionTimeOutInMs() {
42-
return getIntValue(ASYNC_CLIENT + "connectionTimeoutInMs", 60 * 1000);
37+
return Integer.getInteger(ASYNC_CLIENT + "connectionTimeoutInMs", 60 * 1000);
4338
}
4439

4540
public static int defaultIdleConnectionInPoolTimeoutInMs() {
46-
return getIntValue(ASYNC_CLIENT + "idleConnectionInPoolTimeoutInMs", 60 * 1000);
41+
return Integer.getInteger(ASYNC_CLIENT + "idleConnectionInPoolTimeoutInMs", 60 * 1000);
4742
}
4843

4944
public static int defaultIdleConnectionTimeoutInMs() {
50-
return getIntValue(ASYNC_CLIENT + "idleConnectionTimeoutInMs", 60 * 1000);
45+
return Integer.getInteger(ASYNC_CLIENT + "idleConnectionTimeoutInMs", 60 * 1000);
5146
}
5247

5348
public static int defaultRequestTimeoutInMs() {
54-
return getIntValue(ASYNC_CLIENT + "requestTimeoutInMs", 60 * 1000);
49+
return Integer.getInteger(ASYNC_CLIENT + "requestTimeoutInMs", 60 * 1000);
5550
}
5651

5752
public static int defaultWebSocketIdleTimeoutInMs() {
58-
return getIntValue(ASYNC_CLIENT + "webSocketTimoutInMS", 15 * 60 * 1000);
53+
return Integer.getInteger(ASYNC_CLIENT + "webSocketTimoutInMS", 15 * 60 * 1000);
5954
}
6055

6156
public static int defaultMaxConnectionLifeTimeInMs() {
62-
return getIntValue(ASYNC_CLIENT + "maxConnectionLifeTimeInMs", -1);
57+
return Integer.getInteger(ASYNC_CLIENT + "maxConnectionLifeTimeInMs", -1);
6358
}
6459

6560
public static boolean defaultRedirectEnabled() {
66-
return getBooleanValue(ASYNC_CLIENT + "redirectsEnabled",false);
61+
return Boolean.getBoolean(ASYNC_CLIENT + "redirectsEnabled");
6762
}
6863

6964
public static int defaultMaxRedirects() {
70-
return getIntValue(ASYNC_CLIENT + "maxRedirects", 5);
65+
return Integer.getInteger(ASYNC_CLIENT + "maxRedirects", 5);
7166
}
7267

7368
public static boolean defaultCompressionEnabled() {
74-
return getBooleanValue(ASYNC_CLIENT + "compressionEnabled",false);
69+
return Boolean.getBoolean(ASYNC_CLIENT + "compressionEnabled");
7570
}
7671

7772
public static String defaultUserAgent() {
7873
return System.getProperty(ASYNC_CLIENT + "userAgent", "NING/1.0");
7974
}
8075

8176
public static int defaultIoThreadMultiplier() {
82-
return getIntValue(ASYNC_CLIENT + "ioThreadMultiplier", 2);
77+
return Integer.getInteger(ASYNC_CLIENT + "ioThreadMultiplier", 2);
8378
}
8479

8580
public static boolean defaultUseProxySelector() {
86-
return getBooleanValue(ASYNC_CLIENT + "useProxySelector",false);
81+
return Boolean.getBoolean(ASYNC_CLIENT + "useProxySelector");
8782
}
8883

8984
public static boolean defaultUseProxyProperties() {
90-
return getBooleanValue(ASYNC_CLIENT + "useProxyProperties",false);
85+
return Boolean.getBoolean(ASYNC_CLIENT + "useProxyProperties");
9186
}
9287

9388
public static boolean defaultStrict302Handling() {
94-
return getBooleanValue(ASYNC_CLIENT + "strict302Handling",false);
89+
return Boolean.getBoolean(ASYNC_CLIENT + "strict302Handling");
9590
}
9691

9792
public static boolean defaultAllowPoolingConnection() {
98-
return getBooleanValue(ASYNC_CLIENT + "allowPoolingConnection", true);
93+
return getBoolean(ASYNC_CLIENT + "allowPoolingConnection", true);
9994
}
10095

10196
public static boolean defaultUseRelativeURIsWithSSLProxies() {
102-
return getBooleanValue(ASYNC_CLIENT + "useRelativeURIsWithSSLProxies", true);
97+
return getBoolean(ASYNC_CLIENT + "useRelativeURIsWithSSLProxies", true);
10398
}
10499

105100
// unused/broken, left there for compatibility, fixed in Netty 4
106101
public static int defaultRequestCompressionLevel() {
107-
return getIntValue(ASYNC_CLIENT + "requestCompressionLevel", -1);
102+
return Integer.getInteger(ASYNC_CLIENT + "requestCompressionLevel", -1);
108103
}
109104

110105
public static int defaultMaxRequestRetry() {
111-
return getIntValue(ASYNC_CLIENT + "maxRequestRetry", 5);
106+
return Integer.getInteger(ASYNC_CLIENT + "maxRequestRetry", 5);
112107
}
113108

114109
public static boolean defaultAllowSslConnectionPool() {
115-
return getBooleanValue(ASYNC_CLIENT + "allowSslConnectionPool", true);
110+
return getBoolean(ASYNC_CLIENT + "allowSslConnectionPool", true);
116111
}
117112

118113
public static boolean defaultUseRawUrl() {
119-
return getBooleanValue(ASYNC_CLIENT + "useRawUrl",false);
114+
return Boolean.getBoolean(ASYNC_CLIENT + "useRawUrl");
120115
}
121116

122117
public static boolean defaultRemoveQueryParamOnRedirect() {
123-
return getBooleanValue(ASYNC_CLIENT + "removeQueryParamOnRedirect", true);
118+
return getBoolean(ASYNC_CLIENT + "removeQueryParamOnRedirect", true);
124119
}
125120

126121
public static HostnameVerifier defaultHostnameVerifier() {
127122
return new DefaultHostnameVerifier();
128123
}
129124

130125
public static boolean defaultSpdyEnabled() {
131-
return getBooleanValue(ASYNC_CLIENT + "spdyEnabled",false);
126+
return Boolean.getBoolean(ASYNC_CLIENT + "spdyEnabled");
132127
}
133128

134129
public static int defaultSpdyInitialWindowSize() {
135-
return getIntValue(ASYNC_CLIENT + "spdyInitialWindowSize", 10 * 1024 * 1024);
130+
return Integer.getInteger(ASYNC_CLIENT + "spdyInitialWindowSize", 10 * 1024 * 1024);
136131
}
137132

138133
public static int defaultSpdyMaxConcurrentStreams() {
139-
return getIntValue(ASYNC_CLIENT + "spdyMaxConcurrentStreams", 100);
134+
return Integer.getInteger(ASYNC_CLIENT + "spdyMaxConcurrentStreams", 100);
140135
}
141136

142137
public static boolean defaultAcceptAnyCertificate() {

api/src/main/java/org/asynchttpclient/util/AsyncImplHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static Class<AsyncHttpClient> getAsyncImplClass(String propertyName) {
5959
return asyncHttpClientImplClass;
6060
}
6161

62-
public static Properties getAsyncImplProperties() {
62+
private static Properties getAsyncImplProperties() {
6363
try {
6464
return AccessController.doPrivileged(new PrivilegedExceptionAction<Properties>() {
6565
public Properties run() throws IOException {

api/src/main/java/org/asynchttpclient/util/MiscUtil.java

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,11 @@
1212
*/
1313
package org.asynchttpclient.util;
1414

15-
import org.slf4j.Logger;
16-
import org.slf4j.LoggerFactory;
1715
import java.util.Collection;
1816
import java.util.Map;
19-
import java.util.Properties;
2017

2118
public class MiscUtil {
2219

23-
public final static Logger logger = LoggerFactory.getLogger(MiscUtil.class);
24-
2520
private MiscUtil() {
2621
}
2722

@@ -45,69 +40,12 @@ public static boolean isNonEmpty(Map<?, ?> map) {
4540
return map != null && !map.isEmpty();
4641
}
4742

48-
// The getBooleanValue() method replaces this and reads the property from
49-
// properties file
50-
// too. Plus has a better check for invalid boolean values.
51-
/*
52-
* public static boolean getBoolean(String systemPropName, boolean
53-
* defaultValue) { String systemPropValue =
54-
* System.getProperty(systemPropName); return systemPropValue != null ?
55-
* systemPropValue.equalsIgnoreCase("true") : defaultValue; }
56-
*/
57-
58-
public static Integer getIntValue(String property, int defaultValue) {
59-
// Read system property and if not null return that.
60-
Integer value = Integer.getInteger(property);
61-
if (value != null)
62-
return value;
63-
Properties asyncHttpClientConfigProperties = AsyncImplHelper.getAsyncImplProperties();
64-
if (asyncHttpClientConfigProperties != null) {
65-
String valueString = asyncHttpClientConfigProperties.getProperty(property);
66-
try {
67-
// If property is present and is non null parse it.
68-
if (valueString != null)
69-
return Integer.parseInt(valueString);
70-
} catch (NumberFormatException e) {
71-
// If property couldn't be parsed log the error message and
72-
// return default value.
73-
logger.error("Property : " + property + " has value = " + valueString
74-
+ " which couldn't be parsed to an int value. Returning default value: " + defaultValue, e);
75-
}
76-
}
77-
return defaultValue;
78-
}
79-
80-
private static boolean isValidBooleanValue(String value) {
81-
return value != null && ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value));
43+
public static boolean getBoolean(String systemPropName, boolean defaultValue) {
44+
String systemPropValue = System.getProperty(systemPropName);
45+
return systemPropValue != null ? systemPropValue.equalsIgnoreCase("true") : defaultValue;
8246
}
8347

84-
85-
public static Boolean getBooleanValue(String property, boolean defaultValue) {
86-
87-
// get from System property first
88-
String value = System.getProperty(property);
89-
if (isValidBooleanValue(value))
90-
return Boolean.parseBoolean(value);
91-
92-
// get from property file
93-
Properties asyncHttpClientConfigProperties = AsyncImplHelper.getAsyncImplProperties();
94-
if (asyncHttpClientConfigProperties != null) {
95-
value = asyncHttpClientConfigProperties.getProperty(property);
96-
if (isValidBooleanValue(value))
97-
return Boolean.parseBoolean(value);
98-
}
99-
100-
// have to use the default value now
101-
if (value != null)
102-
logger.error("Property : " + property + " has value = " + value
103-
+ " which couldn't be parsed to an boolean value. Returning default value: " + defaultValue);
104-
105-
return defaultValue;
106-
}
107-
108-
10948
public static <T> T withDefault(T value, T defaults) {
11049
return value != null? value : value;
11150
}
112-
11351
}

api/src/test/java/org/asynchttpclient/AsyncHttpClientConfigBuilderTest.java

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

api/src/test/java/org/asynchttpclient/AsyncImplHelperMock.java

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

0 commit comments

Comments
 (0)