org.eclipse.jetty.server.handler

Class ConnectHandler

  • All Implemented Interfaces:
    Handler, HandlerContainer, Destroyable, Dumpable, LifeCycle
    Direct Known Subclasses:
    ProxyHandler


    public class ConnectHandlerextends HandlerWrapper

    Implementation of a tunneling proxy that supports HTTP CONNECT.

    To work as CONNECT proxy, objects of this class must be instantiated using the no-arguments constructor, since the remote server information will be present in the CONNECT URI.

    • Constructor Detail

      • ConnectHandler

        public ConnectHandler()
      • ConnectHandler

        public ConnectHandler(String[] white,              String[] black)
      • ConnectHandler

        public ConnectHandler(Handler handler)
    • Method Detail

      • getConnectTimeout

        public int getConnectTimeout()
        Returns:
        the timeout, in milliseconds, to connect to the remote server
      • setConnectTimeout

        public void setConnectTimeout(int connectTimeout)
        Parameters:
        connectTimeout - the timeout, in milliseconds, to connect to the remote server
      • getWriteTimeout

        public int getWriteTimeout()
        Returns:
        the timeout, in milliseconds, to write data to a peer
      • setWriteTimeout

        public void setWriteTimeout(int writeTimeout)
        Parameters:
        writeTimeout - the timeout, in milliseconds, to write data to a peer
      • getThreadPool

        public ThreadPool getThreadPool()
        Returns:
        the thread pool
      • setThreadPool

        public void setThreadPool(ThreadPool threadPool)
        Parameters:
        threadPool - the thread pool
      • handle

        public void handle(String target,          Request baseRequest,          javax.servlet.http.HttpServletRequest request,          javax.servlet.http.HttpServletResponse response)            throws javax.servlet.ServletException,                   IOException
        Description copied from interface: Handler
        Handle a request.
        Specified by:
        handle in interface Handler
        Overrides:
        handle in class HandlerWrapper
        Parameters:
        target - The target of the request - either a URI or a name.
        baseRequest - The original unwrapped request object.
        request - The request either as the Request object or a wrapper of that request. The AbstractHttpConnection.getCurrentConnection() method can be used access the Request object if required.
        response - The response as the Response object or a wrapper of that request. The AbstractHttpConnection.getCurrentConnection() method can be used access the Response object if required.
        Throws:
        javax.servlet.ServletException
        IOException
      • handleConnect

        protected void handleConnect(Request baseRequest,                 javax.servlet.http.HttpServletRequest request,                 javax.servlet.http.HttpServletResponse response,                 String serverAddress)                      throws javax.servlet.ServletException,                             IOException

        Handles a CONNECT request.

        CONNECT requests may have authentication headers such as Proxy-Authorization that authenticate the client with the proxy.

        Parameters:
        baseRequest - Jetty-specific http request
        request - the http request
        response - the http response
        serverAddress - the remote server address in the form host:port
        Throws:
        javax.servlet.ServletException - if an application error occurs
        IOException - if an I/O error occurs
      • handleAuthentication

        protected boolean handleAuthentication(javax.servlet.http.HttpServletRequest request,                           javax.servlet.http.HttpServletResponse response,                           String address)                                throws javax.servlet.ServletException,                                       IOException

        Handles the authentication before setting up the tunnel to the remote server.

        The default implementation returns true.

        Parameters:
        request - the HTTP request
        response - the HTTP response
        address - the address of the remote server in the form host:port.
        Returns:
        true to allow to connect to the remote host, false otherwise
        Throws:
        javax.servlet.ServletException - to report a server error to the caller
        IOException - to report a server error to the caller
      • connect

        protected SocketChannel connect(javax.servlet.http.HttpServletRequest request,                    String host,                    int port)                         throws IOException

        Establishes a connection to the remote server.

        Parameters:
        request - the HTTP request that initiated the tunnel
        host - the host to connect to
        port - the port to connect to
        Returns:
        a SocketChannel connected to the remote server
        Throws:
        IOException - if the connection cannot be established
      • prepareContext

        protected void prepareContext(javax.servlet.http.HttpServletRequest request,                  ConcurrentMap<String,Object> context)
      • read

        protected int read(EndPoint endPoint,       Buffer buffer,       ConcurrentMap<String,Object> context)            throws IOException

        Reads (with non-blocking semantic) into the given buffer from the given endPoint.

        Parameters:
        endPoint - the endPoint to read from
        buffer - the buffer to read data into
        context - the context information related to the connection
        Returns:
        the number of bytes read (possibly 0 since the read is non-blocking) or -1 if the channel has been closed remotely
        Throws:
        IOException - if the endPoint cannot be read
      • write

        protected int write(EndPoint endPoint,        Buffer buffer,        ConcurrentMap<String,Object> context)             throws IOException

        Writes (with blocking semantic) the given buffer of data onto the given endPoint.

        Parameters:
        endPoint - the endPoint to write to
        buffer - the buffer to write
        context - the context information related to the connection
        Returns:
        the number of bytes written
        Throws:
        IOException - if the buffer cannot be written
      • addWhite

        public void addWhite(String entry)
        Add a whitelist entry to an existing handler configuration
        Parameters:
        entry - new whitelist entry
      • addBlack

        public void addBlack(String entry)
        Add a blacklist entry to an existing handler configuration
        Parameters:
        entry - new blacklist entry
      • setWhite

        public void setWhite(String[] entries)
        Re-initialize the whitelist of existing handler object
        Parameters:
        entries - array of whitelist entries
      • setBlack

        public void setBlack(String[] entries)
        Re-initialize the blacklist of existing handler object
        Parameters:
        entries - array of blacklist entries
      • set

        protected void set(String[] entries,       HostMap<String> hostMap)
        Helper method to process a list of new entries and replace the content of the specified host map
        Parameters:
        entries - new entries
        hostMap - target host map
      • validateDestination

        public boolean validateDestination(String host)
        Check the request hostname against white- and blacklist.
        Parameters:
        host - hostname to check
        Returns:
        true if hostname is allowed to be proxied

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



NOTHING
NOTHING
Add the Maven Dependecy to your project: maven dependecy for com.amazonaws : aws-java-sdk : 1.3.14