org.apache.mina.proxy.filter
Class ProxyFilter

java.lang.Object
  extended by org.apache.mina.core.filterchain.IoFilterAdapter
      extended by 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
Author:
Apache MINA Project

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.mina.core.filterchain.IoFilter
IoFilter.NextFilter
 
Constructor Summary
ProxyFilter()
          Create a new ProxyFilter.
 
Method Summary
 void exceptionCaught(IoFilter.NextFilter nextFilter, IoSession session, Throwable cause)
          Called when an exception occurs in the chain.
 void filterWrite(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest)
          Filters outgoing writes, queueing them up if necessary while a handshake is ongoing.
 void messageReceived(IoFilter.NextFilter nextFilter, IoSession session, Object message)
          Receives data from the remote host, passes to the handler if a handshake is in progress, otherwise passes on transparently.
 void messageSent(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest)
          Filter handshake related messages from reaching the messageSent callbacks of downstream filters.
 void onPreAdd(IoFilterChain chain, String name, IoFilter.NextFilter nextFilter)
          Called before the filter is added into the filter chain.
 void onPreRemove(IoFilterChain chain, String name, IoFilter.NextFilter nextFilter)
          Called when the filter is removed from the filter chain.
 void sessionClosed(IoFilter.NextFilter nextFilter, IoSession session)
          Event is stored in an IoSessionEventQueue for later delivery to the next filter in the chain when the handshake would have succeed.
 void sessionCreated(IoFilter.NextFilter nextFilter, IoSession session)
          Called when the session is created.
 void sessionIdle(IoFilter.NextFilter nextFilter, IoSession session, IdleStatus status)
          Event is stored in an IoSessionEventQueue for later delivery to the next filter in the chain when the handshake would have succeed.
 void sessionOpened(IoFilter.NextFilter nextFilter, IoSession session)
          Event is stored in an IoSessionEventQueue for later delivery to the next filter in the chain when the handshake would have succeed.
 void writeData(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest, boolean isHandshakeData)
          Actually write data.
 
Methods inherited from class org.apache.mina.core.filterchain.IoFilterAdapter
destroy, filterClose, init, onPostAdd, onPostRemove, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ProxyFilter

public ProxyFilter()
Create a new ProxyFilter.

Method Detail

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:
chain - the filter chain
name - the name assigned to this filter
nextFilter - the next filter
Throws:
Exception

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

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

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

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
Throws:
Exception

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


Copyright © 2004-2011 Apache MINA Project. All Rights Reserved.