You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Andre de C. Rodrigues" <an...@gmail.com> on 2007/05/23 21:13:51 UTC

Help creating a filter

I'm having some trouble creating a filter.

I need a filter that reads the content of the first received message
for authentication purposes. I'm trying to do something like the
EchoProtocolHandler does for reading the message:

        ByteBuffer rb = ( ByteBuffer ) message;
        // Write the received data back to remote peer
        ByteBuffer wb = ByteBuffer.allocate( rb.remaining() );
        wb.put( rb );
        wb.flip();
        ...


Now, this code works fine in a handler class (extends
IoHandlerAdapter)... and in my conception, it should work when placed
in the messageReceived method of a filter (extends LoggingFilter)
aswell. The thing is that it doesn't.

I'm having an exception thrown at me because of the        ByteBuffer
rb = ( ByteBuffer ) message;      line :

org.apache.mina.filter.SSLFilter$SSLFilterMessage cannot be cast to
org.apache.mina.common.ByteBuffer
	at org.apache.mina.example.echoserver.LogbackFilter.messageReceived(LogbackFilter.java:66)



Well, to put things short, the line ByteBuffer rb = ( ByteBuffer )
message; doesn't seem to work in a filter. Does anybody know why this
exception is being thrown and what I can do to fix/work around it?

Thanks in advance,
André

Re: Help creating a filter

Posted by Niklas Therning <ni...@trillian.se>.
Andre de C. Rodrigues wrote:
> I'm having some trouble creating a filter.
>
> I need a filter that reads the content of the first received message
> for authentication purposes. I'm trying to do something like the
> EchoProtocolHandler does for reading the message:
>
>        ByteBuffer rb = ( ByteBuffer ) message;
>        // Write the received data back to remote peer
>        ByteBuffer wb = ByteBuffer.allocate( rb.remaining() );
>        wb.put( rb );
>        wb.flip();
>        ...
>
>
> Now, this code works fine in a handler class (extends
> IoHandlerAdapter)... and in my conception, it should work when placed
> in the messageReceived method of a filter (extends LoggingFilter)
> aswell. The thing is that it doesn't.
>
> I'm having an exception thrown at me because of the        ByteBuffer
> rb = ( ByteBuffer ) message;      line :
>
> org.apache.mina.filter.SSLFilter$SSLFilterMessage cannot be cast to
> org.apache.mina.common.ByteBuffer
>     at
> org.apache.mina.example.echoserver.LogbackFilter.messageReceived(LogbackFilter.java:66)
>
>
>
>
> Well, to put things short, the line ByteBuffer rb = ( ByteBuffer )
> message; doesn't seem to work in a filter. Does anybody know why this
> exception is being thrown and what I can do to fix/work around it?
>
> Thanks in advance,
> André
>
The SSLFilterMessage is a special kind of message emitted by the
SSLFilter when a connection has been secured or becomes unsecure. The
message will only be sent by the SSLFilter if the
SSLFilter.USE_NOTIFICATION attribute has been put in the session. This
should be off by default. Seems like you've enabled that? Have a look at
the Javadoc for SSLFilter for more info.

If you want to use USE_NOTIFICATION you need to check in your filter
whether the message is instanceof SSLFilterMessage before you cast it to
ByteBuffer.

-- 
Niklas Therning
www.spamdrain.net