@@ -1336,7 +1336,8 @@ public static Client getClient(KeyStore keyStore, String keyStorePassword, KeySt
13361336 if (keyStore == null ) throw new IllegalArgumentException ("KeyStore cannot be null" );
13371337 if (keyStorePassword == null ) throw new IllegalArgumentException ("KeyStore password string cannot be null" );
13381338 if (trustStore == null ) throw new IllegalArgumentException ("KeyStore (truststore) cannot be null" );
1339-
1339+ Integer connIdleTimeout = 5000 ;
1340+
13401341 // for client authentication
13411342 KeyManagerFactory kmf = KeyManagerFactory .getInstance (KeyManagerFactory .getDefaultAlgorithm ());
13421343 kmf .init (keyStore , keyStorePassword .toCharArray ());
@@ -1384,6 +1385,8 @@ public void releaseConnection(final HttpClientConnection managedConn, final Obje
13841385 };
13851386 if (maxConnPerRoute != null ) conman .setDefaultMaxPerRoute (maxConnPerRoute );
13861387 if (maxTotalConn != null ) conman .setMaxTotal (maxTotalConn );
1388+ conman .setValidateAfterInactivity (connIdleTimeout ); // check connections idle for more than Varnish's idle_timeout which is 5s
1389+ //conman.closeIdleConnections(connIdleTimeout, TimeUnit.MILLISECONDS); // match the Varnish idle timeout
13871390
13881391 ClientConfig config = new ClientConfig ();
13891392 config .connectorProvider (new ApacheConnectorProvider ());
@@ -1394,7 +1397,7 @@ public void releaseConnection(final HttpClientConnection managedConn, final Obje
13941397 config .register (new QueryProvider ());
13951398 config .register (new UpdateRequestProvider ());
13961399 config .property (ClientProperties .FOLLOW_REDIRECTS , true );
1397- config .property (ClientProperties .CONNECT_TIMEOUT , 1000 );
1400+ // config.property(ClientProperties.CONNECT_TIMEOUT, 1000);
13981401 config .property (ClientProperties .REQUEST_ENTITY_PROCESSING , RequestEntityProcessing .BUFFERED ); // https://stackoverflow.com/questions/42139436/jersey-client-throws-cannot-retry-request-with-a-non-repeatable-request-entity
13991402 config .property (ApacheClientProperties .CONNECTION_MANAGER , conman );
14001403 //config.property(ApacheClientProperties.CONNECTION_CLOSING_STRATEGY, new ApacheConnectionClosingStrategy.GracefulClosingStrategy());
0 commit comments