Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.eclipse.jetty.client
Class HttpClient

    java.lang.Object
      org.eclipse.jetty.util.component.AbstractLifeCycle
          org.eclipse.jetty.http.HttpBuffers
              org.eclipse.jetty.client.HttpClient

All Implemented Interfaces:
  Attributes, LifeCycle

    public class HttpClient

extends HttpBuffers
implements Attributes

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 `HttpConnection`, queued in the `HttpConnection` waiting to be transmitted or pipelined on the actual TCP/IP connection waiting for a response.

The `HttpDestination` class is an aggregation of `HttpConnection`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
`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
`HttpClient()`

Method Summary
`void` | `cancel(Timeout.Task task)`
`void` | `clearAttributes()`
`protected void` | `doStart()`
`protected void` | `doStop()`
`void` | `dump()`
`java.lang.Object` | `getAttribute(java.lang.String name)`
`java.util.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()`
`java.lang.String` | `getKeyManagerAlgorithm()`
`java.io.InputStream` | `getKeyStoreInputStream()`
`java.lang.String` | `getKeyStoreLocation()`
`java.lang.String` | `getKeyStoreType()`
`protected javax.net.ssl.SSLContext` | `getLooseSSLContext()`
`int` | `getMaxConnectionsPerAddress()`
`java.util.Set<java.lang.String>` | `getNoProxy()`
`java.lang.String` | `getProtocol()`
`java.lang.String` | `getProvider()`
`Address` | `getProxy()`
`Authentication` | `getProxyAuthentication()`
`RealmResolver` | `getRealmResolver()` returns the SecurityRealmResolver reg_realmResolveristered with the HttpClient or null
`java.util.LinkedList<java.lang.String>` | `getRegisteredListeners()`
`java.lang.String` | `getSecureRandomAlgorithm()`
`int` | `getSoTimeout()` Deprecated. use `getTimeout()` instead.
`protected javax.net.ssl.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.
`protected javax.net.ssl.SSLContext` | `getStrictSSLContext()`
`ThreadPool` | `getThreadPool()`
`long` | `getTimeout()`
`java.lang.String` | `getTrustManagerAlgorithm()`
`java.io.InputStream` | `getTrustStoreInputStream()`
`java.lang.String` | `getTrustStoreLocation()`
`java.lang.String` | `getTrustStoreType()`
`boolean` | `getUseDirectBuffers()` Get whether the connector can use direct NIO buffers.
`boolean` | `hasRealms()`
`boolean` | `isProxied()`
`protected boolean` | `isRequestHeader(Buffer buffer)`
`protected boolean` | `isResponseHeader(Buffer buffer)`
`int` | `maxRedirects()`
`int` | `maxRetries()`
`protected Buffer` | `newRequestBuffer(int size)`
`protected Buffer` | `newRequestHeader(int size)`
`protected Buffer` | `newResponseBuffer(int size)`
`protected Buffer` | `newResponseHeader(int size)`
`void` | `registerListener(java.lang.String listenerClass)` Registers a listener that can listen to the stream of execution between the client and the server and influence events.
`void` | `removeAttribute(java.lang.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(java.lang.String name, java.lang.Object attribute)` Set an attribute on the HttpClient.
`void` | `setConnectorType(int connectorType)`
`void` | `setConnectTimeout(int connectTimeout)`
`void` | `setIdleTimeout(long ms)`
`void` | `setKeyManagerAlgorithm(java.lang.String keyManagerAlgorithm)`
`void` | `setKeyManagerPassword(java.lang.String keyManagerPassword)`
`void` | `setKeyStoreInputStream(java.io.InputStream keyStoreInputStream)`
`void` | `setKeyStoreLocation(java.lang.String keyStoreLocation)`
`void` | `setKeyStorePassword(java.lang.String keyStorePassword)`
`void` | `setKeyStoreType(java.lang.String keyStoreType)`
`void` | `setMaxConnectionsPerAddress(int maxConnectionsPerAddress)`
`void` | `setMaxRedirects(int redirects)`
`void` | `setMaxRetries(int retries)`
`void` | `setNoProxy(java.util.Set<java.lang.String> noProxyAddresses)`
`void` | `setProtocol(java.lang.String protocol)`
`void` | `setProvider(java.lang.String provider)`
`void` | `setProxy(Address proxy)`
`void` | `setProxyAuthentication(Authentication authentication)`
`void` | `setRealmResolver(RealmResolver resolver)` Set a RealmResolver for client Authentication.
`void` | `setSecureRandomAlgorithm(java.lang.String secureRandomAlgorithm)`
`void` | `setSoTimeout(int timeout)` Deprecated. use `setTimeout(long)` instead.
`void` | `setThreadPool(ThreadPool threadPool)`
`void` | `setTimeout(long timeout)`
`void` | `setTrustManagerAlgorithm(java.lang.String trustManagerAlgorithm)`
`void` | `setTrustStoreInputStream(java.io.InputStream trustStoreInputStream)`
`void` | `setTrustStoreLocation(java.lang.String trustStoreLocation)`
`void` | `setTrustStorePassword(java.lang.String trustStorePassword)`
`void` | `setTrustStoreType(java.lang.String trustStoreType)`
`void` | `setUseDirectBuffers(boolean direct)` Set to use NIO direct buffers.

