class ApacheConnector extends java.lang.Object implements Connector
Connector
that utilizes the Apache HTTP Client to send and receive
HTTP request and responses.
The following properties are only supported at construction of this class:
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 is RequestEntityProcessing.CHUNKED
ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION
ApacheClientProperties.RETRY_HANDLER
This connector uses chunked encoding
as a default setting. This can
be overridden by the ClientProperties.REQUEST_ENTITY_PROCESSING
. By default the
ClientProperties.CHUNKED_ENCODING_SIZE
property is only supported by using default connection manager. If custom
connection manager needs to be used then chunked encoding size can be set by providing a custom
HttpClientConnection
(via custom ManagedHttpClientConnectionFactory
)
and overriding createOutputStream
method.
Using of authorization 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 to true
.
If a ClientResponse
is obtained and an
entity is not read from the response then
InboundMessageContext.close()
MUST be called
after processing the response to release connection-based resources.
Client operations are thread safe, the HTTP connection may be shared between different threads.
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.
Modifier and Type | Class and Description |
---|---|
private static class |
ApacheConnector.ConnectionFactory |
private static class |
ApacheConnector.HttpClientConnection |
private static class |
ApacheConnector.HttpClientResponseInputStream |
Modifier and Type | Field and Description |
---|---|
private org.apache.http.impl.client.CloseableHttpClient |
client |
private org.apache.http.client.CookieStore |
cookieStore |
private static java.util.logging.Logger |
LOGGER |
private boolean |
preemptiveBasicAuth |
private static java.lang.String |
release |
private org.apache.http.client.config.RequestConfig |
requestConfig |
private static org.apache.http.util.VersionInfo |
vi |
Constructor and Description |
---|
ApacheConnector(javax.ws.rs.client.Client client,
javax.ws.rs.core.Configuration config)
Create the new Apache HTTP Client connector.
|
Modifier and Type | Method and Description |
---|---|
ClientResponse |
apply(ClientRequest clientRequest)
Synchronously process client request into a response.
|
java.util.concurrent.Future<?> |
apply(ClientRequest request,
AsyncConnectorCallback callback)
Asynchronously process client request into a response.
|
void |
close()
Close connector and release all it's internally associated resources.
|
private org.apache.http.conn.HttpClientConnectionManager |
createConnectionManager(javax.ws.rs.client.Client client,
javax.ws.rs.core.Configuration config,
javax.net.ssl.SSLContext sslContext,
boolean useSystemProperties) |
private org.apache.http.conn.HttpClientConnectionManager |
getConnectionManager(javax.ws.rs.client.Client client,
javax.ws.rs.core.Configuration config,
javax.net.ssl.SSLContext sslContext) |
org.apache.http.client.CookieStore |
getCookieStore()
Get the
CookieStore . |
private org.apache.http.HttpHost |
getHost(org.apache.http.client.methods.HttpUriRequest request) |
org.apache.http.client.HttpClient |
getHttpClient()
Get the
HttpClient . |
private org.apache.http.HttpEntity |
getHttpEntity(ClientRequest clientRequest,
boolean bufferingEnabled) |
private static java.io.InputStream |
getInputStream(org.apache.http.client.methods.CloseableHttpResponse response) |
java.lang.String |
getName()
Get name of current connector.
|
private static java.net.URI |
getProxyUri(java.lang.Object proxy) |
private org.apache.http.client.methods.HttpUriRequest |
getUriHttpRequest(ClientRequest clientRequest) |
private static java.lang.String[] |
split(java.lang.String s) |
private static java.util.Map<java.lang.String,java.lang.String> |
writeOutBoundHeaders(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> headers,
org.apache.http.client.methods.HttpUriRequest request) |
private static final java.util.logging.Logger LOGGER
private static final org.apache.http.util.VersionInfo vi
private static final java.lang.String release
private final org.apache.http.impl.client.CloseableHttpClient client
private final org.apache.http.client.CookieStore cookieStore
private final boolean preemptiveBasicAuth
private final org.apache.http.client.config.RequestConfig requestConfig
ApacheConnector(javax.ws.rs.client.Client client, javax.ws.rs.core.Configuration config)
client
- JAX-RS client instance for which the connector is being created.config
- client configuration.private org.apache.http.conn.HttpClientConnectionManager getConnectionManager(javax.ws.rs.client.Client client, javax.ws.rs.core.Configuration config, javax.net.ssl.SSLContext sslContext)
private org.apache.http.conn.HttpClientConnectionManager createConnectionManager(javax.ws.rs.client.Client client, javax.ws.rs.core.Configuration config, javax.net.ssl.SSLContext sslContext, boolean useSystemProperties)
private static java.lang.String[] split(java.lang.String s)
public org.apache.http.client.HttpClient getHttpClient()
HttpClient
.HttpClient
.public org.apache.http.client.CookieStore getCookieStore()
CookieStore
.CookieStore
instance or null
when set to
true
.private static java.net.URI getProxyUri(java.lang.Object proxy)
public ClientResponse apply(ClientRequest clientRequest) throws javax.ws.rs.ProcessingException
Connector
apply
in interface Connector
apply
in interface Inflector<ClientRequest,ClientResponse>
clientRequest
- Jersey client request to be sent.javax.ws.rs.ProcessingException
- in case of any invocation failure.public java.util.concurrent.Future<?> apply(ClientRequest request, AsyncConnectorCallback callback)
Connector
public java.lang.String getName()
Connector
public void close()
Connector
private org.apache.http.HttpHost getHost(org.apache.http.client.methods.HttpUriRequest request)
private org.apache.http.client.methods.HttpUriRequest getUriHttpRequest(ClientRequest clientRequest)
private org.apache.http.HttpEntity getHttpEntity(ClientRequest clientRequest, boolean bufferingEnabled)
private static java.util.Map<java.lang.String,java.lang.String> writeOutBoundHeaders(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> headers, org.apache.http.client.methods.HttpUriRequest request)
private static java.io.InputStream getInputStream(org.apache.http.client.methods.CloseableHttpResponse response) throws java.io.IOException
java.io.IOException