Class GrizzlyConnectorProvider

java.lang.Object
org.glassfish.jersey.grizzly.connector.GrizzlyConnectorProvider
All Implemented Interfaces:
ConnectorProvider

public class GrizzlyConnectorProvider extends Object implements ConnectorProvider
Connector provider for Jersey connectors that utilize Grizzly Asynchronous HTTP Client to send and receive HTTP request and responses.

The following connector configuration properties are supported:

Connector instances created via this connector provider use chunked encoding as a default setting. This can be overridden by the ClientProperties.REQUEST_ENTITY_PROCESSING.

If a ClientResponse is obtained and an entity is not read from the response then InboundMessageContext.close() MUST be called after processing the response to release connection-based resources.

If a response entity is obtained that is an instance of Closeable then the instance MUST be closed after processing the entity to release connection-based resources.

The following methods are currently supported: HEAD, GET, POST, PUT, DELETE, OPTIONS, PATCH and TRACE.

Since:
2.5
Author:
Marek Potociar
  • Constructor Details

    • GrizzlyConnectorProvider

      public GrizzlyConnectorProvider()
      Create new Grizzly Async HTTP Client connector provider.
    • GrizzlyConnectorProvider

      public GrizzlyConnectorProvider(GrizzlyConnectorProvider.AsyncClientCustomizer asyncClientCustomizer)
      Create new Grizzly Async HTTP Client connector provider with a custom client configuration customizer.
      Parameters:
      asyncClientCustomizer - Async HTTP Client configuration customizer.
      Since:
      2.10
  • Method Details

    • getConnector

      public Connector getConnector(Client client, Configuration config)
      Description copied from interface: ConnectorProvider
      Get a Jersey client connector instance for a given client instance and Jersey client runtime configuration.

      Note that the supplied runtime configuration can be different from the client instance configuration as a single client can be used to serve multiple differently configured runtimes. While the SSL context or hostname verifier are shared, other configuration properties may change in each runtime.

      Based on the supplied client and runtime configuration data, it is up to each connector provider implementation to decide whether a new dedicated connector instance is required or if the existing, previously create connector instance can be reused.

      Specified by:
      getConnector in interface ConnectorProvider
      Parameters:
      client - Jersey client instance.
      config - Jersey client runtime configuration.
      Returns:
      configured Connector instance to be used by the client.
    • getHttpClient

      public static com.ning.http.client.AsyncHttpClient getHttpClient(Configurable<?> component)
      Retrieve the underlying Grizzly AsyncHttpClient instance from JerseyClient or JerseyWebTarget configured to use GrizzlyConnectorProvider.
      Parameters:
      component - JerseyClient or JerseyWebTarget instance that is configured to use GrizzlyConnectorProvider.
      Returns:
      underlying Grizzly AsyncHttpClient instance.
      Throws:
      IllegalArgumentException - in case the component is neither JerseyClient nor JerseyWebTarget instance or in case the component is not configured to use a GrizzlyConnectorProvider.
      Since:
      2.8
    • register

      Register a request customizer for a single request. A registered customizer will be used to customize the underlying Async HTTP Client request builder.

      Invoking this method on an instance that is not configured to use Grizzly Async HTTP Client connector does not have any effect.

      Parameters:
      builder - JAX-RS request invocation builder.
      customizer - request customizer to be registered.
      Returns:
      updated Jersey client config with the Grizzly GrizzlyConnectorProvider.RequestCustomizer attached.
    • register

      public static ClientConfig register(ClientConfig config, GrizzlyConnectorProvider.RequestCustomizer customizer)
      Register a request customizer for a all requests executed by a client instance configured with this client config. A registered customizer will be used to customize underlying Async HTTP Client request builders for all requests created using the Jersey client instance configured with this client config.

      Invoking this method on an instance that is not configured to use Grizzly Async HTTP Client connector does not have any effect.

      Parameters:
      config - Jersey client configuration.
      customizer - Async HTTP Client configuration customizer.
      Returns:
      updated JAX-RS client invocation builder with the Grizzly RequestCustomizer attached.