org.eclipse.jetty.server.handler
类 ConnectHandler

java.lang.Object
  继承者 org.eclipse.jetty.util.component.AbstractLifeCycle
      继承者 org.eclipse.jetty.util.component.AggregateLifeCycle
          继承者 org.eclipse.jetty.server.handler.AbstractHandler
              继承者 org.eclipse.jetty.server.handler.AbstractHandlerContainer
                  继承者 org.eclipse.jetty.server.handler.HandlerWrapper
                      继承者 org.eclipse.jetty.server.handler.ConnectHandler
所有已实现的接口:
Handler, HandlerContainer, Destroyable, Dumpable, LifeCycle
直接已知子类:
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.


嵌套类摘要
 class ConnectHandler.ClientToProxyConnection
           
 class ConnectHandler.ProxyToServerConnection
           
 
从类 org.eclipse.jetty.util.component.AbstractLifeCycle 继承的嵌套类/接口
AbstractLifeCycle.AbstractLifeCycleListener
 
从接口 org.eclipse.jetty.util.component.LifeCycle 继承的嵌套类/接口
LifeCycle.Listener
 
字段摘要
 
从类 org.eclipse.jetty.server.handler.HandlerWrapper 继承的字段
_handler
 
从类 org.eclipse.jetty.util.component.AbstractLifeCycle 继承的字段
_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING
 
构造方法摘要
ConnectHandler()
           
ConnectHandler(Handler handler)
           
ConnectHandler(Handler handler, String[] white, String[] black)
           
ConnectHandler(String[] white, String[] black)
           
 
方法摘要
 void addBlack(String entry)
          Add a blacklist entry to an existing handler configuration
 void addWhite(String entry)
          Add a whitelist entry to an existing handler configuration
protected  SocketChannel connect(HttpServletRequest request, String host, int port)
          Establishes a connection to the remote server.
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.
 void dump(Appendable out, String indent)
           
 int getConnectTimeout()
           
 ThreadPool getThreadPool()
           
 int getWriteTimeout()
           
 void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
          Handle a request.
protected  boolean handleAuthentication(HttpServletRequest request, HttpServletResponse response, String address)
          Handles the authentication before setting up the tunnel to the remote server.
protected  void handleConnect(Request baseRequest, HttpServletRequest request, HttpServletResponse response, String serverAddress)
          Handles a CONNECT request.
protected  ConnectHandler.ClientToProxyConnection newClientToProxyConnection(ConcurrentMap<String,Object> context, SocketChannel channel, EndPoint endPoint, long timeStamp)
           
protected  ConnectHandler.ProxyToServerConnection newProxyToServerConnection(ConcurrentMap<String,Object> context, Buffer buffer)
           
protected  void prepareContext(HttpServletRequest request, ConcurrentMap<String,Object> context)
           
protected  int read(EndPoint endPoint, Buffer buffer, ConcurrentMap<String,Object> context)
          Reads (with non-blocking semantic) into the given buffer from the given endPoint.
protected  void set(String[] entries, HostMap<String> hostMap)
          Helper method to process a list of new entries and replace the content of the specified host map
 void setBlack(String[] entries)
          Re-initialize the blacklist of existing handler object
 void setConnectTimeout(int connectTimeout)
           
 void setServer(Server server)
           
 void setThreadPool(ThreadPool threadPool)
           
 void setWhite(String[] entries)
          Re-initialize the whitelist of existing handler object
 void setWriteTimeout(int writeTimeout)
           
 boolean validateDestination(String host)
          Check the request hostname against white- and blacklist.
protected  int write(EndPoint endPoint, Buffer buffer, ConcurrentMap<String,Object> context)
          Writes (with blocking semantic) the given buffer of data onto the given endPoint.
 
从类 org.eclipse.jetty.server.handler.HandlerWrapper 继承的方法
destroy, expandChildren, getHandler, getHandlers, getNestedHandlerByClass, setHandler
 
从类 org.eclipse.jetty.server.handler.AbstractHandlerContainer 继承的方法
expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass
 
从类 org.eclipse.jetty.server.handler.AbstractHandler 继承的方法
dumpThis, getServer
 
从类 org.eclipse.jetty.util.component.AggregateLifeCycle 继承的方法
addBean, addBean, contains, dump, dump, dump, dump, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, unmanage
 
从类 org.eclipse.jetty.util.component.AbstractLifeCycle 继承的方法
addLifeCycleListener, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
从接口 org.eclipse.jetty.util.component.LifeCycle 继承的方法
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
 

构造方法详细信息

ConnectHandler

public ConnectHandler()

ConnectHandler

public ConnectHandler(String[] white,
                      String[] black)

ConnectHandler

public ConnectHandler(Handler handler)

ConnectHandler

public ConnectHandler(Handler handler,
                      String[] white,
                      String[] black)
方法详细信息

getConnectTimeout

public int getConnectTimeout()
返回:
the timeout, in milliseconds, to connect to the remote server

setConnectTimeout

