public class ProxyServlet extends 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 HashSet<String> |
_DontProxyHeaders |
protected 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 String |
filterResponseHeaderValue(String headerName,
String headerValue,
javax.servlet.http.HttpServletRequest request)
Extension point for remote server response header filtering.
|
String |
getHostHeader()
Get the hostHeader.
|
javax.servlet.ServletConfig |
getServletConfig() |
String |
getServletInfo() |
void |
handleConnect(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
protected void |
handleOnConnectionFailed(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(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,
String uri) |
protected HttpURI |
proxyHttpURI(String scheme,
String serverName,
int serverPort,
String uri) |
void |
service(javax.servlet.ServletRequest req,
javax.servlet.ServletResponse res) |
void |
setHostHeader(String hostHeader)
Set the hostHeader.
|
boolean |
validateDestination(String host,
String path)
Check the request hostname and path against white- and blacklist.
|
protected Logger _log
protected HttpClient _client
protected String _hostHeader
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.Servlet
javax.servlet.ServletException
public void destroy()
destroy
in interface javax.servlet.Servlet
protected Logger createLogger(javax.servlet.ServletConfig config)
config
- protected HttpClient createHttpClientInstance()
protected HttpClient createHttpClient(javax.servlet.ServletConfig config) throws Exception
config
- Exception
public boolean validateDestination(String host, String path)
host
- hostname to checkpath
- path to checkpublic javax.servlet.ServletConfig getServletConfig()
getServletConfig
in interface javax.servlet.Servlet
public String getHostHeader()
public void setHostHeader(String hostHeader)
hostHeader
- the hostHeader to setpublic void service(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res) throws javax.servlet.ServletException, IOException
service
in interface javax.servlet.Servlet
javax.servlet.ServletException
IOException
public void handleConnect(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
IOException
protected HttpURI proxyHttpURI(javax.servlet.http.HttpServletRequest request, String uri) throws MalformedURLException
MalformedURLException
protected HttpURI proxyHttpURI(String scheme, String serverName, int serverPort, String uri) throws MalformedURLException
MalformedURLException
public String getServletInfo()
getServletInfo
in interface javax.servlet.Servlet
protected void customizeExchange(HttpExchange exchange, javax.servlet.http.HttpServletRequest request)
exchange
- request
- protected void customizeContinuation(Continuation continuation)
continuation
- protected void handleOnConnectionFailed(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(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 String filterResponseHeaderValue(String headerName, String headerValue, javax.servlet.http.HttpServletRequest request)
headerName
- headerValue
- request
- Copyright © 1995-2013 Mort Bay Consulting. All Rights Reserved.