hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: PoolingClientConnectionManager lease/release connection problem with SSLConnectionFactory
Date Fri, 20 Jan 2017 19:07:05 GMT
On Fri, 2017-01-20 at 15:17 +0800, sdy wrote:
> hi, folks,
>               I'm working with httpclient (4.2.1) on suse linux
> enterprise server 11(x86_64),  and construct the connectionpool
> manager code as follow:
> 
> 
>  KeyStore keyStore = getKeyStore(KEY_STORE_CLIENT_PATH,
> KEY_STORE_CLIENT_PASS);
> KeyStore trustStore = getKeyStore(KEY_STORE_TRUST_PATH,
> KEY_STORE_TRUST_PASS);
> socketFactory = new SSLSocketFactory(keyStore, KEY_STORE_CLIENT_PASS,
> trustStore);
> socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME
> _VERIFIER);    
> connManager = new PoolingClientConnectionManager();  
> connManager.setMaxTotal(100);  
> connManager.setDefaultMaxPerRoute(100);  
> connManager.getSchemeRegistry().register(new Scheme("https", 443,
> socketFactory));
> params = new BasicHttpParams();
> params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,5000);
> params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 5000);
> httpClient = new DefaultHttpClient(connManager, params);
> 
> 
> 
> 
> and do the post request with the following method:
> 
> 
> private String doPost(String url, String payload) {
> HttpPost httpPost = null;
> String result = null;
> HttpResponse response = null;
>         try {
>         httpPost = new HttpPost(url);
> StringEntity postEntity = new StringEntity(payload);
> httpPost.setEntity(postEntity);
> httpPost.addHeader("Content-Type", "application/json");
> httpPost.addHeader("Authorization", "Basic " + this.authString);
> response = this.httpClient.execute(httpPost);
> result = EntityUtils.toString(response.getEntity());
> EntityUtils.consume(response.getEntity());
>         } catch (Exception e) { 
>         e.printStackTrace();
>         return null;
>         }finally {
>         if(response != null){
>         if(response.getEntity() != null){
>         InputStream input;
> try {
> input = response.getEntity().getContent();
> if(input != null){
>        input.close();
>        }
> } catch (IllegalStateException | IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>         }
>         }
>         }
>         return result;
>     }
> 
> 
>     the problem for me is that I want to use the keep-alive ability
> of PoolingClientConnectionManager, but the httpclient close the
> connection after the single post request.  the debug log as follow.
> Who konws 
>     what's wrong? Is it the bug of the httpclient ? or I have done
> something wrong with my code?
> 
> 


There is nothing wrong. Connections associated with a particular SSL
principal are considered state-full. Please see this section of the
tutorial 

http://hc.apache.org/httpcomponents-client-4.5.x/tutorial/html/advanced
.html#stateful_conn

Oleg


> DEBUG [org.apache.http.impl.conn.PoolingClientConnectionManager]
> Connection request: [route: {s}->https://api.svip.jiguang.cn][total
> kept alive: 100; route allocated: 100 of 100; total allocated: 100 of
> 100]
> DEBUG [org.apache.http.impl.conn.DefaultClientConnection] Connection
> 0.0.0.0:37394<->183.240.12.100:443 closed
> DEBUG [org.apache.http.impl.conn.PoolingClientConnectionManager]
> Connection leased: [id: 100][route: {s}->https://api.svip.jiguang.cn]
> [total kept alive: 99; route allocated: 100 of 100; total allocated:
> 100 of 100]
> DEBUG [org.apache.http.impl.conn.DefaultClientConnectionOperator]
> Connecting to api.svip.jiguang.cn:443
> DEBUG [org.apache.http.client.protocol.RequestAddCookies] CookieSpec
> selected: best-match
> DEBUG [org.apache.http.client.protocol.RequestAuthCache] Auth cache
> not set in the context
> DEBUG [org.apache.http.client.protocol.RequestProxyAuthentication]
> Proxy auth state: UNCHALLENGED
> DEBUG [org.apache.http.impl.client.DefaultHttpClient] Attempt 1 to
> execute request
> DEBUG [org.apache.http.impl.conn.DefaultClientConnection] Sending
> request: POST /v3/push HTTP/1.1
> DEBUG [org.apache.http.headers] >> POST /v3/push HTTP/1.1
> DEBUG [org.apache.http.headers] >> Content-Type: application/json
> DEBUG [org.apache.http.headers] >> Authorization: Basic
> ZGQxMjEwYWJhYTNhZWZmYTFkMDZjNDhlOjA5MjRiZThhMDdlNWJiZjViYTdkYTNmZA==
> DEBUG [org.apache.http.headers] >> Content-Length: 471
> DEBUG [org.apache.http.headers] >> Host: api.svip.jiguang.cn
> DEBUG [org.apache.http.headers] >> Connection: Keep-Alive
> DEBUG [org.apache.http.impl.conn.DefaultClientConnection] Receiving
> response: HTTP/1.1 200 OK
> DEBUG [org.apache.http.headers] << HTTP/1.1 200 OK
> DEBUG [org.apache.http.headers] << Server: nginx
> DEBUG [org.apache.http.headers] << Date: Fri, 20 Jan 2017 07:05:02
> GMT
> DEBUG [org.apache.http.headers] << Content-Type: application/json
> DEBUG [org.apache.http.headers] << Transfer-Encoding: chunked
> DEBUG [org.apache.http.headers] << Connection: keep-alive
> DEBUG [org.apache.http.headers] << X-Rate-Limit-Limit: 33000
> DEBUG [org.apache.http.headers] << X-Rate-Limit-Remaining: 32799
> DEBUG [org.apache.http.headers] << X-Rate-Limit-Reset: 4
> DEBUG [org.apache.http.headers] << X-JPush-MsgId: 3073146139
> DEBUG [org.apache.http.impl.client.DefaultHttpClient] Connection can
> be kept alive indefinitely
> DEBUG [org.apache.http.impl.conn.PoolingClientConnectionManager]
> Connection [id: 100][route: {s}->https://api.svip.jiguang.cn][state:
> CN=unionpayhce.svip.jiguang.cn, O=Shenzhen HeXunHuaGu Information
> Technologies Co.Ltd, L=Shenzhen, ST=GuangDong, C=CN] can be kept
> alive indefinitely
> DEBUG [org.apache.http.impl.conn.PoolingClientConnectionManager]
> Connection released: [id: 100][route: {s}->https://api.svip.jiguang.c
> n][state: CN=unionpayhce.svip.jiguang.cn, O=Shenzhen HeXunHuaGu
> Information Technologies Co.Ltd, L=Shenzhen, ST=GuangDong,
> C=CN][total kept alive: 100; route allocated: 100 of 100; total
> allocated: 100 of 100]
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message