public class JettyConnector extends 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.DISABLE_COOKIES
JettyClientProperties.ENABLE_SSL_HOSTNAME_VERIFICATION
JettyClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION
JettyClientProperties.SYNC_LISTENER_RESPONSE_MAX_SIZE
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 | Constructor and Description |
---|---|
protected |
JettyConnector(Client jaxrsClient,
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.
|
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.
|
CookieStore |
getCookieStore()
Get the
CookieStore . |
org.eclipse.jetty.client.HttpClient |
getHttpClient()
Get the
HttpClient . |
String |
getName()
Get name of current connector.
|
protected org.eclipse.jetty.client.HttpClient |
getRegisteredHttpClient(Configuration config)
provides custom registered
HttpClient if any (or NULL) |
protected org.eclipse.jetty.client.HttpClientTransport |
initClientTransport(ClientConnector clientConnector)
provides required HTTP client transport for client
the default transport is
HttpClientTransportOverHTTP |
protected JettyConnector(Client jaxrsClient, Configuration config)
jaxrsClient
- JAX-RS client instance, for which the connector is created.config
- client configuration.protected org.eclipse.jetty.client.HttpClientTransport initClientTransport(ClientConnector clientConnector)
HttpClientTransportOverHTTP
HttpClientTransport
protected org.eclipse.jetty.client.HttpClient getRegisteredHttpClient(Configuration config)
HttpClient
if any (or NULL)config
- configuration where HttpClient
could be registeredHttpClient
instance if any was previously registered or NULLpublic org.eclipse.jetty.client.HttpClient getHttpClient()
HttpClient
.HttpClient
.public CookieStore getCookieStore()
CookieStore
.CookieStore
instance or null when
JettyClientProperties.DISABLE_COOKIES set to true.public ClientResponse apply(ClientRequest jerseyRequest) throws ProcessingException
Connector
apply
in interface Connector
apply
in interface Inflector<ClientRequest,ClientResponse>
jerseyRequest
- Jersey client request to be sent.ProcessingException
- in case of any invocation failure.public Future<?> apply(ClientRequest jerseyRequest, AsyncConnectorCallback callback)
Connector
public String getName()
Connector
getName
in interface Connector
null
or empty string means not including
this information in a generated "User-Agent" header.Copyright © 2007-2024, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.