HttpClient (Jetty :: Aggregate :: All core Jetty 7.6.8.v20121106 API)
Date: 2012-11-06

org.eclipse.jetty.client

## Class HttpClient

- java.lang.Object
- - org.eclipse.jetty.util.component.AbstractLifeCycle
  - - org.eclipse.jetty.util.component.AggregateLifeCycle
    - - org.eclipse.jetty.client.HttpClient

- All Implemented Interfaces:
    HttpBuffers, Attributes, Destroyable, Dumpable, LifeCycle

      public class HttpClient
      extends AggregateLifeCycle
      implements HttpBuffers, Attributes, Dumpable

  Http Client.

  HttpClient is the main active component of the client API implementation. It is the opposite of the Connectors in standard Jetty, in that it listens for responses rather than requests. Just like the connectors, there is a blocking socket version and a non-blocking NIO version (implemented as nested classes selected by `setConnectorType(int)`).

  The an instance of `HttpExchange` is passed to the `send(HttpExchange)` method to send a request. The exchange contains both the headers and content (source) of the request plus the callbacks to handle responses. A HttpClient can have many exchanges outstanding and they may be queued on the `HttpDestination` waiting for a `AbstractHttpConnection`, queued in the `AbstractHttpConnection` waiting to be transmitted or pipelined on the actual TCP/IP connection waiting for a response.

  The `HttpDestination` class is an aggregation of `AbstractHttpConnection`s for the same host, port and protocol. A destination may limit the number of connections open and they provide a pool of open connections that may be reused. Connections may also be allocated from a destination, so that multiple request sources are not multiplexed over the same connection.
  See Also:
    `HttpExchange`, `HttpDestination`

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

      `AbstractLifeCycle.AbstractLifeCycleListener`

    - ### Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

      `LifeCycle.Listener`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `CONNECTOR_SELECT_CHANNEL`
    `static int` | `CONNECTOR_SOCKET`

    - ### Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

      `_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HttpClient()`
    `HttpClient(SslContextFactory sslContextFactory)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `cancel(Timeout.Task task)`
    `void` | `clearAttributes()`
    `protected void` | `doStart()` Start the managed lifecycle beans in the order they were added.
    `protected void` | `doStop()` Stop the joined lifecycle beans in the reverse order they were added.
    `Object` | `getAttribute(String name)`
    `Enumeration` | `getAttributeNames()`
    `int` | `getConnectorType()` Get the type of connector (socket, blocking or select) in use.
    `int` | `getConnectTimeout()`
    `HttpDestination` | `getDestination(Address remote, boolean ssl)`
    `long` | `getIdleTimeout()`
    `String` | `getKeyManagerAlgorithm()` Deprecated.
    `InputStream` | `getKeyStoreInputStream()` Deprecated.
    `String` | `getKeyStoreLocation()` Deprecated.
    `String` | `getKeyStoreType()` Deprecated.
    `int` | `getMaxBuffers()`
    `int` | `getMaxConnectionsPerAddress()`
    `int` | `getMaxQueueSizePerAddress()`
    `Set<String>` | `getNoProxy()`
    `String` | `getProtocol()` Deprecated.
    `String` | `getProvider()` Deprecated.
    `Address` | `getProxy()`
    `Authentication` | `getProxyAuthentication()`
    `RealmResolver` | `getRealmResolver()` returns the SecurityRealmResolver reg_realmResolveristered with the HttpClient or null
    `LinkedList<String>` | `getRegisteredListeners()`
    `Buffers` | `getRequestBuffers()`
    `int` | `getRequestBufferSize()`
    `Buffers.Type` | `getRequestBufferType()`
    `int` | `getRequestHeaderSize()`
    `Buffers.Type` | `getRequestHeaderType()`
    `Buffers` | `getResponseBuffers()`
    `int` | `getResponseBufferSize()`
    `Buffers.Type` | `getResponseBufferType()`
    `int` | `getResponseHeaderSize()`
    `Buffers.Type` | `getResponseHeaderType()`
    `String` | `getSecureRandomAlgorithm()` Deprecated.
    `int` | `getSoTimeout()` Deprecated. use `getTimeout()` instead.
    `protected SSLContext` | `getSSLContext()` if a keystore location has been provided then client will attempt to use it as the keystore, otherwise we simply ignore certificates and run with a loose ssl context.
    `SslContextFactory` | `getSslContextFactory()`
    `ThreadPool` | `getThreadPool()`
    `long` | `getTimeout()`
    `String` | `getTrustManagerAlgorithm()` Deprecated.
    `InputStream` | `getTrustStoreInputStream()` Deprecated.
    `String` | `getTrustStoreLocation()` Deprecated.
    `String` | `getTrustStoreType()` Deprecated.
    `boolean` | `getUseDirectBuffers()` Get whether the connector can use direct NIO buffers.
    `boolean` | `hasRealms()`
    `boolean` | `isConnectBlocking()`
    `boolean` | `isProxied()`
    `int` | `maxRedirects()`
    `int` | `maxRetries()`
    `void` | `registerListener(String listenerClass)` Registers a listener that can listen to the stream of execution between the client and the server and influence events.
    `void` | `removeAttribute(String name)`
    `void` | `schedule(Timeout.Task task)`
    `void` | `schedule(Timeout.Task task, long timeout)`
    `void` | `scheduleIdle(Timeout.Task task)`
    `void` | `send(HttpExchange exchange)`
    `void` | `setAttribute(String name, Object attribute)` Set an attribute on the HttpClient.
    `void` | `setConnectBlocking(boolean connectBlocking)`
    `void` | `setConnectorType(int connectorType)`
    `void` | `setConnectTimeout(int connectTimeout)`
    `void` | `setIdleTimeout(long ms)`
    `void` | `setKeyManagerAlgorithm(String keyManagerAlgorithm)` Deprecated.
    `void` | `setKeyManagerPassword(String keyManagerPassword)` Deprecated.
    `void` | `setKeyStoreInputStream(InputStream keyStoreInputStream)` Deprecated.
    `void` | `setKeyStoreLocation(String keyStoreLocation)` Deprecated.
    `void` | `setKeyStorePassword(String keyStorePassword)` Deprecated.
    `void` | `setKeyStoreType(String keyStoreType)` Deprecated.
    `void` | `setMaxBuffers(int maxBuffers)`
    `void` | `setMaxConnectionsPerAddress(int maxConnectionsPerAddress)`
    `void` | `setMaxQueueSizePerAddress(int maxQueueSizePerAddress)`
    `void` | `setMaxRedirects(int redirects)`
    `void` | `setMaxRetries(int retries)`
    `void` | `setNoProxy(Set<String> noProxyAddresses)`
    `void` | `setProtocol(String protocol)` Deprecated.
    `void` | `setProvider(String provider)` Deprecated.
    `void` | `setProxy(Address proxy)`
    `void` | `setProxyAuthentication(Authentication authentication)`
    `void` | `setRealmResolver(RealmResolver resolver)` Set a RealmResolver for client Authentication.
    `void` | `setRequestBuffers(Buffers requestBuffers)`
    `void` | `setRequestBufferSize(int requestBufferSize)`
    `void` | `setRequestHeaderSize(int requestHeaderSize)`
    `void` | `setResponseBuffers(Buffers responseBuffers)`
    `void` | `setResponseBufferSize(int responseBufferSize)`
    `void` | `setResponseHeaderSize(int responseHeaderSize)`
    `void` | `setSecureRandomAlgorithm(String secureRandomAlgorithm)` Deprecated.
    `void` | `setSoTimeout(int timeout)` Deprecated. use `setTimeout(long)` instead.
    `void` | `setThreadPool(ThreadPool threadPool)` Set the ThreadPool.
    `void` | `setTimeout(long timeout)`
    `void` | `setTrustManagerAlgorithm(String trustManagerAlgorithm)` Deprecated.
    `void` | `setTrustStoreInputStream(InputStream trustStoreInputStream)` Deprecated.
    `void` | `setTrustStoreLocation(String trustStoreLocation)` Deprecated.
    `void` | `setTrustStorePassword(String trustStorePassword)` Deprecated.
    `void` | `setTrustStoreType(String trustStoreType)` Deprecated.
    `void` | `setUseDirectBuffers(boolean direct)` Set to use NIO direct buffers.

    - ### Methods inherited from class org.eclipse.jetty.util.component.AggregateLifeCycle

      `addBean, addBean, contains, destroy, dump, dump, dump, dump, dump, dumpObject, dumpStdErr, dumpThis, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, unmanage`

    - ### Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

      `addLifeCycleListener, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.eclipse.jetty.util.component.Dumpable

      `dump, dump`

