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_SIZEClientProperties.CONNECT_TIMEOUTClientProperties.FOLLOW_REDIRECTSClientProperties.PROXY_URIClientProperties.PROXY_USERNAMEClientProperties.PROXY_PASSWORDClientProperties.PROXY_PASSWORDJettyClientProperties.PREEMPTIVE_BASIC_AUTHENTICATIONJettyClientProperties.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.HttpClientprivate final CookieStoreprivate 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.voidclose()Close connector and release all it's internally associated resources.private org.eclipse.jetty.client.api.ContentProvidergetBytesProvider(ClientRequest clientRequest) Get theCookieStore.org.eclipse.jetty.client.HttpClientGet theHttpClient.getName()Get name of current connector.private static URIgetProxyUri(Object proxy) private org.eclipse.jetty.client.api.ContentProvidergetStreamProvider(ClientRequest clientRequest) private voidprocessContent(ClientRequest clientRequest, org.eclipse.jetty.client.api.ContentProvider entity) private static voidprocessResponseHeaders(org.eclipse.jetty.http.HttpFields respHeaders, ClientResponse jerseyResponse) private org.eclipse.jetty.client.api.RequesttranslateRequest(ClientRequest clientRequest) private static ClientResponsetranslateResponse(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
CookieStoreinstance or null when JettyClientProperties.DISABLE_COOKIES set to true.
-
apply
Description copied from interface:ConnectorSynchronously 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:
applyin interfaceConnector- Specified by:
applyin 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:ConnectorAsynchronously 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:ConnectorGet 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:ConnectorClose connector and release all it's internally associated resources.
-