Class ApacheConnectorProvider
- java.lang.Object
-
- org.glassfish.jersey.apache.connector.ApacheConnectorProvider
-
- All Implemented Interfaces:
ConnectorProvider
public class ApacheConnectorProvider extends java.lang.Object implements ConnectorProvider
Connector provider for Jerseyconnectors
that utilize Apache HTTP Client to send and receive HTTP request and responses.The following connector configuration properties are supported:
ApacheClientProperties.CONNECTION_MANAGER
ApacheClientProperties.REQUEST_CONFIG
ApacheClientProperties.CREDENTIALS_PROVIDER
ApacheClientProperties.DISABLE_COOKIES
ClientProperties.PROXY_URI
ClientProperties.PROXY_USERNAME
ClientProperties.PROXY_PASSWORD
ClientProperties.REQUEST_ENTITY_PROCESSING
- default value isRequestEntityProcessing.CHUNKED
ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION
ApacheClientProperties.RETRY_HANDLER
Connector instances created via this connector provider use
chunked encoding
as a default setting. This can be overridden by theClientProperties.REQUEST_ENTITY_PROCESSING
. By default theClientProperties.CHUNKED_ENCODING_SIZE
property is only supported when using the defaultorg.apache.http.conn.HttpClientConnectionManager
instance. If custom connection manager is used, then chunked encoding size can be set by providing a customorg.apache.http.HttpClientConnection
(via customorg.apache.http.impl.conn.ManagedHttpClientConnectionFactory
) and overriding it'screateOutputStream
method.Use of authorization by the AHC-based connectors is dependent on the chunk encoding setting. If the entity buffering is enabled, the entity is buffered and authorization can be performed automatically in response to a 401 by sending the request again. When entity buffering is disabled (chunked encoding is used) then the property
ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION
must be set totrue
.If a
ClientResponse
is obtained and an entity is not read from the response thenInboundMessageContext.close()
MUST be called after processing the response to release connection-based resources.If a response entity is obtained that is an instance of
Closeable
then the instance MUST be closed after processing the entity to release connection-based resources.The following methods are currently supported: HEAD, GET, POST, PUT, DELETE, OPTIONS, PATCH and TRACE.
- Since:
- 2.5
-
-
Constructor Summary
Constructors Constructor Description ApacheConnectorProvider()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Connector
getConnector(javax.ws.rs.client.Client client, javax.ws.rs.core.Configuration runtimeConfig)
Get a Jersey client connector instance for a givenclient
instance and Jersey client runtimeconfiguration
.private static ApacheConnector
getConnector(javax.ws.rs.core.Configurable<?> component)
static org.apache.http.client.CookieStore
getCookieStore(javax.ws.rs.core.Configurable<?> component)
Retrieve the underlying ApacheCookieStore
instance fromJerseyClient
orJerseyWebTarget
configured to useApacheConnectorProvider
.static org.apache.http.client.HttpClient
getHttpClient(javax.ws.rs.core.Configurable<?> component)
Retrieve the underlying ApacheHttpClient
instance fromJerseyClient
orJerseyWebTarget
configured to useApacheConnectorProvider
.
-
-
-
Method Detail
-
getConnector
public Connector getConnector(javax.ws.rs.client.Client client, javax.ws.rs.core.Configuration runtimeConfig)
Description copied from interface:ConnectorProvider
Get a Jersey client connector instance for a givenclient
instance and Jersey client runtimeconfiguration
.Note that the supplied runtime configuration can be different from the client instance configuration as a single client can be used to serve multiple differently configured runtimes. While the
SSL context
orhostname verifier
are shared, other configuration properties may change in each runtime.Based on the supplied client and runtime configuration data, it is up to each connector provider implementation to decide whether a new dedicated connector instance is required or if the existing, previously create connector instance can be reused.
- Specified by:
getConnector
in interfaceConnectorProvider
- Parameters:
client
- Jersey client instance.runtimeConfig
- Jersey client runtime configuration.- Returns:
- configured
Connector
instance to be used by the client.
-
getHttpClient
public static org.apache.http.client.HttpClient getHttpClient(javax.ws.rs.core.Configurable<?> component)
Retrieve the underlying ApacheHttpClient
instance fromJerseyClient
orJerseyWebTarget
configured to useApacheConnectorProvider
.- Parameters:
component
-JerseyClient
orJerseyWebTarget
instance that is configured to useApacheConnectorProvider
.- Returns:
- underlying Apache
HttpClient
instance. - Throws:
java.lang.IllegalArgumentException
- in case thecomponent
is neitherJerseyClient
norJerseyWebTarget
instance or in case the component is not configured to use aApacheConnectorProvider
.- Since:
- 2.8
-
getCookieStore
public static org.apache.http.client.CookieStore getCookieStore(javax.ws.rs.core.Configurable<?> component)
Retrieve the underlying ApacheCookieStore
instance fromJerseyClient
orJerseyWebTarget
configured to useApacheConnectorProvider
.- Parameters:
component
-JerseyClient
orJerseyWebTarget
instance that is configured to useApacheConnectorProvider
.- Returns:
- underlying Apache
CookieStore
instance. - Throws:
java.lang.IllegalArgumentException
- in case thecomponent
is neitherJerseyClient
norJerseyWebTarget
instance or in case the component is not configured to use aApacheConnectorProvider
.- Since:
- 2.16
-
getConnector
private static ApacheConnector getConnector(javax.ws.rs.core.Configurable<?> component)
-
-