@@ -123,29 +123,53 @@ public ApacheHttpTransport(HttpClient httpClient) {
123
123
* @since 1.30
124
124
*/
125
125
public static HttpClient newDefaultHttpClient () {
126
+ return newDefaultHttpClientBuilder ().build ();
127
+ }
128
+
129
+ /**
130
+ * Creates a new Apache HTTP client builder that is used by the
131
+ * {@link #ApacheHttpTransport()} constructor.
132
+ *
133
+ * <p>
134
+ * Settings:
135
+ * </p>
136
+ * <ul>
137
+ * <li>The client connection manager is set to {@link PoolingHttpClientConnectionManager}.</li>
138
+ * <li>The socket buffer size is set to 8192 using {@link SocketConfig}.</li>
139
+ * <li><The retry mechanism is turned off using
140
+ * {@link HttpClientBuilder#disableRedirectHandling}.</li>
141
+ * <li>The route planner uses {@link SystemDefaultRoutePlanner} with
142
+ * {@link ProxySelector#getDefault()}, which uses the proxy settings from <a
143
+ * href="http://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html">system
144
+ * properties</a>.</li>
145
+ * </ul>
146
+ *
147
+ * @return new instance of the Apache HTTP client
148
+ * @since 1.31
149
+ */
150
+ public static HttpClientBuilder newDefaultHttpClientBuilder () {
126
151
// Set socket buffer sizes to 8192
127
152
SocketConfig socketConfig =
128
- SocketConfig .custom ()
129
- .setRcvBufSize (8192 )
130
- .setSndBufSize (8192 )
131
- .build ();
153
+ SocketConfig .custom ()
154
+ .setRcvBufSize (8192 )
155
+ .setSndBufSize (8192 )
156
+ .build ();
132
157
133
158
PoolingHttpClientConnectionManager connectionManager =
134
- new PoolingHttpClientConnectionManager (-1 , TimeUnit .MILLISECONDS );
159
+ new PoolingHttpClientConnectionManager (-1 , TimeUnit .MILLISECONDS );
135
160
// Disable the stale connection check (previously configured in the HttpConnectionParams
136
161
connectionManager .setValidateAfterInactivity (-1 );
137
162
138
163
return HttpClientBuilder .create ()
139
- .useSystemProperties ()
140
- .setSSLSocketFactory (SSLConnectionSocketFactory .getSocketFactory ())
141
- .setDefaultSocketConfig (socketConfig )
142
- .setMaxConnTotal (200 )
143
- .setMaxConnPerRoute (20 )
144
- .setRoutePlanner (new SystemDefaultRoutePlanner (ProxySelector .getDefault ()))
145
- .setConnectionManager (connectionManager )
146
- .disableRedirectHandling ()
147
- .disableAutomaticRetries ()
148
- .build ();
164
+ .useSystemProperties ()
165
+ .setSSLSocketFactory (SSLConnectionSocketFactory .getSocketFactory ())
166
+ .setDefaultSocketConfig (socketConfig )
167
+ .setMaxConnTotal (200 )
168
+ .setMaxConnPerRoute (20 )
169
+ .setRoutePlanner (new SystemDefaultRoutePlanner (ProxySelector .getDefault ()))
170
+ .setConnectionManager (connectionManager )
171
+ .disableRedirectHandling ()
172
+ .disableAutomaticRetries ();
149
173
}
150
174
151
175
@ Override
0 commit comments