Class ProxyFilter

java.lang.Object
org.apache.mina.core.filterchain.IoFilterAdapter
org.apache.mina.proxy.filter.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
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
  • Constructor Details

    • ProxyFilter

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

    • onPreAdd

      public void onPreAdd(IoFilterChain chain, 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:
      IllegalStateException - if chain already contains an instance of ProxyFilter
    • onPreRemove

      public void onPreRemove(IoFilterChain chain, String name, IoFilter.NextFilter nextFilter)
      Called when the filter is removed from the filter chain. Cleans the ProxyIoSession instance from the session.
      Specified by:
      onPreRemove in interface IoFilter
      Overrides:
      onPreRemove in class IoFilterAdapter
      Parameters:
      chain - the filter chain
      name - the name assigned to this filter
      nextFilter - the next filter
    • exceptionCaught

      public void exceptionCaught(IoFilter.NextFilter nextFilter, IoSession session, Throwable cause) throws 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:
      Exception - If an error occurred while processing the event
    • getProxyHandler

      private ProxyLogicHandler getProxyHandler(IoSession session)
      Get the ProxyLogicHandler for a given session.
      Parameters:
      session - the session object
      Returns:
      the handler which will handle handshaking with the proxy
    • messageReceived

      public void messageReceived(IoFilter.NextFilter nextFilter, IoSession session, Object message) throws ProxyAuthException
      Receives data from the remote host, passes to the handler if a handshake is in progress, otherwise passes on transparently.
      Specified by:
      messageReceived in interface IoFilter
      Overrides:
      messageReceived in class IoFilterAdapter
      Parameters:
      nextFilter - the next filter in filter chain
      session - the session object
      message - the object holding the received data
      Throws:
      ProxyAuthException
    • 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 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:
      Exception - If an error occurred while processing the event
    • sessionCreated

      public void sessionCreated(IoFilter.NextFilter nextFilter, IoSession session) throws 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:
      Exception - If an error occurred while processing the event
    • sessionOpened

      public void sessionOpened(IoFilter.NextFilter nextFilter, IoSession session) throws 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:
      Exception - If an error occurred while processing the event
    • sessionIdle

      public void sessionIdle(IoFilter.NextFilter nextFilter, IoSession session, IdleStatus status) throws 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:
      Exception - If an error occurred while processing the event
    • sessionClosed

      public void sessionClosed(IoFilter.NextFilter nextFilter, IoSession session) throws 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:
      Exception - If an error occurred while processing the event