Asynchronous Proxy Servlet

The Jetty release contains an Asychronous Proxy Servlet that may be used either as a traditional web proxy (configured in a browser) or as a transparent proxy to forward requests from a jetty server to any other server.

Proxy Server

If the Asynchronous Proxy Servlet is configured as the default servlet at the '/' path of the root context, then browsers can be configured to use the jetty server as a proxy server. The Proxy servlet will detect the proxy requests from the absolute URL in the request line and forward the request to the real server.

Transparent Proxy

A transparent proxy can proxy normal HTTP requests to another server without any special cooperation from the client.

A derived AsynchronousProxyServlet should be configured in web.xml to match the paths that are to be proxied. The AsynchronousProxyServlet itself should be extended to implement the HttpURI proxyHttpURI(final String scheme, final String serverName, int serverPort, final String uri) method to return the URI destination to which a specific request will be proxied.

The derived AsynchronousProxyServlet.Trasparent subclass exists to perform standard transparent proxy operation. Currently this class needs to be programmaticly instantiated. From 6.1.19 release, the transparent proxy will configurable with init parameters as follows:

  <servlet>
    <servlet-name>GoogleProxy</servlet-name>
    <servlet-class>org.mortbay.proxy.AsyncProxyServlet$Transparent</servlet-class>
    <load-on-startup>1</load-on-startup>
    <init-param>
      <param-name>ProxyTo</param-name><param-value>http://www.google.com</param-value>
    </init-param>
    <init-param>
      <param-name>Prefix</param-name><param-value>/google</param-value>
    </init-param>
  </servlet>
  
  <servlet-mapping>
    <servlet-name>GoogleProxy</servlet-name>
    <url-pattern>/google/*</url-pattern>
  </servlet-mapping>