class JettyConnector extends java.lang.Object implements Connector
Connector
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 property ClientProperties.REQUEST_ENTITY_PROCESSING
has no effect on this connector.
Modifier and Type | Class and Description |
---|---|
private static class |
JettyConnector.HttpClientResponseInputStream |
Modifier and Type | Field and Description |
---|---|
private org.eclipse.jetty.client.HttpClient |
client |
private java.net.CookieStore |
cookieStore |
private static java.util.logging.Logger |
LOGGER |
Constructor and Description |
---|
JettyConnector(javax.ws.rs.client.Client jaxrsClient,
javax.ws.rs.core.Configuration config)
Create the new Jetty client connector.
|
Modifier and Type | Method and 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 the
CookieStore . |
org.eclipse.jetty.client.HttpClient |
getHttpClient()
Get the
HttpClient . |
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) |
private static final java.util.logging.Logger LOGGER
private final org.eclipse.jetty.client.HttpClient client
private final java.net.CookieStore cookieStore
JettyConnector(javax.ws.rs.client.Client jaxrsClient, javax.ws.rs.core.Configuration config)
jaxrsClient
- JAX-RS client instance, for which the connector is created.config
- client configuration.private static java.net.URI getProxyUri(java.lang.Object proxy)
public org.eclipse.jetty.client.HttpClient getHttpClient()
HttpClient
.HttpClient
.public java.net.CookieStore getCookieStore()
CookieStore
.CookieStore
instance or null when
JettyClientProperties.DISABLE_COOKIES set to true.public ClientResponse apply(ClientRequest jerseyRequest) throws javax.ws.rs.ProcessingException
Connector
apply
in interface Connector
apply
in interface Inflector<ClientRequest,ClientResponse>
jerseyRequest
- Jersey client request to be sent.javax.ws.rs.ProcessingException
- in case of any invocation failure.private static void processResponseHeaders(org.eclipse.jetty.http.HttpFields respHeaders, ClientResponse jerseyResponse)
private org.eclipse.jetty.client.api.Request translateRequest(ClientRequest clientRequest)
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)
private org.eclipse.jetty.client.api.ContentProvider getBytesProvider(ClientRequest clientRequest)
private org.eclipse.jetty.client.api.ContentProvider getStreamProvider(ClientRequest clientRequest)
private void processContent(ClientRequest clientRequest, org.eclipse.jetty.client.api.ContentProvider entity) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<?> apply(ClientRequest jerseyRequest, AsyncConnectorCallback callback)
Connector
private static ClientResponse translateResponse(ClientRequest jerseyRequest, org.eclipse.jetty.client.api.Response jettyResponse, NonBlockingInputStream entityStream)
public java.lang.String getName()
Connector