Class JettyHttpTransport

java.lang.Object
org.apache.juneau.rest.client.jetty.JettyHttpTransport
All Implemented Interfaces:
Closeable, AutoCloseable, HttpTransport

public final class JettyHttpTransport extends Object implements HttpTransport
HttpTransport implementation backed by Jetty 12 HttpClient.

This transport is auto-discovered via ServiceLoader when org.eclipse.jetty:jetty-client is on the classpath. You can also instantiate it explicitly:

transport = JettyHttpTransport.builder() .httpClient(new HttpClient()) .build(); client = RestClient.builder() .transport(transport) .build();

The Jetty HttpClient is started automatically when the transport is created and stopped when close() is called. The request body is streamed via OutputStreamRequestContent using a background thread, avoiding full in-memory buffering. The response header timeout defaults to 30 seconds and is configurable via JettyHttpTransportBuilder.responseTimeoutMs(long).

See Also:
Since:
9.2.1
  • Method Details

    • builder

      Returns a new builder for this transport.
      Returns:
      A new builder. Never null.
    • create

      public static JettyHttpTransport create() throws Exception
      Returns a new instance backed by a default HttpClient.
      Returns:
      A new instance. Never null.
      Throws:
      Exception - If the Jetty HttpClient cannot be started.
    • execute

      Description copied from interface: HttpTransport
      Executes the given request and returns the response.

      The caller is responsible for closing the returned TransportResponse after consuming the body.

      Specified by:
      execute in interface HttpTransport
      Parameters:
      request - The fully-resolved request. Must not be null.
      Returns:
      The response. Never null.
      Throws:
      TransportException - If a network-level error occurs.
    • supportsUrlPolicy

      public boolean supportsUrlPolicy()
      Description copied from interface: HttpTransport
      Returns true if this transport can honor the SSRF guardrail's connect-time contract for a policy-covered request (TransportRequest.isSsrfGuardActive()): pin-on-connect to a resolved address that has passed the deny-private policy, and Juneau-controlled redirect revalidation (no fallback to the transport's own auto-follow).

      The default implementation returns false (fail closed): an unknown/caller-supplied transport that has not affirmatively opted in is presumed unable to honor the contract, so RestRequest#run() rejects policy-covered requests against it rather than silently connecting without the guardrail. First-party transports that construct and fully control their own underlying HTTP client override this to return true.

      Specified by:
      supportsUrlPolicy in interface HttpTransport
      Returns:
      true if this transport supports pin-on-connect + redirect revalidation for policy-covered requests.
    • close

      public void close() throws IOException
      Description copied from interface: HttpTransport
      Releases resources held by this transport (connection pools, threads, etc.).

      The default implementation is a no-op.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface HttpTransport
      Throws:
      IOException