public void setConnectTimeout(int connectTimeout)
参数:
connectTimeout - the timeout, in milliseconds, to connect to the remote server

getWriteTimeout

public int getWriteTimeout()
返回:
the timeout, in milliseconds, to write data to a peer

setWriteTimeout

public void setWriteTimeout(int writeTimeout)
参数:
writeTimeout - the timeout, in milliseconds, to write data to a peer

setServer

public void setServer(Server server)
指定者:
接口 Handler 中的 setServer
覆盖:
HandlerWrapper 中的 setServer

getThreadPool

public ThreadPool getThreadPool()
返回:
the thread pool

setThreadPool

public void setThreadPool(ThreadPool threadPool)
参数:
threadPool - the thread pool

doStart

protected void doStart()
                throws Exception
从类 AggregateLifeCycle 复制的描述
Start the managed lifecycle beans in the order they were added.

覆盖:
HandlerWrapper 中的 doStart
抛出:
Exception
另请参见:
AbstractLifeCycle.doStart()

doStop

protected void doStop()
               throws Exception
从类 AggregateLifeCycle 复制的描述
Stop the joined lifecycle beans in the reverse order they were added.

覆盖:
HandlerWrapper 中的 doStop
抛出:
Exception
另请参见:
AbstractLifeCycle.doStart()

handle

public void handle(String target,
                   Request baseRequest,
                   HttpServletRequest request,
                   HttpServletResponse response)
            throws ServletException,
                   IOException
从接口 Handler 复制的描述
Handle a request.

指定者:
接口 Handler 中的 handle
覆盖:
HandlerWrapper 中的 handle
参数:
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 AbstractHttpConnection.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 AbstractHttpConnection.getCurrentConnection() method can be used access the Response object if required.
抛出:
ServletException
IOException

handleConnect

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

Handles a CONNECT request.

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

参数:
baseRequest - Jetty-specific http request
request - the http request
response - the http response
serverAddress - the remote server address in the form host:port
抛出:
ServletException - if an application error occurs
IOException - if an I/O error occurs

handleAuthentication

protected boolean handleAuthentication(HttpServletRequest request,
                                       HttpServletResponse response,
                                       String address)
                                throws ServletException,
                                       IOException

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

The default implementation returns true.

参数:
request - the HTTP request
response - the HTTP response
address - the address of the remote server in the form host:port.
返回:
true to allow to connect to the remote host, false otherwise
抛出:
ServletException - to report a server error to the caller
IOException - to report a server error to the caller

newClientToProxyConnection

protected ConnectHandler.ClientToProxyConnection newClientToProxyConnection(ConcurrentMap<String,Object> context,
                                                                            SocketChannel channel,
                                                                            EndPoint endPoint,
                                                                            long timeStamp)

newProxyToServerConnection

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

connect

protected SocketChannel connect(HttpServletRequest request,
                                String host,
                                int port)
                         throws IOException

Establishes a connection to the remote server.

参数:
request - the HTTP request that initiated the tunnel
host - the host to connect to
port - the port to connect to
返回:
a SocketChannel connected to the remote server
抛出:
IOException - if the connection cannot be established

prepareContext

protected void prepareContext(HttpServletRequest request,
                              ConcurrentMap<String,Object> context)

read

protected int read(EndPoint endPoint,
                   Buffer buffer,
                   ConcurrentMap<String,Object> context)
            throws IOException

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

参数:
endPoint - the endPoint to read from
buffer - the buffer to read data into
context - the context information related to the connection
返回:
the number of bytes read (possibly 0 since the read is non-blocking) or -1 if the channel has been closed remotely
抛出:
IOException - if the endPoint cannot be read

write

protected int write(EndPoint endPoint,
                    Buffer buffer,
                    ConcurrentMap<String,Object> context)
             throws IOException

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

参数:
endPoint - the endPoint to write to
buffer - the buffer to write
context - the context information related to the connection
返回:
the number of bytes written
抛出:
IOException - if the buffer cannot be written

addWhite

public void addWhite(String entry)
Add a whitelist entry to an existing handler configuration

参数:
entry - new whitelist entry

addBlack

public void addBlack(String entry)
Add a blacklist entry to an existing handler configuration

参数:
entry - new blacklist entry

setWhite

public void setWhite(String[] entries)
Re-initialize the whitelist of existing handler object

参数:
entries - array of whitelist entries

setBlack

public void setBlack(String[] entries)
Re-initialize the blacklist of existing handler object

参数:
entries - array of blacklist entries

set

protected void set(String[] entries,
                   HostMap<String> hostMap)
Helper method to process a list of new entries and replace the content of the specified host map

参数:
entries - new entries
hostMap - target host map

validateDestination

public boolean validateDestination(String host)
Check the request hostname against white- and blacklist.

参数:
host - hostname to check
返回:
true if hostname is allowed to be proxied

dump

public void dump(Appendable out,
                 String indent)
          throws IOException
指定者:
接口 Dumpable 中的 dump
覆盖:
AbstractHandlerContainer 中的 dump
抛出:
IOException


Copyright © 2013. All Rights Reserved.