public class ProxyServlet extends HttpServlet
HttpClient
instance is set as context attribute,
prefixed with the servlet's name and exposed by the mechanism provided by
ServletContext.setAttribute(String, Object)
.
The following init parameters may be used to configure the servlet:
createHttpClient()
for init parameters used to configure
the HttpClient
instance.ConnectHandler
,
Serialized FormModifier and Type | Class and Description |
---|---|
protected class |
ProxyServlet.ProxyInputStreamContentProvider |
protected class |
ProxyServlet.ProxyResponseListener |
static class |
ProxyServlet.Transparent
This convenience extension to
ProxyServlet configures the servlet as a transparent proxy. |
protected static class |
ProxyServlet.TransparentDelegate |
Constructor and Description |
---|
ProxyServlet() |
Modifier and Type | Method and Description |
---|---|
protected Request |
addViaHeader(Request proxyRequest) |
protected void |
addXForwardedHeaders(Request proxyRequest,
HttpServletRequest request) |
protected HttpClient |
createHttpClient()
Creates a
HttpClient instance, configured with init parameters of this servlet. |
protected Logger |
createLogger() |
protected void |
customizeProxyRequest(Request proxyRequest,
HttpServletRequest request)
Extension point for subclasses to customize the proxy request.
|
void |
destroy() |
protected String |
filterResponseHeader(HttpServletRequest request,
String headerName,
String headerValue)
Extension point for remote server response header filtering.
|
Set<String> |
getBlackListHosts() |
protected HttpClient |
getHttpClient() |
protected int |
getRequestId(HttpServletRequest request) |
long |
getTimeout() |
String |
getViaHost() |
Set<String> |
getWhiteListHosts() |
void |
init() |
protected HttpClient |
newHttpClient() |
protected Response.Listener |
newProxyResponseListener(HttpServletRequest request,
HttpServletResponse response) |
protected void |
onClientRequestFailure(Request proxyRequest,
HttpServletRequest request,
Throwable failure) |
protected void |
onResponseContent(HttpServletRequest request,
HttpServletResponse response,
Response proxyResponse,
byte[] buffer,
int offset,
int length,
Callback callback) |
protected void |
onResponseFailure(HttpServletRequest request,
HttpServletResponse response,
Response proxyResponse,
Throwable failure) |
protected void |
onResponseHeaders(HttpServletRequest request,
HttpServletResponse response,
Response proxyResponse) |
protected void |
onResponseSuccess(HttpServletRequest request,
HttpServletResponse response,
Response proxyResponse) |
protected void |
onRewriteFailed(HttpServletRequest request,
HttpServletResponse response) |
protected ContentProvider |
proxyRequestContent(Request proxyRequest,
HttpServletRequest request) |
protected URI |
rewriteURI(HttpServletRequest request) |
protected void |
service(HttpServletRequest request,
HttpServletResponse response) |
void |
setTimeout(long timeout) |
boolean |
validateDestination(String host,
int port)
Checks the given
host and port against whitelist and blacklist. |
protected static String |
viaHost() |
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
protected Logger _log
public void init() throws ServletException
init
in class GenericServlet
ServletException
public String getViaHost()
public long getTimeout()
public void setTimeout(long timeout)
protected static String viaHost()
protected HttpClient getHttpClient()
protected Logger createLogger()
public void destroy()
destroy
in interface Servlet
destroy
in class GenericServlet
protected HttpClient createHttpClient() throws ServletException
HttpClient
instance, configured with init parameters of this servlet.
The init parameters used to configure the HttpClient
instance are:
init-param | default | description |
---|---|---|
maxThreads | 256 | The max number of threads of HttpClient's Executor. If not set, or set to the value of "-", then the Jetty server thread pool will be used. |
maxConnections | 32768 | The max number of connections per destination, see HttpClient.setMaxConnectionsPerDestination(int) |
idleTimeout | 30000 | The idle timeout in milliseconds, see HttpClient.setIdleTimeout(long) |
timeout | 60000 | The total timeout in milliseconds, see Request.timeout(long, TimeUnit) |
requestBufferSize | HttpClient's default | The request buffer size, see HttpClient.setRequestBufferSize(int) |
responseBufferSize | HttpClient's default | The response buffer size, see HttpClient.setResponseBufferSize(int) |
HttpClient
configured from the servlet configuration
ServletException
- if the HttpClient
cannot be createdprotected HttpClient newHttpClient()
public boolean validateDestination(String host, int port)
host
and port
against whitelist and blacklist.host
- the host to checkport
- the port to checkprotected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
service
in class HttpServlet
ServletException
IOException
protected ContentProvider proxyRequestContent(Request proxyRequest, HttpServletRequest request) throws IOException
IOException
protected Response.Listener newProxyResponseListener(HttpServletRequest request, HttpServletResponse response)
protected void onClientRequestFailure(Request proxyRequest, HttpServletRequest request, Throwable failure)
protected void onRewriteFailed(HttpServletRequest request, HttpServletResponse response) throws IOException
IOException
protected void addXForwardedHeaders(Request proxyRequest, HttpServletRequest request)
protected void onResponseHeaders(HttpServletRequest request, HttpServletResponse response, Response proxyResponse)
protected void onResponseContent(HttpServletRequest request, HttpServletResponse response, Response proxyResponse, byte[] buffer, int offset, int length, Callback callback)
protected void onResponseSuccess(HttpServletRequest request, HttpServletResponse response, Response proxyResponse)
protected void onResponseFailure(HttpServletRequest request, HttpServletResponse response, Response proxyResponse, Throwable failure)
protected int getRequestId(HttpServletRequest request)
protected URI rewriteURI(HttpServletRequest request)
protected void customizeProxyRequest(Request proxyRequest, HttpServletRequest request)
proxyRequest
- the proxy request to customizerequest
- the request to be proxiedprotected String filterResponseHeader(HttpServletRequest request, String headerName, String headerValue)
headerName
- the header nameheaderValue
- the header valuerequest
- the request to proxyCopyright © 1995-2015 Webtide. All Rights Reserved.