Class ApacheConnector
- java.lang.Object
-
- org.glassfish.jersey.apache.connector.ApacheConnector
-
- All Implemented Interfaces:
Connector,Inflector<ClientRequest,ClientResponse>
class ApacheConnector extends java.lang.Object implements Connector
AConnectorthat 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_MANAGERApacheClientProperties.REQUEST_CONFIGApacheClientProperties.CREDENTIALS_PROVIDERApacheClientProperties.DISABLE_COOKIESClientProperties.PROXY_URIClientProperties.PROXY_USERNAMEClientProperties.PROXY_PASSWORDClientProperties.REQUEST_ENTITY_PROCESSING- default value isRequestEntityProcessing.CHUNKEDApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATIONApacheClientProperties.RETRY_HANDLER
This connector uses
chunked encodingas a default setting. This can be overridden by theClientProperties.REQUEST_ENTITY_PROCESSING. By default theClientProperties.CHUNKED_ENCODING_SIZEproperty 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 customHttpClientConnection(via customManagedHttpClientConnectionFactory) and overridingcreateOutputStreammethod.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_AUTHENTICATIONmust be set totrue.If a
ClientResponseis obtained and an entity is not read from the response thenInboundMessageContext.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
Closeablethen 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classApacheConnector.ConnectionFactoryprivate static classApacheConnector.HttpClientConnectionprivate static classApacheConnector.HttpClientResponseInputStream
-
Field Summary
Fields Modifier and Type Field Description private org.apache.http.impl.client.CloseableHttpClientclientprivate org.apache.http.client.CookieStorecookieStoreprivate static java.util.logging.LoggerLOGGERprivate booleanpreemptiveBasicAuthprivate static java.lang.Stringreleaseprivate org.apache.http.client.config.RequestConfigrequestConfigprivate static org.apache.http.util.VersionInfovi
-
Constructor Summary
Constructors Constructor Description ApacheConnector(javax.ws.rs.client.Client client, javax.ws.rs.core.Configuration config)Create the new Apache HTTP Client connector.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ClientResponseapply(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.voidclose()Close connector and release all it's internally associated resources.private org.apache.http.conn.HttpClientConnectionManagercreateConnectionManager(javax.ws.rs.client.Client client, javax.ws.rs.core.Configuration config, javax.net.ssl.SSLContext sslContext, boolean useSystemProperties)private org.apache.http.conn.HttpClientConnectionManagergetConnectionManager(javax.ws.rs.client.Client client, javax.ws.rs.core.Configuration config, javax.net.ssl.SSLContext sslContext)org.apache.http.client.CookieStoregetCookieStore()Get theCookieStore.private org.apache.http.HttpHostgetHost(org.apache.http.client.methods.HttpUriRequest request)org.apache.http.client.HttpClientgetHttpClient()Get theHttpClient.private org.apache.http.HttpEntitygetHttpEntity(ClientRequest clientRequest, boolean bufferingEnabled)private static java.io.InputStreamgetInputStream(org.apache.http.client.methods.CloseableHttpResponse response)java.lang.StringgetName()Get name of current connector.private static java.net.URIgetProxyUri(java.lang.Object proxy)private org.apache.http.client.methods.HttpUriRequestgetUriHttpRequest(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)
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
vi
private static final org.apache.http.util.VersionInfo vi
-
release
private static final java.lang.String release
-
client
private final org.apache.http.impl.client.CloseableHttpClient client
-
cookieStore
private final org.apache.http.client.CookieStore cookieStore
-
preemptiveBasicAuth
private final boolean preemptiveBasicAuth
-
requestConfig
private final org.apache.http.client.config.RequestConfig requestConfig
-
-
Method Detail
-
getConnectionManager
private org.apache.http.conn.HttpClientConnectionManager getConnectionManager(javax.ws.rs.client.Client client, javax.ws.rs.core.Configuration config, javax.net.ssl.SSLContext sslContext)
-
createConnectionManager
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)
-
split
private static java.lang.String[] split(java.lang.String s)
-
getHttpClient
public org.apache.http.client.HttpClient getHttpClient()
Get theHttpClient.- Returns:
- the
HttpClient.
-
getCookieStore
public org.apache.http.client.CookieStore getCookieStore()
Get theCookieStore.- Returns:
- the
CookieStoreinstance ornullwhen "jersey.config.apache.client.handleCookies" set totrue.
-
getProxyUri
private static java.net.URI getProxyUri(java.lang.Object proxy)
-
apply
public ClientResponse apply(ClientRequest clientRequest) throws javax.ws.rs.ProcessingException
Description copied from interface:ConnectorSynchronously process client request into a response. The method is used by Jersey client runtime to synchronously send a request and receive a response.- Specified by:
applyin interfaceConnector- Specified by:
applyin interfaceInflector<ClientRequest,ClientResponse>- Parameters:
clientRequest- Jersey client request to be sent.- Returns:
- Jersey client response received for the client request.
- Throws:
javax.ws.rs.ProcessingException- in case of any invocation failure.
-
apply
public java.util.concurrent.Future<?> apply(ClientRequest request, AsyncConnectorCallback callback)
Description copied from interface:ConnectorAsynchronously process client request into a response. The method is used by Jersey client runtime to asynchronously send a request and receive a response.
-
getName
public java.lang.String getName()
Description copied from interface:ConnectorGet name of current connector. Should contain identification of underlying specification and optionally version number. Will be used in User-Agent header.
-
close
public void close()
Description copied from interface:ConnectorClose connector and release all it's internally associated resources.
-
getHost
private org.apache.http.HttpHost getHost(org.apache.http.client.methods.HttpUriRequest request)
-
getUriHttpRequest
private org.apache.http.client.methods.HttpUriRequest getUriHttpRequest(ClientRequest clientRequest)
-
getHttpEntity
private org.apache.http.HttpEntity getHttpEntity(ClientRequest clientRequest, boolean bufferingEnabled)
-
writeOutBoundHeaders
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)
-
getInputStream
private static java.io.InputStream getInputStream(org.apache.http.client.methods.CloseableHttpResponse response) throws java.io.IOException- Throws:
java.io.IOException
-
-