Class JettyConnector

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

public 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 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 Details

    • JettyConnector

      public JettyConnector(Client jaxrsClient, 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

    • initClientTransport

      protected org.eclipse.jetty.client.HttpClientTransport initClientTransport(org.eclipse.jetty.io.ClientConnector clientConnector)
      provides required HTTP client transport for client the default transport is HttpClientTransportOverHTTP
      Returns:
      instance of HttpClientTransport
      Since:
      2.41
    • getRegisteredHttpClient

      protected org.eclipse.jetty.client.HttpClient getRegisteredHttpClient(Configuration config)
      provides custom registered HttpClient if any (or NULL)
      Parameters:
      config - configuration where HttpClient 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 the HttpClient.
      Returns:
      the HttpClient.
    • getCookieStore

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

      public ClientResponse apply(ClientRequest jerseyRequest) throws 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:
      ProcessingException - in case of any invocation failure.
    • 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.
    • 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