Hi,

I am using 2 filters 
1. CompressionFilter
2. ProtocolCodecFilter

Sample code :
------------------------------------------------------------------------------------------------
    acceptor.getFilterChain().addLast("compressor", new
CompressionFilter());
    
    TextLineEncoder encoder = new
TextLineEncoder(serverConfig.getDataEncoding());
    TextLineDecoder decoder = new
TextLineDecoder(serverConfig.getDataEncoding());
    decoder.setMaxLineLength(serverConfig.getBufferSize());
    acceptor.getFilterChain().addLast("codec", new
ProtocolCodecFilter(encoder, decoder));
------------------------------------------------------------------------------------------------

Now when I send the uncompressed data, CompressionFilter tries to decompress
and throws exception.

Reason:
In the messageReceived method of CompressionFilter class, the first
condition becomes false, and then goes for inflate method which throws
exception.

------------------------------------------------------------------------------------------------
    @Override
    public void messageReceived(NextFilter nextFilter, IoSession session,
Object message) throws Exception {
        if (!compressInbound || !(message instanceof IoBuffer)) {
            nextFilter.messageReceived(session, message);
            return;
        }

        Zlib inflater = (Zlib) session.getAttribute(INFLATER);
        if (inflater == null) {
            throw new IllegalStateException();
        }

        IoBuffer inBuffer = (IoBuffer) message;
        IoBuffer outBuffer = inflater.inflate(inBuffer);
------------------------------------------------------------------------------------------------

compressInbound is true (set from the constructor)
(message instanceof IoBuffer) is also true



But if I move the CompressionFilter below ProtocolCodecFilter then (message
instanceof IoBuffer) becomes false and it returns from there, without going
for inflate method calls.



Questions:

1. Do I need to use some other constructor to create CompressionFilter as it
is always making compressInbound  true? But how do I know if the incoming
data is compressed or not, is it not handled by filter itself? If I know the
data is not compressed then I can make compressInbound  false.

2. Why the different behavior for changing the order of CompressionFilter 
and ProtocolCodecFilter ?




--
View this message in context: 
http://apache-mina.10907.n7.nabble.com/Apache-Mina-CompressionFilter-always-try-to-decompress-tp47947.html
Sent from the Apache MINA User Forum mailing list archive at Nabble.com.

Reply via email to