public class ProxyServlet
extends java.lang.Object
implements javax.servlet.Servlet
This servlet needs the jetty-util and jetty-client classes to be available to the web application.
To facilitate JMX monitoring, the "HttpClient" and "ThreadPool" are set as context attributes prefixed with the servlet name.
The following init parameters may be used to configure the servlet:
ConnectHandler| Modifier and Type | Class and Description |
|---|---|
static class |
ProxyServlet.Transparent
Transparent Proxy.
|
| Modifier and Type | Field and Description |
|---|---|
protected HostMap<PathMap> |
_black |
protected HttpClient |
_client |
protected javax.servlet.ServletConfig |
_config |
protected javax.servlet.ServletContext |
_context |
protected java.util.HashSet<java.lang.String> |
_DontProxyHeaders |
protected java.lang.String |
_hostHeader |
protected Logger |
_log |
protected HostMap<PathMap> |
_white |
| Constructor and Description |
|---|
ProxyServlet() |
| Modifier and Type | Method and Description |
|---|---|
protected HttpClient |
createHttpClient(javax.servlet.ServletConfig config)
Create and return an HttpClient based on ServletConfig
By default this implementation will create an instance of the
HttpClient for use by this proxy servlet.
|
protected HttpClient |
createHttpClientInstance()
Create and return an HttpClientInstance
|
protected Logger |
createLogger(javax.servlet.ServletConfig config)
Create and return a logger based on the ServletConfig for use in the
proxy servlet
|
protected void |
customizeContinuation(Continuation continuation)
Extension point for subclasses to customize the Continuation after it's initial creation in the service method.
|
protected void |
customizeExchange(HttpExchange exchange,
javax.servlet.http.HttpServletRequest request)
Extension point for subclasses to customize an exchange.
|
void |
destroy() |
protected java.lang.String |
filterResponseHeaderValue(java.lang.String headerName,
java.lang.String headerValue,
javax.servlet.http.HttpServletRequest request)
Extension point for remote server response header filtering.
|
java.lang.String |
getHostHeader()
Get the hostHeader.
|
javax.servlet.ServletConfig |
getServletConfig() |
java.lang.String |
getServletInfo() |
void |
handleConnect(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
protected void |
handleOnConnectionFailed(java.lang.Throwable ex,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Extension point for custom handling of an HttpExchange's onConnectionFailed method.
|
protected void |
handleOnException(java.lang.Throwable ex,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Extension point for custom handling of an HttpExchange's onException method.
|
protected void |
handleOnExpire(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Extension point for custom handling of an HttpExchange's onExpire method.
|
void |
init(javax.servlet.ServletConfig config) |
protected HttpURI |
proxyHttpURI(javax.servlet.http.HttpServletRequest request,
java.lang.String uri) |
protected HttpURI |
proxyHttpURI(java.lang.String scheme,
java.lang.String serverName,
int serverPort,
java.lang.String uri) |
void |
service(javax.servlet.ServletRequest req,
javax.servlet.ServletResponse res) |
void |
setHostHeader(java.lang.String hostHeader)
Set the hostHeader.
|
boolean |
validateDestination(java.lang.String host,
java.lang.String path)
Check the request hostname and path against white- and blacklist.
|
protected Logger _log
protected HttpClient _client
protected java.lang.String _hostHeader
protected java.util.HashSet<java.lang.String> _DontProxyHeaders
protected javax.servlet.ServletConfig _config
protected javax.servlet.ServletContext _context
public void init(javax.servlet.ServletConfig config)
throws javax.servlet.ServletException
init in interface javax.servlet.Servletjavax.servlet.ServletExceptionpublic void destroy()
destroy in interface javax.servlet.Servletprotected Logger createLogger(javax.servlet.ServletConfig config)
config - protected HttpClient createHttpClientInstance()
protected HttpClient createHttpClient(javax.servlet.ServletConfig config) throws java.lang.Exception
config - java.lang.Exceptionpublic boolean validateDestination(java.lang.String host,
java.lang.String path)
host - hostname to checkpath - path to checkpublic javax.servlet.ServletConfig getServletConfig()
getServletConfig in interface javax.servlet.Servletpublic java.lang.String getHostHeader()
public void setHostHeader(java.lang.String hostHeader)
hostHeader - the hostHeader to setpublic void service(javax.servlet.ServletRequest req,
javax.servlet.ServletResponse res)
throws javax.servlet.ServletException,
java.io.IOException
service in interface javax.servlet.Servletjavax.servlet.ServletExceptionjava.io.IOExceptionpublic void handleConnect(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws java.io.IOException
java.io.IOExceptionprotected HttpURI proxyHttpURI(javax.servlet.http.HttpServletRequest request, java.lang.String uri) throws java.net.MalformedURLException
java.net.MalformedURLExceptionprotected HttpURI proxyHttpURI(java.lang.String scheme, java.lang.String serverName, int serverPort, java.lang.String uri) throws java.net.MalformedURLException
java.net.MalformedURLExceptionpublic java.lang.String getServletInfo()
getServletInfo in interface javax.servlet.Servletprotected void customizeExchange(HttpExchange exchange, javax.servlet.http.HttpServletRequest request)
exchange - request - protected void customizeContinuation(Continuation continuation)
continuation - protected void handleOnConnectionFailed(java.lang.Throwable ex,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
handleOnException(Throwable, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)ex - request - response - protected void handleOnException(java.lang.Throwable ex,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
ex - request - response - protected void handleOnExpire(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
request - response - protected java.lang.String filterResponseHeaderValue(java.lang.String headerName,
java.lang.String headerValue,
javax.servlet.http.HttpServletRequest request)
headerName - headerValue - request - Copyright © 2013 FuseSource, Corp.. All Rights Reserved.