org.eclipse.jetty.servlets
类 ProxyServlet

java.lang.Object
  继承者 org.eclipse.jetty.servlets.ProxyServlet
所有已实现的接口:
Servlet
直接已知子类:
BalancerServlet, ProxyServlet.Transparent

public class ProxyServlet
extends Object
implements Servlet

Asynchronous Proxy Servlet. Forward requests to another server either as a standard web proxy (as defined by RFC2616) or as a transparent proxy.

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

嵌套类摘要
static class ProxyServlet.Transparent
          Transparent Proxy.
 
字段摘要
protected  HostMap<PathMap> _black
           
protected  HttpClient _client
           
protected  ServletConfig _config
           
protected  ServletContext _context
           
protected  HashSet<String> _DontProxyHeaders
           
protected  String _hostHeader
           
protected  Logger _log
           
protected  HostMap<PathMap> _white
           
 
构造方法摘要
ProxyServlet()
           
 
方法摘要
protected  HttpClient createHttpClient(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(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, HttpServletRequest request)
          Extension point for subclasses to customize an exchange.
 void destroy()
          Called by the servlet container to indicate to a servlet that the servlet is being taken out of service.
protected  String filterResponseHeaderValue(String headerName, String headerValue, HttpServletRequest request)
          Extension point for remote server response header filtering.
 String getHostHeader()
          Get the hostHeader.
 ServletConfig getServletConfig()
          Returns a ServletConfig object, which contains initialization and startup parameters for this servlet.
 String getServletInfo()
          Returns information about the servlet, such as author, version, and copyright.
 void handleConnect(HttpServletRequest request, HttpServletResponse response)
           
protected  void handleOnConnectionFailed(Throwable ex, HttpServletRequest request, HttpServletResponse response)
          Extension point for custom handling of an HttpExchange's onConnectionFailed method.
protected  void handleOnException(Throwable ex, HttpServletRequest request, HttpServletResponse response)
          Extension point for custom handling of an HttpExchange's onException method.
protected  void handleOnExpire(HttpServletRequest request, HttpServletResponse response)
          Extension point for custom handling of an HttpExchange's onExpire method.
 void init(ServletConfig config)
          Called by the servlet container to indicate to a servlet that the servlet is being placed into service.
protected  HttpURI proxyHttpURI(HttpServletRequest request, String uri)
           
protected  HttpURI proxyHttpURI(String scheme, String serverName, int serverPort, String uri)
           
 void service(ServletRequest req, ServletResponse res)
          Called by the servlet container to allow the servlet to respond to a request.
 void setHostHeader(String hostHeader)
          Set the hostHeader.
 boolean validateDestination(String host, String path)
          Check the request hostname and path against white- and blacklist.
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

_log

protected Logger _log

_client

protected HttpClient _client

_hostHeader

protected String _hostHeader

_DontProxyHeaders

protected HashSet<String> _DontProxyHeaders

_config

protected ServletConfig _config

_context

protected ServletContext _context

_white

protected HostMap<PathMap> _white

_black

protected HostMap<PathMap> _black
构造方法详细信息

ProxyServlet

public ProxyServlet()
方法详细信息

init

public void init(ServletConfig config)
          throws ServletException
从接口 Servlet 复制的描述
Called by the servlet container to indicate to a servlet that the servlet is being placed into service.

The servlet container calls the init method exactly once after instantiating the servlet. The init method must complete successfully before the servlet can receive any requests.

The servlet container cannot place the servlet into service if the init method

  1. Throws a ServletException
  2. Does not return within a time period defined by the Web server

指定者:
接口 Servlet 中的 init
参数:
config - a ServletConfig object containing the servlet's configuration and initialization parameters
抛出:
ServletException - if an exception has occurred that interferes with the servlet's normal operation
另请参见:
UnavailableException, Servlet.getServletConfig()

destroy

public void destroy()
从接口 Servlet 复制的描述
Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. This method is only called once all threads within the servlet's service method have exited or after a timeout period has passed. After the servlet container calls this method, it will not call the service method again on this servlet.

This method gives the servlet an opportunity to clean up any resources that are being held (for example, memory, file handles, threads) and make sure that any persistent state is synchronized with the servlet's current state in memory.

指定者:
接口 Servlet 中的 destroy

createLogger

protected Logger createLogger(ServletConfig config)
Create and return a logger based on the ServletConfig for use in the proxy servlet

参数:
config -
返回:
Logger

createHttpClientInstance

protected HttpClient createHttpClientInstance()
Create and return an HttpClientInstance

返回:
HttpClient

createHttpClient

protected HttpClient createHttpClient(ServletConfig config)
                               throws Exception
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.

参数:
config -
返回:
HttpClient
抛出:
Exception

validateDestination

public boolean validateDestination(String host,
                                   String path)
Check the request hostname and path against white- and blacklist.

参数:
host - hostname to check
path - path to check
返回:
true if request is allowed to be proxied

getServletConfig

public ServletConfig getServletConfig()
从接口 Servlet 复制的描述
Returns a ServletConfig object, which contains initialization and startup parameters for this servlet. The ServletConfig object returned is the one passed to the init method.

Implementations of this interface are responsible for storing the ServletConfig object so that this method can return it. The GenericServlet class, which implements this interface, already does this.

指定者:
接口 Servlet 中的 getServletConfig
返回:
the ServletConfig object that initializes this servlet
另请参见:
Servlet.init(javax.servlet.ServletConfig)

getHostHeader

public String getHostHeader()
Get the hostHeader.

返回:
the hostHeader

setHostHeader

public void setHostHeader(String hostHeader)
Set the hostHeader.

参数:
hostHeader - the hostHeader to set

service

public void service(ServletRequest req,
                    ServletResponse res)
             throws ServletException,
                    IOException
从接口 Servlet 复制的描述
Called by the servlet container to allow the servlet to respond to a request.

This method is only called after the servlet's init() method has completed successfully.

The status code of the response always should be set for a servlet that throws or sends an error.

Servlets typically run inside multithreaded servlet containers that can handle multiple requests concurrently. Developers must be aware to synchronize access to any shared resources such as files, network connections, and as well as the servlet's class and instance variables. More information on multithreaded programming in Java is available in the Java tutorial on multi-threaded programming.

指定者:
接口 Servlet 中的 service
参数:
req - the ServletRequest object that contains the client's request
res - the ServletResponse object that contains the servlet's response
抛出:
ServletException - if an exception occurs that interferes with the servlet's normal operation
IOException - if an input or output exception occurs

handleConnect

public void handleConnect(HttpServletRequest request,
                          HttpServletResponse response)
                   throws IOException
抛出:
IOException

proxyHttpURI

protected HttpURI proxyHttpURI(HttpServletRequest request,
                               String uri)
                        throws MalformedURLException
抛出:
MalformedURLException

proxyHttpURI

protected HttpURI proxyHttpURI(String scheme,
                               String serverName,
                               int serverPort,
                               String uri)
                        throws MalformedURLException
抛出:
MalformedURLException

getServletInfo

public String getServletInfo()
从接口 Servlet 复制的描述
Returns information about the servlet, such as author, version, and copyright.

The string that this method returns should be plain text and not markup of any kind (such as HTML, XML, etc.).

指定者:
接口 Servlet 中的 getServletInfo
返回:
a String containing servlet information

customizeExchange

protected void customizeExchange(HttpExchange exchange,
                                 HttpServletRequest request)
Extension point for subclasses to customize an exchange. Useful for setting timeouts etc. The default implementation does nothing.

参数:
exchange -
request -

customizeContinuation

protected void customizeContinuation(Continuation continuation)
Extension point for subclasses to customize the Continuation after it's initial creation in the service method. Useful for setting timeouts etc. The default implementation does nothing.

参数:
continuation -

handleOnConnectionFailed

protected void handleOnConnectionFailed(Throwable ex,
                                        HttpServletRequest request,
                                        HttpServletResponse response)
Extension point for custom handling of an HttpExchange's onConnectionFailed method. The default implementation delegates to handleOnException(Throwable, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

参数:
ex -
request -
response -

handleOnException

protected void handleOnException(Throwable ex,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
Extension point for custom handling of an HttpExchange's onException method. The default implementation sets the response status to HttpServletResponse.SC_INTERNAL_SERVER_ERROR (503)

参数:
ex -
request -
response -

handleOnExpire

protected void handleOnExpire(HttpServletRequest request,
                              HttpServletResponse response)
Extension point for custom handling of an HttpExchange's onExpire method. The default implementation sets the response status to HttpServletResponse.SC_GATEWAY_TIMEOUT (504)

参数:
request -
response -

filterResponseHeaderValue

protected String filterResponseHeaderValue(String headerName,
                                           String headerValue,
                                           HttpServletRequest request)
Extension point for remote server response header filtering. The default implementation returns the header value as is. If null is returned, this header won't be forwarded back to the client.

参数:
headerName -
headerValue -
request -
返回:
filteredHeaderValue


Copyright © 2013. All Rights Reserved.