ProxyServlet (Jetty :: Aggregate :: All core Jetty 7.6.8.v20121106 API)
Date: 2012-11-06

org.eclipse.jetty.servlets

## Class ProxyServlet

- java.lang.Object
- - org.eclipse.jetty.servlets.ProxyServlet

- All Implemented Interfaces:
    javax.servlet.Servlet
  Direct Known Subclasses:
    BalancerServlet, ProxyServlet.Transparent

      public class ProxyServlet
      extends Object
      implements javax.servlet.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:

  - name - Name of Proxy servlet (default: "ProxyServlet"
  - maxThreads - maximum threads
  - maxConnections - maximum connections per destination
  - timeout - the period in ms the client will wait for a response from the proxied server
  - idleTimeout - the period in ms a connection to proxied server can be idle for before it is closed
  - requestHeaderSize - the size of the request header buffer (d. 6,144)
  - requestBufferSize - the size of the request buffer (d. 12,288)
  - responseHeaderSize - the size of the response header buffer (d. 6,144)
  - responseBufferSize - the size of the response buffer (d. 32,768)
  - HostHeader - Force the host header to a particular value
  - whiteList - comma-separated list of allowed proxy destinations
  - blackList - comma-separated list of forbidden proxy destinations
  See Also:
    `ConnectHandler`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `ProxyServlet.Transparent` Transparent Proxy.

  - ### Field Summary

    Fields
    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 Summary

    Constructors
    Constructor and Description
    `ProxyServlet()`

  - ### Method Summary

    Methods
    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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### _log

          protected Logger _log

    - #### _client

          protected HttpClient _client

    - #### _hostHeader

          protected String _hostHeader

    - #### _DontProxyHeaders

          protected HashSet<String> _DontProxyHeaders

    - #### _config

          protected javax.servlet.ServletConfig _config

    - #### _context

          protected javax.servlet.ServletContext _context

    - #### _white

          protected HostMap<PathMap> _white

    - #### _black

          protected HostMap<PathMap> _black

  - ### Constructor Detail

    - #### ProxyServlet

          public ProxyServlet()

  - ### Method Detail

    - #### init

          public void init(javax.servlet.ServletConfig config)
                    throws javax.servlet.ServletException

      Specified by:
        `init` in interface `javax.servlet.Servlet`
      Throws:
        `javax.servlet.ServletException`

    - #### destroy

          public void destroy()

      Specified by:
        `destroy` in interface `javax.servlet.Servlet`

    - #### createLogger

          protected Logger createLogger(javax.servlet.ServletConfig config)

      Create and return a logger based on the ServletConfig for use in the proxy servlet
      Parameters:
        `config` -
      Returns:
        Logger

    - #### createHttpClientInstance

          protected HttpClient createHttpClientInstance()

      Create and return an HttpClientInstance
      Returns:
        HttpClient

    - #### createHttpClient

          protected HttpClient createHttpClient(javax.servlet.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.
      Parameters:
        `config` -
      Returns:
        HttpClient
      Throws:
        `Exception`

    - #### validateDestination

          public boolean validateDestination(String host,
                                    String path)

      Check the request hostname and path against white- and blacklist.
      Parameters:
        `host` - hostname to check
        `path` - path to check
      Returns:
        true if request is allowed to be proxied

    - #### getServletConfig

          public javax.servlet.ServletConfig getServletConfig()

      Specified by:
        `getServletConfig` in interface `javax.servlet.Servlet`

    - #### getHostHeader

          public String getHostHeader()

      Get the hostHeader.
      Returns:
        the hostHeader

    - #### setHostHeader

          public void setHostHeader(String hostHeader)

      Set the hostHeader.
      Parameters:
        `hostHeader` - the hostHeader to set

    - #### service

          public void service(javax.servlet.ServletRequest req,
                     javax.servlet.ServletResponse res)
                       throws javax.servlet.ServletException,
                              IOException

      Specified by:
        `service` in interface `javax.servlet.Servlet`
      Throws:
        `javax.servlet.ServletException`
        `IOException`

    - #### handleConnect

          public void handleConnect(javax.servlet.http.HttpServletRequest request,
                           javax.servlet.http.HttpServletResponse response)
                             throws IOException

      Throws:
        `IOException`

    - #### proxyHttpURI

          protected HttpURI proxyHttpURI(javax.servlet.http.HttpServletRequest request,
                             String uri)
                                  throws MalformedURLException

      Throws:
        `MalformedURLException`

    - #### proxyHttpURI

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

      Throws:
        `MalformedURLException`

    - #### getServletInfo

          public String getServletInfo()

      Specified by:
        `getServletInfo` in interface `javax.servlet.Servlet`

    - #### customizeExchange

          protected void customizeExchange(HttpExchange exchange,
                               javax.servlet.http.HttpServletRequest request)

      Extension point for subclasses to customize an exchange. Useful for setting timeouts etc. The default implementation does nothing.
      Parameters:
        `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.
      Parameters:
        `continuation` -

    - #### handleOnConnectionFailed

          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. The default implementation delegates to `handleOnException(Throwable, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)`
      Parameters:
        `ex` -
        `request` -
        `response` -

    - #### handleOnException

          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. The default implementation sets the response status to HttpServletResponse.SC_INTERNAL_SERVER_ERROR (503)
      Parameters:
        `ex` -
        `request` -
        `response` -

    - #### handleOnExpire

          protected void handleOnExpire(javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.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)
      Parameters:
        `request` -
        `response` -

    - #### filterResponseHeaderValue

          protected String filterResponseHeaderValue(String headerName,
                                         String headerValue,
                                         javax.servlet.http.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.
      Parameters:
        `headerName` -
        `headerValue` -
        `request` -
      Returns:
        filteredHeaderValue

Copyright © 1995-2012 Mort Bay Consulting. All Rights Reserved.