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.server.handler
Class ConnectHandler

    java.lang.Object
      org.eclipse.jetty.util.component.AbstractLifeCycle
          org.eclipse.jetty.server.handler.AbstractHandler
              org.eclipse.jetty.server.handler.AbstractHandlerContainer
                  org.eclipse.jetty.server.handler.HandlerWrapper
                      org.eclipse.jetty.server.handler.ConnectHandler

All Implemented Interfaces:
  Handler, HandlerContainer, LifeCycle

Direct Known Subclasses:
  ProxyHandler

    public class ConnectHandler

extends HandlerWrapper

Implementation of a tunneling proxy that supports HTTP CONNECT.

To work as CONNECT proxy, objects of this class must be instantiated using the no-arguments constructor, since the remote server information will be present in the CONNECT URI.

See Also:
  `org.eclipse.jetty.servlets.ProxyServlet`

Nested Class Summary
`class` | `ConnectHandler.ClientToProxyConnection`
`class` | `ConnectHandler.ProxyToServerConnection`

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 inherited from class org.eclipse.jetty.server.handler.HandlerWrapper
`_handler`

Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
`_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING`

Constructor Summary
`ConnectHandler()`
`ConnectHandler(Handler handler)`
`ConnectHandler(Handler handler, java.lang.String[] white, java.lang.String[] black)`
`ConnectHandler(java.lang.String[] white, java.lang.String[] black)`

Method Summary
`void` | `addBlack(java.lang.String entry)` Add a blacklist entry to an existing handler configuration
`void` | `addWhite(java.lang.String entry)` Add a whitelist entry to an existing handler configuration
`protected java.nio.channels.SocketChannel` | `connect(HttpServletRequest request, java.lang.String host, int port)` Establishes a connection to the remote server.
`protected void` | `doStart()`
`protected void` | `doStop()`
`int` | `getConnectTimeout()`
`ThreadPool` | `getThreadPool()`
`int` | `getWriteTimeout()`
`void` | `handle(java.lang.String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)` Handle a request.
`protected boolean` | `handleAuthentication(HttpServletRequest request, HttpServletResponse response, java.lang.String address)` Handles the authentication before setting up the tunnel to the remote server.
`protected void` | `handleConnect(Request baseRequest, HttpServletRequest request, HttpServletResponse response, java.lang.String serverAddress)` Handles a CONNECT request.
`protected ConnectHandler.ClientToProxyConnection` | `newClientToProxyConnection(java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> context, java.nio.channels.SocketChannel channel, EndPoint endPoint, long timeStamp)`
`protected ConnectHandler.ProxyToServerConnection` | `newProxyToServerConnection(java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> context, Buffer buffer)`
`protected void` | `prepareContext(HttpServletRequest request, java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> context)`
`protected int` | `read(EndPoint endPoint, Buffer buffer, java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> context)` Reads (with non-blocking semantic) into the given `buffer` from the given `endPoint`.
`protected void` | `set(java.lang.String[] entries, HostMap<java.lang.String> hostMap)` Helper method to process a list of new entries and replace the content of the specified host map
`void` | `setBlack(java.lang.String[] entries)` Re-initialize the blacklist of existing handler object
`void` | `setConnectTimeout(int connectTimeout)`
`void` | `setServer(Server server)`
`void` | `setThreadPool(ThreadPool threadPool)`
`void` | `setWhite(java.lang.String[] entries)` Re-initialize the whitelist of existing handler object
`void` | `setWriteTimeout(int writeTimeout)`
`boolean` | `validateDestination(java.lang.String host)` Check the request hostname against white- and blacklist.
`protected int` | `write(EndPoint endPoint, Buffer buffer, java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> context)` Writes (with blocking semantic) the given buffer of data onto the given endPoint.

Methods inherited from class org.eclipse.jetty.server.handler.HandlerWrapper
`expandChildren, getHandler, getHandlers, getNestedHandlerByClass, setHandler`

Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandlerContainer
`dump, dumpHandlers, expandHandler, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass`

Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandler
`destroy, dump, dump, getServer, toString`

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, wait, wait, wait`

Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle
`addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

Constructor Detail

### ConnectHandler

    public ConnectHandler()

### ConnectHandler

    public ConnectHandler(java.lang.String[] white,
                          java.lang.String[] black)

### ConnectHandler

    public ConnectHandler(Handler handler)

### ConnectHandler

    public ConnectHandler(Handler handler,
                          java.lang.String[] white,
                          java.lang.String[] black)

Method Detail

### getConnectTimeout

    public int getConnectTimeout()

  Returns:
    the timeout, in milliseconds, to connect to the remote server

### setConnectTimeout

    public void setConnectTimeout(int connectTimeout)

  Parameters:
    `connectTimeout` - the timeout, in milliseconds, to connect to the remote server

### getWriteTimeout

    public int getWriteTimeout()

  Returns:
    the timeout, in milliseconds, to write data to a peer

### setWriteTimeout

    public void setWriteTimeout(int writeTimeout)

  Parameters:
    `writeTimeout` - the timeout, in milliseconds, to write data to a peer

### setServer

    public void setServer(Server server)

  Specified by:
    `setServer` in interface `Handler`
  Overrides:
    `setServer` in class `HandlerWrapper`

### getThreadPool

    public ThreadPool getThreadPool()

  Returns:
    the thread pool