Methods inherited from class org.eclipse.jetty.http.HttpBuffers
`getHeaderBufferSize, getRequestBuffers, getRequestBufferSize, getRequestHeaderSize, getResponseBuffers, getResponseBufferSize, getResponseHeaderSize, setHeaderBufferSize, setRequestBufferSize, setRequestHeaderSize, setResponseBufferSize, setResponseHeaderSize`

Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
`addLifeCycleListener, 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`

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()

Method Detail

### dump

    public void dump()

### send

    public void send(HttpExchange exchange)
              throws java.io.IOException

  Throws:
    `java.io.IOException`

### getThreadPool

    public ThreadPool getThreadPool()

  Returns:
    the threadPool

### setThreadPool

    public void setThreadPool(ThreadPool threadPool)

  Parameters:
    `threadPool` - the threadPool to set

### getAttribute

    public java.lang.Object getAttribute(java.lang.String name)

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

### getAttributeNames

    public java.util.Enumeration getAttributeNames()

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

### removeAttribute

    public void removeAttribute(java.lang.String name)

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

### setAttribute

    public void setAttribute(java.lang.String name,
                             java.lang.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 java.net.UnknownHostException,
                                          java.io.IOException

  Throws:
    `java.net.UnknownHostException`
    `java.io.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(java.lang.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 java.util.LinkedList<java.lang.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)

### newRequestBuffer

    protected Buffer newRequestBuffer(int size)

  Specified by:
    `newRequestBuffer` in class `HttpBuffers`
  See Also:
    `HttpBuffers.newRequestBuffer(int)`

### newRequestHeader

    protected Buffer newRequestHeader(int size)

  Specified by:
    `newRequestHeader` in class `HttpBuffers`
  See Also:
    `HttpBuffers.newRequestHeader(int)`

### newResponseBuffer

    protected Buffer newResponseBuffer(int size)

  Specified by:
    `newResponseBuffer` in class `HttpBuffers`
  See Also:
    `HttpBuffers.newResponseBuffer(int)`

### newResponseHeader

    protected Buffer newResponseHeader(int size)

  Specified by:
    `newResponseHeader` in class `HttpBuffers`
  See Also:
    `HttpBuffers.newResponseHeader(int)`

### isRequestHeader

    protected boolean isRequestHeader(Buffer buffer)

  Specified by:
    `isRequestHeader` in class `HttpBuffers`
  Returns:
    True if the buffer is the correct type for a request header buffer

### isResponseHeader

    protected boolean isResponseHeader(Buffer buffer)

  Specified by:
    `isResponseHeader` in class `HttpBuffers`
  Returns:
    True if the buffer is the correct type for a response header buffer

### getMaxConnectionsPerAddress

    public int getMaxConnectionsPerAddress()

### setMaxConnectionsPerAddress

    public void setMaxConnectionsPerAddress(int maxConnectionsPerAddress)

### doStart

    protected void doStart()
                    throws java.lang.Exception

  Overrides:
    `doStart` in class `HttpBuffers`
  Throws:
    `java.lang.Exception`

### doStop

    protected void doStop()
                   throws java.lang.Exception

  Overrides:
    `doStop` in class `AbstractLifeCycle`
  Throws:
    `java.lang.Exception`

### getSSLContext

    protected javax.net.ssl.SSLContext getSSLContext()
                                              throws java.io.IOException

  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
  Throws:
    `java.io.IOException`

### getStrictSSLContext

    protected javax.net.ssl.SSLContext getStrictSSLContext()
                                                    throws java.io.IOException

  Throws:
    `java.io.IOException`

### getLooseSSLContext

    protected javax.net.ssl.SSLContext getLooseSSLContext()
                                                   throws java.io.IOException

  Throws:
    `java.io.IOException`

### getIdleTimeout

    public long getIdleTimeout()

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

### setIdleTimeout

    public void setIdleTimeout(long ms)

  Parameters:
    `ms` - the period in milliseconds a `HttpConnection` 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 java.util.Set<java.lang.String> getNoProxy()

### setNoProxy

    public void setNoProxy(java.util.Set<java.lang.String> noProxyAddresses)

### maxRetries

    public int maxRetries()

### setMaxRetries

    public void setMaxRetries(int retries)

### maxRedirects

    public int maxRedirects()

### setMaxRedirects

    public void setMaxRedirects(int redirects)

### getTrustStoreLocation

    public java.lang.String getTrustStoreLocation()

### setTrustStoreLocation

    public void setTrustStoreLocation(java.lang.String trustStoreLocation)

### getTrustStoreInputStream

    public java.io.InputStream getTrustStoreInputStream()

### setTrustStoreInputStream

    public void setTrustStoreInputStream(java.io.InputStream trustStoreInputStream)

### getKeyStoreLocation

    public java.lang.String getKeyStoreLocation()

### setKeyStoreLocation

    public void setKeyStoreLocation(java.lang.String keyStoreLocation)

### getKeyStoreInputStream

    public java.io.InputStream getKeyStoreInputStream()

### setKeyStoreInputStream

    public void setKeyStoreInputStream(java.io.InputStream keyStoreInputStream)

### setKeyStorePassword

    public void setKeyStorePassword(java.lang.String keyStorePassword)

### setKeyManagerPassword

    public void setKeyManagerPassword(java.lang.String keyManagerPassword)

### setTrustStorePassword

    public void setTrustStorePassword(java.lang.String trustStorePassword)

### getKeyStoreType

    public java.lang.String getKeyStoreType()

### setKeyStoreType

    public void setKeyStoreType(java.lang.String keyStoreType)

### getTrustStoreType

    public java.lang.String getTrustStoreType()

### setTrustStoreType

    public void setTrustStoreType(java.lang.String trustStoreType)

### getKeyManagerAlgorithm

    public java.lang.String getKeyManagerAlgorithm()

### setKeyManagerAlgorithm

    public void setKeyManagerAlgorithm(java.lang.String keyManagerAlgorithm)

### getTrustManagerAlgorithm

    public java.lang.String getTrustManagerAlgorithm()

### setTrustManagerAlgorithm

    public void setTrustManagerAlgorithm(java.lang.String trustManagerAlgorithm)

### getProtocol

    public java.lang.String getProtocol()

### setProtocol

    public void setProtocol(java.lang.String protocol)

### getProvider

    public java.lang.String getProvider()

### setProvider

    public void setProvider(java.lang.String provider)

### getSecureRandomAlgorithm

    public java.lang.String getSecureRandomAlgorithm()

### setSecureRandomAlgorithm

    public void setSecureRandomAlgorithm(java.lang.String secureRandomAlgorithm)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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