Class ProxyServlet

  • All Implemented Interfaces:
    java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

    public class ProxyServlet
    extends GenericServlet
    A simple proxy servlet implementation. Supports HTTP and HTTPS.

    Note: The servlet is not a true HTTP proxy as described in RFC 2616, instead it passes on all incoming HTTP requests to the configured remote server. Useful for bypassing firewalls or to avoid exposing internal network infrastructure to external clients.

    At the moment, no caching of content is implemented.

    If the remoteServer init parameter is not set, the servlet will respond by sending a 500 Internal Server Error response to the client. If the configured remote server is down, or unreachable, the servlet will respond by sending a 502 Bad Gateway response to the client. Otherwise, the response from the remote server will be tunneled unmodified to the client.

    Version:
    $Id: ProxyServlet.java#1 $
    Author:
    Harald Kuhr, last modified by $Author: haku $
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.String remotePath
      Remote server "mount" path
      protected int remotePort
      Remote server port
      protected java.lang.String remoteServer
      Remote server host name or IP address
    • Constructor Summary

      Constructors 
      Constructor Description
      ProxyServlet()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void service​(javax.servlet.http.HttpServletRequest pRequest, javax.servlet.http.HttpServletResponse pResponse)
      Services a single request.
      void service​(javax.servlet.ServletRequest pRequest, javax.servlet.ServletResponse pResponse)
      Override service to use HTTP specifics.
      void setRemotePath​(java.lang.String pRemotePath)
      Called by init to set the remote path.
      void setRemotePort​(java.lang.String pRemotePort)
      Called by init to set the remote port.
      void setRemoteServer​(java.lang.String pRemoteServer)
      Called by init to set the remote server.
      • Methods inherited from class javax.servlet.GenericServlet

        destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • remoteServer

        protected java.lang.String remoteServer
        Remote server host name or IP address
      • remotePort

        protected int remotePort
        Remote server port
      • remotePath

        protected java.lang.String remotePath
        Remote server "mount" path
    • Constructor Detail

      • ProxyServlet

        public ProxyServlet()
    • Method Detail

      • setRemoteServer

        public void setRemoteServer​(java.lang.String pRemoteServer)
        Called by init to set the remote server. Must be a valid host name or IP address. No default.
        Parameters:
        pRemoteServer -
      • setRemotePort

        public void setRemotePort​(java.lang.String pRemotePort)
        Called by init to set the remote port. Must be a number. Default is 80.
        Parameters:
        pRemotePort -
      • setRemotePath

        public void setRemotePath​(java.lang.String pRemotePath)
        Called by init to set the remote path. May be an empty string for the root path, or any other valid path on the remote server. Default is "".
        Parameters:
        pRemotePath -
      • service

        public final void service​(javax.servlet.ServletRequest pRequest,
                                  javax.servlet.ServletResponse pResponse)
                           throws javax.servlet.ServletException,
                                  java.io.IOException
        Override service to use HTTP specifics.
        Specified by:
        service in interface javax.servlet.Servlet
        Specified by:
        service in class javax.servlet.GenericServlet
        Parameters:
        pRequest -
        pResponse -
        Throws:
        javax.servlet.ServletException
        java.io.IOException
        See Also:
        service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
      • service

        protected void service​(javax.servlet.http.HttpServletRequest pRequest,
                               javax.servlet.http.HttpServletResponse pResponse)
                        throws javax.servlet.ServletException,
                               java.io.IOException
        Services a single request. Supports HTTP and HTTPS.
        Parameters:
        pRequest -
        pResponse -
        Throws:
        javax.servlet.ServletException
        java.io.IOException
        See Also:
        Class descrition