Class JettyConnector
java.lang.Object
org.glassfish.jersey.jetty.connector.JettyConnector
- All Implemented Interfaces:
Connector
,Inflector<ClientRequest,
ClientResponse>
A
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.DISABLE_COOKIES
*
JettyClientProperties.ENABLE_SSL_HOSTNAME_VERIFICATION
JettyClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION
JettyClientProperties.SYNC_LISTENER_RESPONSE_MAX_SIZE
ClientConfig config = new ClientConfig();
Connector connector = new Jetty11Connector(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.
- Author:
- Arul Dhesiaseelan (aruld at acm.org), Marek Potociar
-
Constructor Summary
ConstructorDescriptionJettyConnector
(Client jaxrsClient, Configuration config) Create the new Jetty client connector. -
Method Summary
Modifier and TypeMethodDescriptionapply
(ClientRequest jerseyRequest) Synchronously process client request into a response.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.Get theCookieStore
.org.eclipse.jetty.client.HttpClient
Get theHttpClient
.getName()
Get name of current connector.protected org.eclipse.jetty.client.HttpClient
getRegisteredHttpClient
(Configuration config) provides custom registeredHttpClient
if any (or NULL)protected org.eclipse.jetty.client.HttpClientTransport
initClientTransport
(org.eclipse.jetty.io.ClientConnector clientConnector) provides required HTTP client transport for client the default transport isHttpClientTransportOverHTTP
-
Constructor Details
-
JettyConnector
Create the new Jetty client connector.- Parameters:
jaxrsClient
- JAX-RS client instance, for which the connector is created.config
- client configuration.
-
-
Method Details
-
initClientTransport
protected org.eclipse.jetty.client.HttpClientTransport initClientTransport(org.eclipse.jetty.io.ClientConnector clientConnector) provides required HTTP client transport for client the default transport isHttpClientTransportOverHTTP
- Returns:
- instance of
HttpClientTransport
- Since:
- 2.41
-
getRegisteredHttpClient
provides custom registeredHttpClient
if any (or NULL)- Parameters:
config
- configuration whereHttpClient
could be registered- Returns:
HttpClient
instance if any was previously registered or NULL- Since:
- 2.41
-
getHttpClient
public org.eclipse.jetty.client.HttpClient getHttpClient()Get theHttpClient
.- Returns:
- the
HttpClient
.
-
getCookieStore
Get theCookieStore
.- Returns:
- the
CookieStore
instance or null when Jetty11ClientProperties.DISABLE_COOKIES set to true.
-
apply
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:
ProcessingException
- in case of any invocation failure.
-
apply
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. -
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.- Specified by:
getName
in interfaceConnector
- Returns:
- name of current connector. Returning
null
or empty string means not including this information in a generated "User-Agent" header.
-
close
public void close()Description copied from interface:Connector
Close connector and release all it's internally associated resources.
-