Class ProxyFilter

  • All Implemented Interfaces:
    IoFilter

    public class ProxyFilter
    extends IoFilterAdapter
    ProxyFilter.java - Proxy IoFilter. Automatically inserted into the IoFilter chain by ProxyConnector. Sends the initial handshake message to the proxy and handles any response to the handshake. Once the handshake has completed and the proxied connection has been established this filter becomes transparent to data flowing through the connection.

    Based upon SSLFilter from mina-filter-ssl.

    Since:
    MINA 2.0.0-M3
    Author:
    Apache MINA Project
    • Constructor Detail

      • ProxyFilter

        public ProxyFilter()
        Create a new ProxyFilter.
    • Method Detail

      • onPreAdd

        public void onPreAdd​(IoFilterChain chain,
                             java.lang.String name,
                             IoFilter.NextFilter nextFilter)
        Called before the filter is added into the filter chain. Checks if chain already holds an ProxyFilter instance.
        Specified by:
        onPreAdd in interface IoFilter
        Overrides:
        onPreAdd in class IoFilterAdapter
        Parameters:
        chain - the filter chain
        name - the name assigned to this filter
        nextFilter - the next filter
        Throws:
        java.lang.IllegalStateException - if chain already contains an instance of ProxyFilter
      • exceptionCaught

        public void exceptionCaught​(IoFilter.NextFilter nextFilter,
                                    IoSession session,
                                    java.lang.Throwable cause)
                             throws java.lang.Exception
        Called when an exception occurs in the chain. A flag is set in the ProxyIoSession session's instance to signal that handshake failed.
        Specified by:
        exceptionCaught in interface IoFilter
        Overrides:
        exceptionCaught in class IoFilterAdapter
        Parameters:
        nextFilter - next filter in the filter chain
        session - the MINA session
        cause - the original exception
        Throws:
        java.lang.Exception - If an error occurred while processing the event
      • filterWrite

        public void filterWrite​(IoFilter.NextFilter nextFilter,
                                IoSession session,
                                WriteRequest writeRequest)
        Filters outgoing writes, queueing them up if necessary while a handshake is ongoing.
        Specified by:
        filterWrite in interface IoFilter
        Overrides:
        filterWrite in class IoFilterAdapter
        Parameters:
        nextFilter - the next filter in filter chain
        session - the session object
        writeRequest - the data to write
      • writeData

        public void writeData​(IoFilter.NextFilter nextFilter,
                              IoSession session,
                              WriteRequest writeRequest,
                              boolean isHandshakeData)
        Actually write data. Queues the data up unless it relates to the handshake or the handshake is done.
        Parameters:
        nextFilter - the next filter in filter chain
        session - the session object
        writeRequest - the data to write
        isHandshakeData - true if writeRequest is written by the proxy classes.
      • messageSent

        public void messageSent​(IoFilter.NextFilter nextFilter,
                                IoSession session,
                                WriteRequest writeRequest)
                         throws java.lang.Exception
        Filter handshake related messages from reaching the messageSent callbacks of downstream filters.
        Specified by:
        messageSent in interface IoFilter
        Overrides:
        messageSent in class IoFilterAdapter
        Parameters:
        nextFilter - the next filter in filter chain
        session - the session object
        writeRequest - the data written
        Throws:
        java.lang.Exception - If an error occurred while processing the event
      • sessionCreated

        public void sessionCreated​(IoFilter.NextFilter nextFilter,
                                   IoSession session)
                            throws java.lang.Exception
        Called when the session is created. Will create the handler able to handle the ProxyIoSession.getRequest() request stored in the session. Event is stored in an IoSessionEventQueue for later delivery to the next filter in the chain when the handshake would have succeed. This will prevent the rest of the filter chain from being affected by this filter internals. Please note that this event can occur multiple times because of some http proxies not handling keep-alive connections thus needing multiple sessions during the handshake.
        Specified by:
        sessionCreated in interface IoFilter
        Overrides:
        sessionCreated in class IoFilterAdapter
        Parameters:
        nextFilter - the next filter in filter chain
        session - the session object
        Throws:
        java.lang.Exception - If an error occurred while processing the event
      • sessionOpened

        public void sessionOpened​(IoFilter.NextFilter nextFilter,
                                  IoSession session)
                           throws java.lang.Exception
        Event is stored in an IoSessionEventQueue for later delivery to the next filter in the chain when the handshake would have succeed. This will prevent the rest of the filter chain from being affected by this filter internals.
        Specified by:
        sessionOpened in interface IoFilter
        Overrides:
        sessionOpened in class IoFilterAdapter
        Parameters:
        nextFilter - the next filter in filter chain
        session - the session object
        Throws:
        java.lang.Exception - If an error occurred while processing the event
      • sessionIdle

        public void sessionIdle​(IoFilter.NextFilter nextFilter,
                                IoSession session,
                                IdleStatus status)
                         throws java.lang.Exception
        Event is stored in an IoSessionEventQueue for later delivery to the next filter in the chain when the handshake would have succeed. This will prevent the rest of the filter chain from being affected by this filter internals.
        Specified by:
        sessionIdle in interface IoFilter
        Overrides:
        sessionIdle in class IoFilterAdapter
        Parameters:
        nextFilter - the next filter in filter chain
        session - the session object
        status - The IdleStatus type
        Throws:
        java.lang.Exception - If an error occurred while processing the event
      • sessionClosed

        public void sessionClosed​(IoFilter.NextFilter nextFilter,
                                  IoSession session)
                           throws java.lang.Exception
        Event is stored in an IoSessionEventQueue for later delivery to the next filter in the chain when the handshake would have succeed. This will prevent the rest of the filter chain from being affected by this filter internals.
        Specified by:
        sessionClosed in interface IoFilter
        Overrides:
        sessionClosed in class IoFilterAdapter
        Parameters:
        nextFilter - the next filter in filter chain
        session - the session object
        Throws:
        java.lang.Exception - If an error occurred while processing the event