Package org.apache.mina.proxy.filter
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 - ProxyIoFilter
. Automatically inserted into theIoFilter
chain byProxyConnector
. 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
Constructors Constructor Description ProxyFilter()
Create a newProxyFilter
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 anIoSessionEventQueue
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 anIoSessionEventQueue
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 anIoSessionEventQueue
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, inputClosed, onPostAdd, onPostRemove, toString
-
-
-
-
Constructor Detail
-
ProxyFilter
public ProxyFilter()
Create a newProxyFilter
.
-
-
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 anProxyFilter
instance.- Specified by:
onPreAdd
in interfaceIoFilter
- Overrides:
onPreAdd
in classIoFilterAdapter
- Parameters:
chain
- the filter chainname
- the name assigned to this filternextFilter
- the next filter- Throws:
IllegalStateException
- if chain already contains an instance ofProxyFilter
-
onPreRemove
public void onPreRemove(IoFilterChain chain, String name, IoFilter.NextFilter nextFilter)
Called when the filter is removed from the filter chain. Cleans theProxyIoSession
instance from the session.- Specified by:
onPreRemove
in interfaceIoFilter
- Overrides:
onPreRemove
in classIoFilterAdapter
- Parameters:
chain
- the filter chainname
- the name assigned to this filternextFilter
- 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 theProxyIoSession
session's instance to signal that handshake failed.- Specified by:
exceptionCaught
in interfaceIoFilter
- Overrides:
exceptionCaught
in classIoFilterAdapter
- Parameters:
nextFilter
- next filter in the filter chainsession
- the MINA sessioncause
- the original exception- Throws:
Exception
- If an error occurred while processing the event
-
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 interfaceIoFilter
- Overrides:
messageReceived
in classIoFilterAdapter
- Parameters:
nextFilter
- the next filter in filter chainsession
- the session objectmessage
- 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 interfaceIoFilter
- Overrides:
filterWrite
in classIoFilterAdapter
- Parameters:
nextFilter
- the next filter in filter chainsession
- the session objectwriteRequest
- 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 chainsession
- the session objectwriteRequest
- the data to writeisHandshakeData
- 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 interfaceIoFilter
- Overrides:
messageSent
in classIoFilterAdapter
- Parameters:
nextFilter
- the next filter in filter chainsession
- the session objectwriteRequest
- 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 theProxyIoSession.getRequest()
request stored in the session. Event is stored in anIoSessionEventQueue
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 interfaceIoFilter
- Overrides:
sessionCreated
in classIoFilterAdapter
- Parameters:
nextFilter
- the next filter in filter chainsession
- 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 anIoSessionEventQueue
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 interfaceIoFilter
- Overrides:
sessionOpened
in classIoFilterAdapter
- Parameters:
nextFilter
- the next filter in filter chainsession
- 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 anIoSessionEventQueue
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 interfaceIoFilter
- Overrides:
sessionIdle
in classIoFilterAdapter
- Parameters:
nextFilter
- the next filter in filter chainsession
- the session objectstatus
- TheIdleStatus
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 anIoSessionEventQueue
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 interfaceIoFilter
- Overrides:
sessionClosed
in classIoFilterAdapter
- Parameters:
nextFilter
- the next filter in filter chainsession
- the session object- Throws:
Exception
- If an error occurred while processing the event
-
-