|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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
public class ConnectHandler
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.
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,
String[] white,
String[] black)
|
|
ConnectHandler(String[] white,
String[] black)
|
Method Summary | |
---|---|
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()
|
protected void |
doStop()
|
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. |
Methods inherited from class org.eclipse.jetty.server.handler.HandlerWrapper |
---|
destroy, expandChildren, getHandler, getHandlers, getNestedHandlerByClass, setHandler |
Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandlerContainer |
---|
expandHandler, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass |
Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandler |
---|
dumpThis, getServer |
Methods inherited from class org.eclipse.jetty.util.component.AggregateLifeCycle |
---|
addBean, dump, dump, dump, dump, dumpStdErr, getBean, getBeans, getBeans, removeBean, removeBeans |
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle |
---|
addLifeCycleListener, getState, getState, 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 |
Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle |
---|
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop |
Constructor Detail |
---|
public ConnectHandler()
public ConnectHandler(String[] white, String[] black)
public ConnectHandler(Handler handler)
public ConnectHandler(Handler handler, String[] white, String[] black)
Method Detail |
---|
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
doStart
in class HandlerWrapper
Exception
protected void doStop() throws Exception
doStop
in class HandlerWrapper
Exception
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws 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 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.
ServletException
IOException
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 requestrequest
- the http requestresponse
- the http responseserverAddress
- the remote server address in the form host:port
ServletException
- if an application error occurs
IOException
- if an I/O error occursprotected 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 requestresponse
- the HTTP responseaddress
- the address of the remote server in the form host:port
.
ServletException
- to report a server error to the caller
IOException
- 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(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 to
SocketChannel
connected to the remote server
IOException
- if the connection cannot be establishedprotected void prepareContext(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 connection
IOException
- 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 connection
IOException
- 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 check
public void dump(Appendable out, String indent) throws IOException
dump
in interface Dumpable
dump
in class AbstractHandlerContainer
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |