4949import org .apache .http .client .methods .HttpPut ;
5050import org .apache .http .client .methods .HttpRequestBase ;
5151import org .apache .http .client .utils .URLEncodedUtils ;
52+ import org .apache .http .config .Registry ;
53+ import org .apache .http .config .RegistryBuilder ;
5254import org .apache .http .conn .ConnectionKeepAliveStrategy ;
55+ import org .apache .http .conn .socket .ConnectionSocketFactory ;
56+ import org .apache .http .conn .socket .PlainConnectionSocketFactory ;
57+ import org .apache .http .conn .ssl .SSLConnectionSocketFactory ;
5358import org .apache .http .entity .ContentType ;
5459import org .apache .http .entity .StringEntity ;
5560import org .apache .http .impl .auth .BasicScheme ;
6267import org .apache .http .message .BasicNameValuePair ;
6368import org .apache .http .protocol .HTTP ;
6469import org .apache .http .protocol .HttpContext ;
70+ import org .apache .http .ssl .SSLContexts ;
6571import org .slf4j .Logger ;
6672import org .slf4j .LoggerFactory ;
6773
@@ -95,9 +101,7 @@ public class HttpManager {
95101 private Map <String , InvocationObject > jobs = new HashMap <String , InvocationObject >();
96102
97103 public static enum HttpMode {
98- SYNC ,
99- ASYNC ,
100- FIREANDFORGET
104+ SYNC , ASYNC , FIREANDFORGET
101105 }
102106
103107 public HttpManager (ArangoConfigure configure ) {
@@ -109,8 +113,23 @@ public ArangoConfigure getConfiguration() {
109113 }
110114
111115 public void init () {
116+ // socket factory for HTTP
117+ ConnectionSocketFactory plainsf = new PlainConnectionSocketFactory ();
118+
119+ // socket factory for HTTPS
120+ SSLConnectionSocketFactory sslsf = null ;
121+ if (configure .getSslContext () != null ) {
122+ sslsf = new SSLConnectionSocketFactory (configure .getSslContext ());
123+ } else {
124+ sslsf = new SSLConnectionSocketFactory (SSLContexts .createSystemDefault ());
125+ }
126+
127+ // register socket factories
128+ Registry <ConnectionSocketFactory > r = RegistryBuilder .<ConnectionSocketFactory > create ()
129+ .register ("http" , plainsf ).register ("https" , sslsf ).build ();
130+
112131 // ConnectionManager
113- cm = new PoolingHttpClientConnectionManager ();
132+ cm = new PoolingHttpClientConnectionManager (r );
114133 cm .setDefaultMaxPerRoute (configure .getMaxPerConnection ());
115134 cm .setMaxTotal (configure .getMaxTotalConnection ());
116135
@@ -137,7 +156,8 @@ public void init() {
137156 @ Override
138157 public long getKeepAliveDuration (HttpResponse response , HttpContext context ) {
139158 // Honor 'keep-alive' header
140- HeaderElementIterator it = new BasicHeaderElementIterator (response .headerIterator (HTTP .CONN_KEEP_ALIVE ));
159+ HeaderElementIterator it = new BasicHeaderElementIterator (
160+ response .headerIterator (HTTP .CONN_KEEP_ALIVE ));
141161 while (it .hasNext ()) {
142162 HeaderElement he = it .nextElement ();
143163 String param = he .getName ();
@@ -281,8 +301,11 @@ public HttpResponseEntity doPostWithHeaders(
281301 return doPostPutPatch (RequestType .POST , url , headers , params , body , entity );
282302 }
283303
284- public HttpResponseEntity doPut (String url , Map <String , Object > headers , Map <String , Object > params , String bodyText )
285- throws ArangoException {
304+ public HttpResponseEntity doPut (
305+ String url ,
306+ Map <String , Object > headers ,
307+ Map <String , Object > params ,
308+ String bodyText ) throws ArangoException {
286309 return doPostPutPatch (RequestType .PUT , url , headers , params , bodyText , null );
287310 }
288311
@@ -365,19 +388,19 @@ public HttpResponseEntity execute(HttpRequestEntity requestEntity) throws Arango
365388 * @return the response of the request
366389 * @throws ArangoException
367390 */
368- private HttpResponseEntity executeInternal (String baseUrl , HttpRequestEntity requestEntity ) throws ArangoException ,
369- SocketException {
391+ private HttpResponseEntity executeInternal (String baseUrl , HttpRequestEntity requestEntity )
392+ throws ArangoException , SocketException {
370393
371394 String url = buildUrl (baseUrl , requestEntity );
372395
373396 if (logger .isDebugEnabled ()) {
374397 if (requestEntity .type == RequestType .POST || requestEntity .type == RequestType .PUT
375398 || requestEntity .type == RequestType .PATCH ) {
376- logger .debug ("[REQ]http-{}: url={}, headers={}, body={}" , new Object [] { requestEntity . type , url ,
377- requestEntity .headers , requestEntity .bodyText });
399+ logger .debug ("[REQ]http-{}: url={}, headers={}, body={}" ,
400+ new Object [] { requestEntity . type , url , requestEntity .headers , requestEntity .bodyText });
378401 } else {
379- logger .debug ("[REQ]http-{}: url={}, headers={}" , new Object [] { requestEntity . type , url ,
380- requestEntity .headers });
402+ logger .debug ("[REQ]http-{}: url={}, headers={}" ,
403+ new Object [] { requestEntity . type , url , requestEntity .headers });
381404 }
382405 }
383406
0 commit comments