Class JettyConnector
- java.lang.Object
-
- org.glassfish.jersey.jetty.connector.JettyConnector
-
- All Implemented Interfaces:
Connector
,Inflector<ClientRequest,ClientResponse>
class JettyConnector extends java.lang.Object implements Connector
AConnector
that utilizes the Jetty HTTP Client to send and receive HTTP request and responses. The following properties are only supported at construction of this class:ClientProperties.ASYNC_THREADPOOL_SIZE
ClientProperties.CONNECT_TIMEOUT
ClientProperties.FOLLOW_REDIRECTS
ClientProperties.PROXY_URI
ClientProperties.PROXY_USERNAME
ClientProperties.PROXY_PASSWORD
ClientProperties.PROXY_PASSWORD
JettyClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION
JettyClientProperties.DISABLE_COOKIES
ClientConfig config = new ClientConfig(); Connector connector = new JettyConnector(config); config.connector(connector); Client client = ClientBuilder.newClient(config); // async request WebTarget target = client.target("http://localhost:8080"); Future<Response> future = target.path("resource").request().async().get(); // wait for 3 seconds Response response = future.get(3, TimeUnit.SECONDS); String entity = response.readEntity(String.class); client.close();
This connector supports only
entity buffering
. Defining the propertyClientProperties.REQUEST_ENTITY_PROCESSING
has no effect on this connector.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
JettyConnector.HttpClientResponseInputStream
-
Field Summary
Fields Modifier and Type Field Description private org.eclipse.jetty.client.HttpClient
client
private java.net.CookieStore
cookieStore
private static java.util.logging.Logger
LOGGER
-
Constructor Summary
Constructors Constructor Description JettyConnector(javax.ws.rs.client.Client jaxrsClient, javax.ws.rs.core.Configuration config)
Create the new Jetty client connector.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ClientResponse
apply(ClientRequest jerseyRequest)
Synchronously process client request into a response.java.util.concurrent.Future<?>
apply(ClientRequest jerseyRequest, AsyncConnectorCallback callback)
Asynchronously process client request into a response.void
close()
Close connector and release all it's internally associated resources.private org.eclipse.jetty.client.api.ContentProvider
getBytesProvider(ClientRequest clientRequest)
java.net.CookieStore
getCookieStore()
Get theCookieStore
.org.eclipse.jetty.client.HttpClient
getHttpClient()
Get theHttpClient
.java.lang.String
getName()
Get name of current connector.private static java.net.URI
getProxyUri(java.lang.Object proxy)
private org.eclipse.jetty.client.api.ContentProvider
getStreamProvider(ClientRequest clientRequest)
private void
processContent(ClientRequest clientRequest, org.eclipse.jetty.client.api.ContentProvider entity)
private static void
processResponseHeaders(org.eclipse.jetty.http.HttpFields respHeaders, ClientResponse jerseyResponse)
private org.eclipse.jetty.client.api.Request
translateRequest(ClientRequest clientRequest)
private static ClientResponse
translateResponse(ClientRequest jerseyRequest, org.eclipse.jetty.client.api.Response jettyResponse, NonBlockingInputStream entityStream)
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.eclipse.jetty.client.api.Request request)
-
-
-
Method Detail
-
getProxyUri
private static java.net.URI getProxyUri(java.lang.Object proxy)
-
getHttpClient
public org.eclipse.jetty.client.HttpClient getHttpClient()
Get theHttpClient
.- Returns:
- the
HttpClient
.
-
getCookieStore
public java.net.CookieStore getCookieStore()
Get theCookieStore
.- Returns:
- the
CookieStore
instance or null when JettyClientProperties.DISABLE_COOKIES set to true.
-
apply
public ClientResponse apply(ClientRequest jerseyRequest) throws javax.ws.rs.ProcessingException
Description copied from interface:Connector
Synchronously 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:
apply
in interfaceConnector
- Specified by:
apply
in interfaceInflector<ClientRequest,ClientResponse>
- Parameters:
jerseyRequest
- 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.
-
processResponseHeaders
private static void processResponseHeaders(org.eclipse.jetty.http.HttpFields respHeaders, ClientResponse jerseyResponse)
-
translateRequest
private org.eclipse.jetty.client.api.Request translateRequest(ClientRequest clientRequest)
-
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.eclipse.jetty.client.api.Request request)
-
getBytesProvider
private org.eclipse.jetty.client.api.ContentProvider getBytesProvider(ClientRequest clientRequest)
-
getStreamProvider
private org.eclipse.jetty.client.api.ContentProvider getStreamProvider(ClientRequest clientRequest)
-
processContent
private void processContent(ClientRequest clientRequest, org.eclipse.jetty.client.api.ContentProvider entity) throws java.io.IOException
- Throws:
java.io.IOException
-
apply
public java.util.concurrent.Future<?> apply(ClientRequest jerseyRequest, AsyncConnectorCallback callback)
Description copied from interface:Connector
Asynchronously process client request into a response. The method is used by Jersey client runtime to asynchronously send a request and receive a response.
-
translateResponse
private static ClientResponse translateResponse(ClientRequest jerseyRequest, org.eclipse.jetty.client.api.Response jettyResponse, NonBlockingInputStream entityStream)
-
getName
public java.lang.String getName()
Description copied from interface:Connector
Get name of current connector. Should contain identification of underlying specification and optionally version number. Will be used in User-Agent header.
-
-