diff --git a/connectors/apache-connector/src/main/java/org/glassfish/jersey/apache/connector/ApacheClientProperties.java b/connectors/apache-connector/src/main/java/org/glassfish/jersey/apache/connector/ApacheClientProperties.java index 6f87627e87..cca39ebf79 100644 --- a/connectors/apache-connector/src/main/java/org/glassfish/jersey/apache/connector/ApacheClientProperties.java +++ b/connectors/apache-connector/src/main/java/org/glassfish/jersey/apache/connector/ApacheClientProperties.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -134,6 +134,28 @@ public final class ApacheClientProperties { */ public static final String RETRY_HANDLER = "jersey.config.apache.client.retryHandler"; + /** + * ConnectionReuseStrategy for the {@link org.apache.http.client.HttpClient}. + *

+ * The value MUST be an instance of {@link org.apache.http.impl.ConnectionReuseStrategy}. + *

+ * If the property is absent the default reuse strategy of the Apache HTTP library will be used + *

+ * The name of the configuration property is {@value}. + */ + public static final String REUSE_STRATEGY = "jersey.config.apache.client.reuseStrategy"; + + /** + * ConnectionKeepAliveStrategy for the {@link org.apache.http.client.HttpClient}. + *

+ * The value MUST be an instance of {@link org.apache.http.conn.ConnectionKeepAliveStrategy}. + *

+ * If the property is absent the default keepalive strategy of the Apache HTTP library will be used + *

+ * The name of the configuration property is {@value}. + */ + public static final String KEEPALIVE_STRATEGY = "jersey.config.apache.client.keepAliveStrategy"; + /** * Get the value of the specified property. * diff --git a/connectors/apache-connector/src/main/java/org/glassfish/jersey/apache/connector/ApacheConnector.java b/connectors/apache-connector/src/main/java/org/glassfish/jersey/apache/connector/ApacheConnector.java index 693a8d36b2..7377cfeccb 100644 --- a/connectors/apache-connector/src/main/java/org/glassfish/jersey/apache/connector/ApacheConnector.java +++ b/connectors/apache-connector/src/main/java/org/glassfish/jersey/apache/connector/ApacheConnector.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -56,7 +56,7 @@ import org.glassfish.jersey.message.internal.OutboundMessageContext; import org.glassfish.jersey.message.internal.ReaderWriter; import org.glassfish.jersey.message.internal.Statuses; - +import org.apache.http.ConnectionReuseStrategy; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpHost; @@ -76,6 +76,7 @@ import org.apache.http.config.ConnectionConfig; import org.apache.http.config.Registry; import org.apache.http.config.RegistryBuilder; +import org.apache.http.conn.ConnectionKeepAliveStrategy; import org.apache.http.conn.HttpClientConnectionManager; import org.apache.http.conn.ManagedHttpClientConnection; import org.apache.http.conn.routing.HttpRoute; @@ -111,12 +112,14 @@ *

  • {@link ApacheClientProperties#REQUEST_CONFIG}
  • *
  • {@link ApacheClientProperties#CREDENTIALS_PROVIDER}
  • *
  • {@link ApacheClientProperties#DISABLE_COOKIES}
  • - *
  • {@link ClientProperties#PROXY_URI}
  • - *
  • {@link ClientProperties#PROXY_USERNAME}
  • - *
  • {@link ClientProperties#PROXY_PASSWORD}
  • - *
  • {@link ClientProperties#REQUEST_ENTITY_PROCESSING} - default value is {@link RequestEntityProcessing#CHUNKED}
  • + *
  • {@link ApacheClientProperties#KEEPALIVE_STRATEGY}
  • + *
  • {@link org.glassfish.jersey.client.ClientProperties#PROXY_URI}
  • + *
  • {@link org.glassfish.jersey.client.ClientProperties#PROXY_USERNAME}
  • + *
  • {@link org.glassfish.jersey.client.ClientProperties#PROXY_PASSWORD}
  • + *
  • {@link org.glassfish.jersey.client.ClientProperties#REQUEST_ENTITY_PROCESSING} - default value is {@link org.glassfish.jersey.client.RequestEntityProcessing#CHUNKED}
  • *
  • {@link ApacheClientProperties#PREEMPTIVE_BASIC_AUTHENTICATION}
  • *
  • {@link ApacheClientProperties#RETRY_HANDLER}
  • + *
  • {@link ApacheClientProperties#REUSE_STRATEGY}
  • * *

    * This connector uses {@link RequestEntityProcessing#CHUNKED chunked encoding} as a default setting. This can @@ -197,6 +200,34 @@ class ApacheConnector implements Connector { } } + Object keepAliveStrategy = config.getProperties().get(ApacheClientProperties.KEEPALIVE_STRATEGY); + if (keepAliveStrategy != null) { + if (!(keepAliveStrategy instanceof ConnectionKeepAliveStrategy)) { + LOGGER.log( + Level.WARNING, + LocalizationMessages.IGNORING_VALUE_OF_PROPERTY( + ApacheClientProperties.KEEPALIVE_STRATEGY, + keepAliveStrategy.getClass().getName(), + ConnectionKeepAliveStrategy.class.getName()) + ); + keepAliveStrategy = null; + } + } + + Object reuseStrategy = config.getProperties().get(ApacheClientProperties.REUSE_STRATEGY); + if (reuseStrategy != null) { + if (!(reuseStrategy instanceof ConnectionReuseStrategy)) { + LOGGER.log( + Level.WARNING, + LocalizationMessages.IGNORING_VALUE_OF_PROPERTY( + ApacheClientProperties.REUSE_STRATEGY, + reuseStrategy.getClass().getName(), + ConnectionReuseStrategy.class.getName()) + ); + reuseStrategy = null; + } + } + Object reqConfig = config.getProperties().get(ApacheClientProperties.REQUEST_CONFIG); if (reqConfig != null) { if (!(reqConfig instanceof RequestConfig)) { @@ -217,7 +248,13 @@ class ApacheConnector implements Connector { clientBuilder.setConnectionManager(getConnectionManager(client, config, sslContext)); clientBuilder.setConnectionManagerShared( PropertiesHelper.getValue(config.getProperties(), ApacheClientProperties.CONNECTION_MANAGER_SHARED, false, null)); - clientBuilder.setSslcontext(sslContext); + clientBuilder.setSSLContext(sslContext); + if (keepAliveStrategy != null) { + clientBuilder.setKeepAliveStrategy((ConnectionKeepAliveStrategy) keepAliveStrategy); + } + if (reuseStrategy != null) { + clientBuilder.setConnectionReuseStrategy((ConnectionReuseStrategy) reuseStrategy); + } final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom(); diff --git a/connectors/apache-connector/src/main/java/org/glassfish/jersey/apache/connector/ApacheConnectorProvider.java b/connectors/apache-connector/src/main/java/org/glassfish/jersey/apache/connector/ApacheConnectorProvider.java index 1d988b0f61..bf1a432b84 100644 --- a/connectors/apache-connector/src/main/java/org/glassfish/jersey/apache/connector/ApacheConnectorProvider.java +++ b/connectors/apache-connector/src/main/java/org/glassfish/jersey/apache/connector/ApacheConnectorProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -37,6 +37,7 @@ *

  • {@link ApacheClientProperties#REQUEST_CONFIG}
  • *
  • {@link ApacheClientProperties#CREDENTIALS_PROVIDER}
  • *
  • {@link ApacheClientProperties#DISABLE_COOKIES}
  • + *
  • {@link ApacheClientProperties#KEEPALIVE_STRATEGY}
  • *
  • {@link org.glassfish.jersey.client.ClientProperties#PROXY_URI}
  • *
  • {@link org.glassfish.jersey.client.ClientProperties#PROXY_USERNAME}
  • *
  • {@link org.glassfish.jersey.client.ClientProperties#PROXY_PASSWORD}
  • @@ -44,6 +45,7 @@ * - default value is {@link org.glassfish.jersey.client.RequestEntityProcessing#CHUNKED} *
  • {@link ApacheClientProperties#PREEMPTIVE_BASIC_AUTHENTICATION}
  • *
  • {@link ApacheClientProperties#RETRY_HANDLER}
  • + *
  • {@link ApacheClientProperties#REUSE_STRATEGY}
  • * *

    *