- - ### Field Detail

    - #### CONNECTOR_SOCKET

          public static final int CONNECTOR_SOCKET

      See Also:
        Constant Field Values

    - #### CONNECTOR_SELECT_CHANNEL

          public static final int CONNECTOR_SELECT_CHANNEL

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### HttpClient

          public HttpClient()

    - #### HttpClient

          public HttpClient(SslContextFactory sslContextFactory)

  - ### Method Detail

    - #### isConnectBlocking

          public boolean isConnectBlocking()

      Returns:
        True if connects will be in blocking mode.

    - #### setConnectBlocking

          public void setConnectBlocking(boolean connectBlocking)

      Parameters:
        `connectBlocking` - True if connects will be in blocking mode.

    - #### send

          public void send(HttpExchange exchange)
                    throws IOException

      Throws:
        `IOException`

    - #### getThreadPool

          public ThreadPool getThreadPool()

      Returns:
        the threadpool

    - #### setThreadPool

          public void setThreadPool(ThreadPool threadPool)

      Set the ThreadPool. The threadpool passed is added via `AggregateLifeCycle.addBean(Object)` so that it's lifecycle may be managed as a `AggregateLifeCycle`.
      Parameters:
        `threadPool` - the threadPool to set

    - #### getAttribute

          public Object getAttribute(String name)

      Specified by:
        `getAttribute` in interface `Attributes`
      Parameters:
        `name` -
      Returns:
        Attribute associated with client

    - #### getAttributeNames

          public Enumeration getAttributeNames()

      Specified by:
        `getAttributeNames` in interface `Attributes`
      Returns:
        names of attributes associated with client

    - #### removeAttribute

          public void removeAttribute(String name)

      Specified by:
        `removeAttribute` in interface `Attributes`
      Parameters:
        `name` -

    - #### setAttribute

          public void setAttribute(String name,
                          Object attribute)

      Set an attribute on the HttpClient. Attributes are not used by the client, but are provided for so that users of a shared HttpClient may share other structures.
      Specified by:
        `setAttribute` in interface `Attributes`
      Parameters:
        `name` -
        `attribute` -

    - #### clearAttributes

          public void clearAttributes()

      Specified by:
        `clearAttributes` in interface `Attributes`

    - #### getDestination

          public HttpDestination getDestination(Address remote,
                                       boolean ssl)
                                         throws IOException

      Throws:
        `IOException`

    - #### schedule

          public void schedule(Timeout.Task task)

    - #### schedule

          public void schedule(Timeout.Task task,
                      long timeout)

    - #### scheduleIdle

          public void scheduleIdle(Timeout.Task task)

    - #### cancel

          public void cancel(Timeout.Task task)

    - #### getUseDirectBuffers

          public boolean getUseDirectBuffers()

      Get whether the connector can use direct NIO buffers.

    - #### setRealmResolver

          public void setRealmResolver(RealmResolver resolver)

      Set a RealmResolver for client Authentication. If a realmResolver is set, then the HttpDestinations created by this client will instantiate a `SecurityListener` so that BASIC and DIGEST authentication can be performed.
      Parameters:
        `resolver` -

    - #### getRealmResolver

          public RealmResolver getRealmResolver()

      returns the SecurityRealmResolver reg_realmResolveristered with the HttpClient or null
      Returns:
        the SecurityRealmResolver reg_realmResolveristered with the HttpClient or null

    - #### hasRealms

          public boolean hasRealms()

    - #### registerListener

          public void registerListener(String listenerClass)

      Registers a listener that can listen to the stream of execution between the client and the server and influence events. Sequential calls to the method wrapper sequentially wrap the preceding listener in a delegation model.

      NOTE: the SecurityListener is a special listener which doesn't need to be added via this mechanic, if you register security realms then it will automatically be added as the top listener of the delegation stack.
      Parameters:
        `listenerClass` -

    - #### getRegisteredListeners

          public LinkedList<String> getRegisteredListeners()

    - #### setUseDirectBuffers

          public void setUseDirectBuffers(boolean direct)

      Set to use NIO direct buffers.
      Parameters:
        `direct` - If True (the default), the connector can use NIO direct buffers. Some JVMs have memory management issues (bugs) with direct buffers.

    - #### getConnectorType

          public int getConnectorType()

      Get the type of connector (socket, blocking or select) in use.

    - #### setConnectorType

          public void setConnectorType(int connectorType)

    - #### getMaxConnectionsPerAddress

          public int getMaxConnectionsPerAddress()

    - #### setMaxConnectionsPerAddress

          public void setMaxConnectionsPerAddress(int maxConnectionsPerAddress)

    - #### getMaxQueueSizePerAddress

          public int getMaxQueueSizePerAddress()

    - #### setMaxQueueSizePerAddress

          public void setMaxQueueSizePerAddress(int maxQueueSizePerAddress)

    - #### doStart

          protected void doStart()
                          throws Exception

      Description copied from class: `AggregateLifeCycle`
      Start the managed lifecycle beans in the order they were added.
      Overrides:
        `doStart` in class `AggregateLifeCycle`
      Throws:
        `Exception`
      See Also:
        `AbstractLifeCycle.doStart()`

    - #### doStop

          protected void doStop()
                         throws Exception

      Description copied from class: `AggregateLifeCycle`
      Stop the joined lifecycle beans in the reverse order they were added.
      Overrides:
        `doStop` in class `AggregateLifeCycle`
      Throws:
        `Exception`
      See Also:
        `AbstractLifeCycle.doStart()`

    - #### getSSLContext

          protected SSLContext getSSLContext()

      if a keystore location has been provided then client will attempt to use it as the keystore, otherwise we simply ignore certificates and run with a loose ssl context.
      Returns:
        the SSL context

    - #### getSslContextFactory

          public SslContextFactory getSslContextFactory()

      Returns:
        the instance of SslContextFactory associated with the client

    - #### getIdleTimeout

          public long getIdleTimeout()

      Returns:
        the period in milliseconds a `AbstractHttpConnection` can be idle for before it is closed.

    - #### setIdleTimeout

          public void setIdleTimeout(long ms)

      Parameters:
        `ms` - the period in milliseconds a `AbstractHttpConnection` can be idle for before it is closed.

    - #### getSoTimeout

          @Deprecated
          public int getSoTimeout()

      Deprecated. use `getTimeout()` instead.
      Returns:
        the period in ms that an exchange will wait for a response from the server.

    - #### setSoTimeout

          @Deprecated
          public void setSoTimeout(int timeout)

      Deprecated. use `setTimeout(long)` instead.
      Parameters:
        `timeout` - the period in ms that an exchange will wait for a response from the server.

    - #### getTimeout

          public long getTimeout()

      Returns:
        the period in ms that an exchange will wait for a response from the server.

    - #### setTimeout

          public void setTimeout(long timeout)

      Parameters:
        `timeout` - the period in ms that an exchange will wait for a response from the server.

    - #### getConnectTimeout

          public int getConnectTimeout()

      Returns:
        the period in ms before timing out an attempt to connect

    - #### setConnectTimeout

          public void setConnectTimeout(int connectTimeout)

      Parameters:
        `connectTimeout` - the period in ms before timing out an attempt to connect

    - #### getProxy

          public Address getProxy()

    - #### setProxy

          public void setProxy(Address proxy)

    - #### getProxyAuthentication

          public Authentication getProxyAuthentication()

    - #### setProxyAuthentication

          public void setProxyAuthentication(Authentication authentication)

    - #### isProxied

          public boolean isProxied()

    - #### getNoProxy

          public Set<String> getNoProxy()

    - #### setNoProxy

          public void setNoProxy(Set<String> noProxyAddresses)

    - #### maxRetries

          public int maxRetries()

    - #### setMaxRetries

          public void setMaxRetries(int retries)

    - #### maxRedirects

          public int maxRedirects()

    - #### setMaxRedirects

          public void setMaxRedirects(int redirects)

    - #### getRequestBufferSize

          public int getRequestBufferSize()

      Specified by:
        `getRequestBufferSize` in interface `HttpBuffers`
      Returns:
        the requestBufferSize

    - #### setRequestBufferSize

          public void setRequestBufferSize(int requestBufferSize)

      Specified by:
        `setRequestBufferSize` in interface `HttpBuffers`
      Parameters:
        `requestBufferSize` - the requestBufferSize to set

    - #### getRequestHeaderSize

          public int getRequestHeaderSize()

      Specified by:
        `getRequestHeaderSize` in interface `HttpBuffers`
      Returns:
        the requestHeaderSize

    - #### setRequestHeaderSize

          public void setRequestHeaderSize(int requestHeaderSize)

      Specified by:
        `setRequestHeaderSize` in interface `HttpBuffers`
      Parameters:
        `requestHeaderSize` - the requestHeaderSize to set

    - #### getResponseBufferSize

          public int getResponseBufferSize()

      Specified by:
        `getResponseBufferSize` in interface `HttpBuffers`
      Returns:
        the responseBufferSize

    - #### setResponseBufferSize

          public void setResponseBufferSize(int responseBufferSize)

      Specified by:
        `setResponseBufferSize` in interface `HttpBuffers`
      Parameters:
        `responseBufferSize` - the responseBufferSize to set

    - #### getResponseHeaderSize

          public int getResponseHeaderSize()

      Specified by:
        `getResponseHeaderSize` in interface `HttpBuffers`
      Returns:
        the responseHeaderSize

    - #### setResponseHeaderSize

          public void setResponseHeaderSize(int responseHeaderSize)

      Specified by:
        `setResponseHeaderSize` in interface `HttpBuffers`
      Parameters:
        `responseHeaderSize` - the responseHeaderSize to set

    - #### getRequestBufferType

          public Buffers.Type getRequestBufferType()

      Specified by:
        `getRequestBufferType` in interface `HttpBuffers`
      Returns:
        the requestBufferType

    - #### getRequestHeaderType

          public Buffers.Type getRequestHeaderType()

      Specified by:
        `getRequestHeaderType` in interface `HttpBuffers`
      Returns:
        the requestHeaderType

    - #### getResponseBufferType

          public Buffers.Type getResponseBufferType()

      Specified by:
        `getResponseBufferType` in interface `HttpBuffers`
      Returns:
        the responseBufferType

    - #### getResponseHeaderType

          public Buffers.Type getResponseHeaderType()

      Specified by:
        `getResponseHeaderType` in interface `HttpBuffers`
      Returns:
        the responseHeaderType

    - #### setRequestBuffers

          public void setRequestBuffers(Buffers requestBuffers)

      Specified by:
        `setRequestBuffers` in interface `HttpBuffers`
      Parameters:
        `requestBuffers` - the requestBuffers to set

    - #### setResponseBuffers

          public void setResponseBuffers(Buffers responseBuffers)

      Specified by:
        `setResponseBuffers` in interface `HttpBuffers`
      Parameters:
        `responseBuffers` - the responseBuffers to set

    - #### getRequestBuffers

          public Buffers getRequestBuffers()

      Specified by:
        `getRequestBuffers` in interface `HttpBuffers`

    - #### getResponseBuffers

          public Buffers getResponseBuffers()

      Specified by:
        `getResponseBuffers` in interface `HttpBuffers`

    - #### setMaxBuffers

          public void setMaxBuffers(int maxBuffers)

      Specified by:
        `setMaxBuffers` in interface `HttpBuffers`

    - #### getMaxBuffers

          public int getMaxBuffers()

      Specified by:
        `getMaxBuffers` in interface `HttpBuffers`

    - #### getTrustStoreLocation

          @Deprecated
          public String getTrustStoreLocation()

      Deprecated.

    - #### setTrustStoreLocation

          @Deprecated
          public void setTrustStoreLocation(String trustStoreLocation)

      Deprecated.

    - #### getTrustStoreInputStream

          @Deprecated
          public InputStream getTrustStoreInputStream()

      Deprecated.

    - #### setTrustStoreInputStream

          @Deprecated
          public void setTrustStoreInputStream(InputStream trustStoreInputStream)

      Deprecated.

    - #### getKeyStoreLocation

          @Deprecated
          public String getKeyStoreLocation()

      Deprecated.

    - #### setKeyStoreLocation

          @Deprecated
          public void setKeyStoreLocation(String keyStoreLocation)

      Deprecated.

    - #### getKeyStoreInputStream

          @Deprecated
          public InputStream getKeyStoreInputStream()

      Deprecated.

    - #### setKeyStoreInputStream

          @Deprecated
          public void setKeyStoreInputStream(InputStream keyStoreInputStream)

      Deprecated.

    - #### setKeyStorePassword

          @Deprecated
          public void setKeyStorePassword(String keyStorePassword)

      Deprecated.

    - #### setKeyManagerPassword

          @Deprecated
          public void setKeyManagerPassword(String keyManagerPassword)

      Deprecated.

    - #### setTrustStorePassword

          @Deprecated
          public void setTrustStorePassword(String trustStorePassword)

      Deprecated.

    - #### getKeyStoreType

          @Deprecated
          public String getKeyStoreType()

      Deprecated.

    - #### setKeyStoreType

          @Deprecated
          public void setKeyStoreType(String keyStoreType)

      Deprecated.

    - #### getTrustStoreType

          @Deprecated
          public String getTrustStoreType()

      Deprecated.

    - #### setTrustStoreType

          @Deprecated
          public void setTrustStoreType(String trustStoreType)

      Deprecated.

    - #### getKeyManagerAlgorithm

          @Deprecated
          public String getKeyManagerAlgorithm()

      Deprecated.

    - #### setKeyManagerAlgorithm

          @Deprecated
          public void setKeyManagerAlgorithm(String keyManagerAlgorithm)

      Deprecated.

    - #### getTrustManagerAlgorithm

          @Deprecated
          public String getTrustManagerAlgorithm()

      Deprecated.

    - #### setTrustManagerAlgorithm

          @Deprecated
          public void setTrustManagerAlgorithm(String trustManagerAlgorithm)

      Deprecated.

    - #### getProtocol

          @Deprecated
          public String getProtocol()

      Deprecated.

    - #### setProtocol

          @Deprecated
          public void setProtocol(String protocol)

      Deprecated.

    - #### getProvider

          @Deprecated
          public String getProvider()

      Deprecated.

    - #### setProvider

          @Deprecated
          public void setProvider(String provider)

      Deprecated.

    - #### getSecureRandomAlgorithm

          @Deprecated
          public String getSecureRandomAlgorithm()

      Deprecated.

    - #### setSecureRandomAlgorithm

          @Deprecated
          public void setSecureRandomAlgorithm(String secureRandomAlgorithm)

      Deprecated.

Copyright © 1995-2012 Mort Bay Consulting. All Rights Reserved.