public class ConnectHandler extends HandlerWrapper
Implementation of a Handler
that supports HTTP CONNECT.
Modifier and Type | Class and Description |
---|---|
protected static class |
ConnectHandler.ConnectContext |
protected class |
ConnectHandler.ConnectManager |
class |
ConnectHandler.DownstreamConnection |
class |
ConnectHandler.UpstreamConnection |
AbstractLifeCycle.AbstractLifeCycleListener
LifeCycle.Listener
Container.InheritedListener, Container.Listener
Modifier and Type | Field and Description |
---|---|
protected static Logger |
LOG |
_handler
Constructor and Description |
---|
ConnectHandler() |
ConnectHandler(Handler handler) |
Modifier and Type | Method and Description |
---|---|
protected void |
doStart()
Starts the managed lifecycle beans in the order they were added.
|
void |
dump(Appendable out,
String indent) |
Set<String> |
getBlackListHosts() |
int |
getBufferSize() |
ByteBufferPool |
getByteBufferPool() |
long |
getConnectTimeout() |
Executor |
getExecutor() |
long |
getIdleTimeout() |
Scheduler |
getScheduler() |
Set<String> |
getWhiteListHosts() |
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 InetSocketAddress |
newConnectAddress(String host,
int port)
Create the address the connect channel will connect to.
|
protected ConnectHandler.DownstreamConnection |
newDownstreamConnection(EndPoint endPoint,
ConcurrentMap<String,Object> context,
ByteBuffer buffer) |
protected SelectorManager |
newSelectorManager() |
protected ConnectHandler.UpstreamConnection |
newUpstreamConnection(EndPoint endPoint,
ConnectHandler.ConnectContext connectContext) |
protected void |
onConnectFailure(HttpServletRequest request,
HttpServletResponse response,
AsyncContext asyncContext,
Throwable failure) |
protected void |
onConnectSuccess(ConnectHandler.ConnectContext connectContext,
ConnectHandler.UpstreamConnection upstreamConnection) |
protected void |
prepareContext(HttpServletRequest request,
ConcurrentMap<String,Object> context) |
protected int |
read(EndPoint endPoint,
ByteBuffer buffer)
Reads (with non-blocking semantic) into the given
buffer from the given endPoint . |
void |
setBufferSize(int bufferSize) |
void |
setByteBufferPool(ByteBufferPool bufferPool) |
void |
setConnectTimeout(long connectTimeout) |
void |
setExecutor(Executor executor) |
void |
setIdleTimeout(long idleTimeout) |
void |
setScheduler(Scheduler scheduler) |
boolean |
validateDestination(String host,
int port)
Checks the given
host and port against whitelist and blacklist. |
protected void |
write(EndPoint endPoint,
ByteBuffer buffer,
Callback callback)
Writes (with non-blocking semantic) the given buffer of data onto the given endPoint.
|
destroy, expandChildren, getHandler, getHandlers, insertHandler, setHandler
expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass, setServer
doStop, dumpThis, getServer
addBean, addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans
addLifeCycleListener, getState, getState, getStopTimeout, 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
protected static final Logger LOG
public ConnectHandler()
public ConnectHandler(Handler handler)
public Executor getExecutor()
public void setExecutor(Executor executor)
public Scheduler getScheduler()
public void setScheduler(Scheduler scheduler)
public ByteBufferPool getByteBufferPool()
public void setByteBufferPool(ByteBufferPool bufferPool)
public long getConnectTimeout()
public void setConnectTimeout(long connectTimeout)
connectTimeout
- the timeout, in milliseconds, to connect to the remote serverpublic long getIdleTimeout()
public void setIdleTimeout(long idleTimeout)
idleTimeout
- the idle timeout, in millisecondspublic int getBufferSize()
public void setBufferSize(int bufferSize)
protected void doStart() throws Exception
ContainerLifeCycle
doStart
in class AbstractHandler
Exception
protected SelectorManager newSelectorManager()
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()
.getHttpChannel()
.getRequest()
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()
.getHttpChannel()
.getResponse()
method can be used access the Response object if required.ServletException
- if unable to handle the request or response due to underlying servlet issueIOException
- if unable to handle the request or response processingprotected void handleConnect(Request baseRequest, HttpServletRequest request, HttpServletResponse response, String serverAddress)
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
protected InetSocketAddress newConnectAddress(String host, int port)
host
- The host from the connect requestport
- The port from the connect requestprotected void onConnectSuccess(ConnectHandler.ConnectContext connectContext, ConnectHandler.UpstreamConnection upstreamConnection)
protected void onConnectFailure(HttpServletRequest request, HttpServletResponse response, AsyncContext asyncContext, Throwable failure)
protected boolean handleAuthentication(HttpServletRequest request, HttpServletResponse response, String address)
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
.protected ConnectHandler.DownstreamConnection newDownstreamConnection(EndPoint endPoint, ConcurrentMap<String,Object> context, ByteBuffer buffer)
protected ConnectHandler.UpstreamConnection newUpstreamConnection(EndPoint endPoint, ConnectHandler.ConnectContext connectContext)
protected void prepareContext(HttpServletRequest request, ConcurrentMap<String,Object> context)
protected int read(EndPoint endPoint, ByteBuffer buffer) 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 intoIOException
- if the endPoint cannot be readprotected void write(EndPoint endPoint, ByteBuffer buffer, Callback callback)
Writes (with non-blocking semantic) the given buffer of data onto the given endPoint.
endPoint
- the endPoint to write tobuffer
- the buffer to writecallback
- the completion callback to invokepublic boolean validateDestination(String host, int port)
host
and port
against whitelist and blacklist.host
- the host to checkport
- the port to checkpublic void dump(Appendable out, String indent) throws IOException
dump
in interface Dumpable
dump
in class ContainerLifeCycle
IOException
Copyright © 1995-2015 Webtide. All Rights Reserved.