### setThreadPool

    public void setThreadPool(ThreadPool threadPool)

  Parameters:
    `threadPool` - the thread pool

### doStart

    protected void doStart()
                    throws java.lang.Exception

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

### doStop

    protected void doStop()
                   throws java.lang.Exception

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

### handle

    public void handle(java.lang.String target,
                       Request baseRequest,
                       HttpServletRequest request,
                       HttpServletResponse response)
                throws ServletException,
                       java.io.IOException

  Description copied from interface: `Handler`
  Handle a request.

  Specified by:
    `handle` in interface `Handler`
  Overrides:
    `handle` in class `HandlerWrapper`
  Parameters:
    `target` - The target of the request - either a URI or a name.
    `baseRequest` - The original unwrapped request object.
    `request` - The request either as the `Request` object or a wrapper of that request. The `HttpConnection.getCurrentConnection()` method can be used access the Request object if required.
    `response` - The response as the `Response` object or a wrapper of that request. The `HttpConnection.getCurrentConnection()` method can be used access the Response object if required.
  Throws:
    `ServletException`
    `java.io.IOException`

### handleConnect

    protected void handleConnect(Request baseRequest,
                                 HttpServletRequest request,
                                 HttpServletResponse response,
                                 java.lang.String serverAddress)
                          throws ServletException,
                                 java.io.IOException

  Handles a CONNECT request.

  CONNECT requests may have authentication headers such as `Proxy-Authorization` that authenticate the client with the proxy.

  Parameters:
    `baseRequest` - Jetty-specific http request
    `request` - the http request
    `response` - the http response
    `serverAddress` - the remote server address in the form `host:port`
  Throws:
    `ServletException` - if an application error occurs
    `java.io.IOException` - if an I/O error occurs

### handleAuthentication

    protected boolean handleAuthentication(HttpServletRequest request,
                                           HttpServletResponse response,
                                           java.lang.String address)
                                    throws ServletException,
                                           java.io.IOException

  Handles the authentication before setting up the tunnel to the remote server.

  The default implementation returns true.

  Parameters:
    `request` - the HTTP request
    `response` - the HTTP response
    `address` - the address of the remote server in the form `host:port`.
  Returns:
    true to allow to connect to the remote host, false otherwise
  Throws:
    `ServletException` - to report a server error to the caller
    `java.io.IOException` - to report a server error to the caller

### newClientToProxyConnection

    protected ConnectHandler.ClientToProxyConnection newClientToProxyConnection(java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> context,
                                                                                java.nio.channels.SocketChannel channel,
                                                                                EndPoint endPoint,
                                                                                long timeStamp)

### newProxyToServerConnection

    protected ConnectHandler.ProxyToServerConnection newProxyToServerConnection(java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> context,
                                                                                Buffer buffer)

### connect

    protected java.nio.channels.SocketChannel connect(HttpServletRequest request,
                                                      java.lang.String host,
                                                      int port)
                                               throws java.io.IOException

  Establishes a connection to the remote server.

  Parameters:
    `request` - the HTTP request that initiated the tunnel
    `host` - the host to connect to
    `port` - the port to connect to
  Returns:
    a `SocketChannel` connected to the remote server
  Throws:
    `java.io.IOException` - if the connection cannot be established

### prepareContext

    protected void prepareContext(HttpServletRequest request,
                                  java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> context)

### read

    protected int read(EndPoint endPoint,
                       Buffer buffer,
                       java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> context)
                throws java.io.IOException

  Reads (with non-blocking semantic) into the given `buffer` from the given `endPoint`.

  Parameters:
    `endPoint` - the endPoint to read from
    `buffer` - the buffer to read data into
    `context` - the context information related to the connection
  Returns:
    the number of bytes read (possibly 0 since the read is non-blocking) or -1 if the channel has been closed remotely
  Throws:
    `java.io.IOException` - if the endPoint cannot be read

### write

    protected int write(EndPoint endPoint,
                        Buffer buffer,
                        java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> context)
                 throws java.io.IOException

  Writes (with blocking semantic) the given buffer of data onto the given endPoint.

  Parameters:
    `endPoint` - the endPoint to write to
    `buffer` - the buffer to write
    `context` - the context information related to the connection
  Returns:
    the number of bytes written
  Throws:
    `java.io.IOException` - if the buffer cannot be written

### addWhite

    public void addWhite(java.lang.String entry)

  Add a whitelist entry to an existing handler configuration

  Parameters:
    `entry` - new whitelist entry

### addBlack

    public void addBlack(java.lang.String entry)

  Add a blacklist entry to an existing handler configuration

  Parameters:
    `entry` - new blacklist entry

### setWhite

    public void setWhite(java.lang.String[] entries)

  Re-initialize the whitelist of existing handler object

  Parameters:
    `entries` - array of whitelist entries

### setBlack

    public void setBlack(java.lang.String[] entries)

  Re-initialize the blacklist of existing handler object

  Parameters:
    `entries` - array of blacklist entries

### set

    protected void set(java.lang.String[] entries,
                       HostMap<java.lang.String> hostMap)

  Helper method to process a list of new entries and replace the content of the specified host map

  Parameters:
    `entries` - new entries
    `patternMap` - target host map

### validateDestination

    public boolean validateDestination(java.lang.String host)

  Check the request hostname against white- and blacklist.

  Parameters:
    `host` - hostname to check
  Returns:
    true if hostname is allowed to be proxied

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.