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.mortbay.jetty.client
Class HttpClient

    java.lang.Object
      org.mortbay.component.AbstractLifeCycle
          org.mortbay.jetty.AbstractBuffers
              org.mortbay.jetty.client.HttpClient

All Implemented Interfaces:
  LifeCycle, Buffers

    public class HttpClient

extends AbstractBuffers

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.

Author:
  Greg Wilkins, Matthew Purland, Guillaume Nodet
See Also:
  `HttpExchange}`, `HttpDestination}`

Nested Class Summary

Nested classes/interfaces inherited from interface org.mortbay.component.LifeCycle
`LifeCycle.Listener`

Field Summary
`static int` | `CONNECTOR_SELECT_CHANNEL`
`static int` | `CONNECTOR_SOCKET`

Fields inherited from class org.mortbay.jetty.AbstractBuffers
`_loss`

Fields inherited from class org.mortbay.component.AbstractLifeCycle
`_listeners`

Constructor Summary
`HttpClient()`

Method Summary
`void` | `cancel(Timeout.Task task)`
`protected void` | `doStart()`
`protected void` | `doStop()`
`void` | `dump()`
`int` | `getConnectorType()` Get the type of connector (socket, blocking or select) in use.
`HttpDestination` | `getDestination(Address remote, boolean ssl)`
`long` | `getIdleTimeout()`
`String` | `getKeyStoreLocation()`
`protected SSLContext` | `getLooseSSLContext()`
`int` | `getMaxConnectionsPerAddress()`
`Set<String>` | `getNoProxy()`
`Address` | `getProxy()`
`Authorization` | `getProxyAuthentication()`
`RealmResolver` | `getRealmResolver()` returns the SecurityRealmResolver registered with the HttpClient or null
`LinkedList<String>` | `getRegisteredListeners()`
`int` | `getSoTimeout()`
`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.
`protected SSLContext` | `getStrictSSLContext()`
`ThreadPool` | `getThreadPool()`
`long` | `getTimeout()`
`String` | `getTrustStoreLocation()`
`boolean` | `getUseDirectBuffers()` Get whether the connector can use direct NIO buffers.
`boolean` | `hasRealms()`
`boolean` | `isProxied()`
`int` | `maxRetries()`
`protected Buffer` | `newBuffer(int size)` Create a new NIO buffer.
`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` | `schedule(Timeout.Task task)`
`void` | `send(HttpExchange exchange)`
`void` | `setConnectorType(int connectorType)`
`void` | `setIdleTimeout(long ms)`
`void` | `setKeyManagerPassword(String _keyManagerPassword)`
`void` | `setKeyStoreLocation(String keyStoreLocation)`
`void` | `setKeyStorePassword(String _keyStorePassword)`
`void` | `setMaxConnectionsPerAddress(int maxConnectionsPerAddress)`
`void` | `setMaxRetries(int retries)`
`void` | `setNoProxy(Set<String> noProxyAddresses)`
`void` | `setProxy(Address proxy)`
`void` | `setProxyAuthentication(Authorization authentication)`
`void` | `setRealmResolver(RealmResolver resolver)`
`void` | `setSoTimeout(int so)`
`void` | `setThreadPool(ThreadPool threadPool)`
`void` | `setTimeout(long ms)`
`void` | `setTrustStoreLocation(String trustStoreLocation)`
`void` | `setTrustStorePassword(String _trustStorePassword)`
`void` | `setUseDirectBuffers(boolean direct)` Set to use NIO direct buffers.

Methods inherited from class org.mortbay.jetty.AbstractBuffers
`getBuffer, getHeaderBufferSize, getRequestBufferSize, getResponseBufferSize, returnBuffer, setHeaderBufferSize, setRequestBufferSize, setResponseBufferSize`

Methods inherited from class org.mortbay.component.AbstractLifeCycle
`addLifeCycleListener, 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()
              throws IOException

  Throws:
    `IOException`

### send

    public void send(HttpExchange exchange)
              throws IOException

  Throws:
    `IOException`

### getThreadPool

    public ThreadPool getThreadPool()

  Returns:
    the threadPool

### setThreadPool

    public void setThreadPool(ThreadPool threadPool)

  Parameters:
    `threadPool` - the threadPool to set

### getDestination

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

  Throws:
    `UnknownHostException`
    `IOException`

### schedule

    public void schedule(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)

### getRealmResolver

    public RealmResolver getRealmResolver()

  returns the SecurityRealmResolver registered with the HttpClient or null

  Returns:

### 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 preceeding 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)

### newBuffer

    protected Buffer newBuffer(int size)

  Create a new NIO buffer. If using direct buffers, it will create a direct NIO buffer, other than an indirect buffer.

  Specified by:
    `newBuffer` in class `AbstractBuffers`

### getMaxConnectionsPerAddress

    public int getMaxConnectionsPerAddress()

### setMaxConnectionsPerAddress

    public void setMaxConnectionsPerAddress(int maxConnectionsPerAddress)

### doStart

    protected void doStart()
                    throws Exception

  Overrides:
    `doStart` in class `AbstractBuffers`
  Throws:
    `Exception`

### doStop

    protected void doStop()
                   throws Exception

  Overrides:
    `doStop` in class `AbstractLifeCycle`
  Throws:
    `Exception`

### getSSLContext

    protected SSLContext getSSLContext()
                                throws 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:
  Throws:
    `IOException`

### getStrictSSLContext

    protected SSLContext getStrictSSLContext()
                                      throws IOException

  Throws:
    `IOException`

### getLooseSSLContext

    protected SSLContext getLooseSSLContext()
                                     throws IOException

  Throws:
    `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

    public int getSoTimeout()

### setSoTimeout

    public void setSoTimeout(int so)

### 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 ms)

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

### getProxy

    public Address getProxy()

### setProxy

    public void setProxy(Address proxy)

### getProxyAuthentication

    public Authorization getProxyAuthentication()

### setProxyAuthentication

    public void setProxyAuthentication(Authorization 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)

### getTrustStoreLocation

    public String getTrustStoreLocation()

### setTrustStoreLocation

    public void setTrustStoreLocation(String trustStoreLocation)

### getKeyStoreLocation

    public String getKeyStoreLocation()

### setKeyStoreLocation

    public void setKeyStoreLocation(String keyStoreLocation)

### setKeyStorePassword

    public void setKeyStorePassword(String _keyStorePassword)

### setKeyManagerPassword

    public void setKeyManagerPassword(String _keyManagerPassword)

### setTrustStorePassword

    public void setTrustStorePassword(String _trustStorePassword)

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-2008 Mort Bay Consulting. All Rights Reserved.