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.
| Modifier and Type | Class and Description |
|---|---|
class |
ConnectHandler.ClientToProxyConnection |
class |
ConnectHandler.ProxyToServerConnection |
AbstractLifeCycle.AbstractLifeCycleListenerLifeCycle.Listener_handler_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING| Constructor and Description |
|---|
ConnectHandler() |
ConnectHandler(Handler handler) |
ConnectHandler(Handler handler,
java.lang.String[] white,
java.lang.String[] black) |
ConnectHandler(java.lang.String[] white,
java.lang.String[] black) |
| Modifier and Type | Method and Description |
|---|---|
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(javax.servlet.http.HttpServletRequest request,
java.lang.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(java.lang.Appendable out,
java.lang.String indent) |
int |
getConnectTimeout() |
ThreadPool |
getThreadPool() |
int |
getWriteTimeout() |
void |
handle(java.lang.String target,
Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Handle a request.
|
protected boolean |
handleAuthentication(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String address)
Handles the authentication before setting up the tunnel to the remote server.
|
protected void |
handleConnect(Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.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(javax.servlet.http.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.
|
destroy, expandChildren, getHandler, getHandlers, getNestedHandlerByClass, setHandlerexpandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClassdumpThis, getServeraddBean, addBean, contains, dump, dump, dump, dump, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, unmanageaddLifeCycleListener, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stopclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stoppublic ConnectHandler()
public ConnectHandler(java.lang.String[] white,
java.lang.String[] black)
public ConnectHandler(Handler handler)
public ConnectHandler(Handler handler, java.lang.String[] white, java.lang.String[] black)
public int getConnectTimeout()
public void setConnectTimeout(int connectTimeout)
connectTimeout - the timeout, in milliseconds, to connect to the remote serverpublic int getWriteTimeout()
public void setWriteTimeout(int writeTimeout)
writeTimeout - the timeout, in milliseconds, to write data to a peerpublic void setServer(Server server)
setServer in interface HandlersetServer in class HandlerWrapperpublic ThreadPool getThreadPool()
public void setThreadPool(ThreadPool threadPool)
threadPool - the thread poolprotected void doStart()
throws java.lang.Exception
AggregateLifeCycledoStart in class HandlerWrapperjava.lang.ExceptionAbstractLifeCycle.doStart()protected void doStop()
throws java.lang.Exception
AggregateLifeCycledoStop in class HandlerWrapperjava.lang.ExceptionAbstractLifeCycle.doStart()public void handle(java.lang.String target,
Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException,
java.io.IOException
Handlerhandle in interface Handlerhandle in class HandlerWrappertarget - 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.javax.servlet.ServletExceptionjava.io.IOExceptionprotected void handleConnect(Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String serverAddress) throws javax.servlet.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.
baseRequest - Jetty-specific http requestrequest - the http requestresponse - the http responseserverAddress - the remote server address in the form host:portjavax.servlet.ServletException - if an application error occursjava.io.IOException - if an I/O error occursprotected boolean handleAuthentication(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String address)
throws javax.servlet.ServletException,
java.io.IOException
Handles the authentication before setting up the tunnel to the remote server.
The default implementation returns true.
request - the HTTP requestresponse - the HTTP responseaddress - the address of the remote server in the form host:port.javax.servlet.ServletException - to report a server error to the callerjava.io.IOException - to report a server error to the callerprotected 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 java.nio.channels.SocketChannel connect(javax.servlet.http.HttpServletRequest request,
java.lang.String host,
int port)
throws java.io.IOException
Establishes a connection to the remote server.
request - the HTTP request that initiated the tunnelhost - the host to connect toport - the port to connect toSocketChannel connected to the remote serverjava.io.IOException - if the connection cannot be establishedprotected void prepareContext(javax.servlet.http.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) throws java.io.IOException
Reads (with non-blocking semantic) into the given buffer from the given endPoint.
endPoint - the endPoint to read frombuffer - the buffer to read data intocontext - the context information related to the connectionjava.io.IOException - if the endPoint cannot be readprotected 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.
endPoint - the endPoint to write tobuffer - the buffer to writecontext - the context information related to the connectionjava.io.IOException - if the buffer cannot be writtenpublic void addWhite(java.lang.String entry)
entry - new whitelist entrypublic void addBlack(java.lang.String entry)
entry - new blacklist entrypublic void setWhite(java.lang.String[] entries)
entries - array of whitelist entriespublic void setBlack(java.lang.String[] entries)
entries - array of blacklist entriesprotected void set(java.lang.String[] entries,
HostMap<java.lang.String> hostMap)
entries - new entrieshostMap - target host mappublic boolean validateDestination(java.lang.String host)
host - hostname to checkpublic void dump(java.lang.Appendable out,
java.lang.String indent)
throws java.io.IOException
dump in interface Dumpabledump in class AbstractHandlerContainerjava.io.IOExceptionCopyright © 2013 FuseSource, Corp.. All Rights Reserved.