|
||||||||||
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.server.handler.AbstractHandler org.eclipse.jetty.server.handler.AbstractHandlerContainer org.eclipse.jetty.server.handler.HandlerWrapper org.eclipse.jetty.server.handler.ProxyHandler
public class ProxyHandler
Implementation of a tunneling proxy that supports HTTP CONNECT and transparent proxy.
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.
To work as transparent proxy, objects of this class must be instantiated using the string
argument constructor, passing the remote host address and port in the form host:port
.
Nested Class Summary | |
---|---|
class |
ProxyHandler.ClientToProxyConnection
|
class |
ProxyHandler.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 | |
---|---|
ProxyHandler()
|
|
ProxyHandler(Handler handler)
|
Method Summary | |
---|---|
protected SocketChannel |
connect(HttpServletRequest request,
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(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 ProxyHandler.ClientToProxyConnection |
newClientToProxyConnection(ConcurrentMap<String,Object> context,
SocketChannel channel,
EndPoint endPoint,
long timeStamp)
|
protected ProxyHandler.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 . |
void |
setConnectTimeout(int connectTimeout)
|
void |
setServer(Server server)
|
void |
setThreadPool(ThreadPool threadPool)
|
void |
setWriteTimeout(int writeTimeout)
|
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 |
---|
expandChildren, getHandler, getHandlers, setHandler |
Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandlerContainer |
---|
dump, expandHandler, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass |
Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandler |
---|
destroy, 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 |
---|
public ProxyHandler()
public ProxyHandler(Handler handler)
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 ProxyHandler.ClientToProxyConnection newClientToProxyConnection(ConcurrentMap<String,Object> context, SocketChannel channel, EndPoint endPoint, long timeStamp)
protected ProxyHandler.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 written
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |