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.AbstractLifeCycleListener
LifeCycle.Listener
_handler
_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING
Constructor and Description |
---|
ConnectHandler() |
ConnectHandler(Handler handler) |
ConnectHandler(Handler handler,
String[] white,
String[] black) |
ConnectHandler(String[] white,
String[] black) |
Modifier and Type | Method and Description |
---|---|
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(javax.servlet.http.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,
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,
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,
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(javax.servlet.http.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.
|
destroy, expandChildren, getHandler, getHandlers, getNestedHandlerByClass, setHandler
expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass
dumpThis, getServer
addBean, addBean, contains, dump, dump, dump, dump, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, unmanage
addLifeCycleListener, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
public ConnectHandler()
public ConnectHandler(Handler handler)
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 Handler
setServer
in class HandlerWrapper
public ThreadPool getThreadPool()
public void setThreadPool(ThreadPool threadPool)
threadPool
- the thread poolprotected void doStart() throws Exception
AggregateLifeCycle
doStart
in class HandlerWrapper
Exception
AbstractLifeCycle.doStart()
protected void doStop() throws Exception
AggregateLifeCycle
doStop
in class HandlerWrapper
Exception
AbstractLifeCycle.doStart()
public void handle(String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
Handler
handle
in interface Handler
handle
in class HandlerWrapper
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.javax.servlet.ServletException
IOException
protected void handleConnect(Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String serverAddress) throws javax.servlet.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 requestrequest
- the http requestresponse
- the http responseserverAddress
- the remote server address in the form host:port
javax.servlet.ServletException
- if an application error occursIOException
- if an I/O error occursprotected boolean handleAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String address) throws javax.servlet.ServletException, 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 callerIOException
- to report a server error to the callerprotected ConnectHandler.ClientToProxyConnection newClientToProxyConnection(ConcurrentMap<String,Object> context, SocketChannel channel, EndPoint endPoint, long timeStamp)
protected ConnectHandler.ProxyToServerConnection newProxyToServerConnection(ConcurrentMap<String,Object> context, Buffer buffer)
protected SocketChannel connect(javax.servlet.http.HttpServletRequest request, String host, int port) throws 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 serverIOException
- if the connection cannot be establishedprotected void prepareContext(javax.servlet.http.HttpServletRequest request, ConcurrentMap<String,Object> context)
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 frombuffer
- the buffer to read data intocontext
- the context information related to the connectionIOException
- if the endPoint cannot be readprotected 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 tobuffer
- the buffer to writecontext
- the context information related to the connectionIOException
- if the buffer cannot be writtenpublic void addWhite(String entry)
entry
- new whitelist entrypublic void addBlack(String entry)
entry
- new blacklist entrypublic void setWhite(String[] entries)
entries
- array of whitelist entriespublic void setBlack(String[] entries)
entries
- array of blacklist entriesprotected void set(String[] entries, HostMap<String> hostMap)
entries
- new entrieshostMap
- target host mappublic boolean validateDestination(String host)
host
- hostname to checkpublic void dump(Appendable out, String indent) throws IOException
dump
in interface Dumpable
dump
in class AbstractHandlerContainer
IOException
Copyright © 1995-2013 Mort Bay Consulting. All Rights Reserved.