Class JettyConnector

java.lang.Object
org.glassfish.jersey.jetty.connector.JettyConnector
All Implemented Interfaces:
Connector, Inflector<ClientRequest,ClientResponse>

class JettyConnector extends Object implements Connector
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:

This transport supports both synchronous and asynchronous processing of client requests. The following methods are supported: GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, CONNECT and MOVE.

Typical usage:

 
 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.

  • Field Details

    • LOGGER

      private static final Logger LOGGER
    • client

      private final org.eclipse.jetty.client.HttpClient client
    • cookieStore

      private final CookieStore 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

      private static URI getProxyUri(Object proxy)
    • getHttpClient

      public org.eclipse.jetty.client.HttpClient getHttpClient()
      Get the HttpClient.
      Returns:
      the HttpClient.
    • getCookieStore

      public CookieStore getCookieStore()
      Get the CookieStore.
      Returns:
      the CookieStore instance or null when JettyClientProperties.DISABLE_COOKIES set to true.
    • apply

      public ClientResponse apply(ClientRequest jerseyRequest) throws javax.ws.rs.ProcessingException
      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 interface Connector
      Specified by:
      apply in interface Inflector<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

      private org.eclipse.jetty.client.api.Request translateRequest(ClientRequest clientRequest)
    • writeOutBoundHeaders

      private static Map<String,String> writeOutBoundHeaders(javax.ws.rs.core.MultivaluedMap<String,Object> headers, org.eclipse.jetty.client.api.Request request)
    • getBytesProvider

      private org.eclipse.jetty.client.api.ContentProvider getBytesProvider(ClientRequest clientRequest)
    • getStreamProvider

      private org.eclipse.jetty.client.api.ContentProvider getStreamProvider(ClientRequest clientRequest)
    • processContent

      private void processContent(ClientRequest clientRequest, org.eclipse.jetty.client.api.ContentProvider entity) throws IOException
      Throws:
      IOException
    • apply

      public Future<?> apply(ClientRequest jerseyRequest, AsyncConnectorCallback callback)
      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.
      Specified by:
      apply in interface Connector
      Parameters:
      jerseyRequest - Jersey client request to be sent.
      callback - Jersey asynchronous connector callback to asynchronously receive the request processing result (either a response or a failure).
      Returns:
      asynchronously executed task handle.
    • translateResponse

      private static ClientResponse translateResponse(ClientRequest jerseyRequest, org.eclipse.jetty.client.api.Response jettyResponse, NonBlockingInputStream entityStream)
    • getName

      public String 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 interface Connector
      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.
      Specified by:
      close in interface Connector