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.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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.eclipse.jetty.client.HttpClient
private final CookieStore
private static final Logger
-
Constructor Summary
ConstructorsConstructorDescriptionJettyConnector
(javax.ws.rs.client.Client jaxrsClient, javax.ws.rs.core.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.private org.eclipse.jetty.client.api.ContentProvider
getBytesProvider
(ClientRequest clientRequest) Get theCookieStore
.org.eclipse.jetty.client.HttpClient
Get theHttpClient
.getName()
Get name of current connector.private static URI
getProxyUri
(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) writeOutBoundHeaders
(javax.ws.rs.core.MultivaluedMap<String, Object> headers, org.eclipse.jetty.client.api.Request request)
-
Field Details
-
LOGGER
-
client
private final org.eclipse.jetty.client.HttpClient client -
cookieStore
-
-
Constructor Details
-
JettyConnector
JettyConnector(javax.ws.rs.client.Client jaxrsClient, javax.ws.rs.core.Configuration config) Create the new Jetty client connector.- Parameters:
jaxrsClient
- JAX-RS client instance, for which the connector is created.config
- client configuration.
-
-
Method Details
-
getProxyUri
-
getHttpClient
public org.eclipse.jetty.client.HttpClient getHttpClient()Get theHttpClient
.- Returns:
- the
HttpClient
.
-
getCookieStore
Get theCookieStore
.- Returns:
- the
CookieStore
instance or null when JettyClientProperties.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:
javax.ws.rs.ProcessingException
- in case of any invocation failure.
-
processResponseHeaders
private static void processResponseHeaders(org.eclipse.jetty.http.HttpFields respHeaders, ClientResponse jerseyResponse) -
translateRequest
-
writeOutBoundHeaders
-
getBytesProvider
-
getStreamProvider
-
processContent
private void processContent(ClientRequest clientRequest, org.eclipse.jetty.client.api.ContentProvider entity) throws IOException - Throws:
IOException
-
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. -
translateResponse
private static ClientResponse translateResponse(ClientRequest jerseyRequest, org.eclipse.jetty.client.api.Response jettyResponse, NonBlockingInputStream entityStream) -
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. -
close
public void close()Description copied from interface:Connector
Close connector and release all it's internally associated resources.
-