mina-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pablo caballero <pdcv...@gmail.com>
Subject Re: CumulativeProtocolDecoder problem [MINA Version 2.0.0-M6]
Date Fri, 07 Aug 2009 16:43:57 GMT
My mistake. I was throwing an exception from the decode method that is
not a RecoverableProtocolDecoderException subclass

On Thu, Jul 30, 2009 at 9:33 AM, pablo caballero<pdcvgmh@gmail.com> wrote:
> Correction: the malformed message is the third message.
>
> Update: If msg3 is a well formed short (~100 bytes) message everything
> works fine. I think that the exception has something to do with the
> error.
>
> Best regards
>
> On Wed, Jul 29, 2009 at 11:43 PM, pablo caballero<pdcvgmh@gmail.com> wrote:
>> Hi, I have a problem with one of my mina based applications.
>>
>> Source code where the problem manifests itself:
>>
>> import org.apache.commons.logging.Log;
>> import org.apache.commons.logging.LogFactory;
>> import org.apache.mina.core.buffer.IoBuffer;
>> import org.apache.mina.core.session.IoSession;
>> import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
>> import org.apache.mina.filter.codec.ProtocolDecoderOutput;
>> import org.jpos.iso.ISOMsg;
>> import org.jpos.iso.ISOPackager;
>>
>> public class TandemProtocolDecoder extends CumulativeProtocolDecoder {
>>
>>        private static final int MAX_MESSAGE_SIZE = 4196;
>>        private Log logger = LogFactory.getLog(TandemProtocolDecoder.class);
>>
>>        private ISOPackager isoPackager;
>>
>>        public TandemProtocolDecoder(ISOPackager isoPackager) {
>>                super();
>>                this.isoPackager = isoPackager;
>>        }
>>
>>        public ISOPackager getIsoPackager() {
>>                return isoPackager;
>>        }
>>
>>        public void setIsoPackager(ISOPackager isoPackager) {
>>                this.isoPackager = isoPackager;
>>        }
>>
>>        public TandemProtocolDecoder() {
>>                super();
>>        }
>>
>>        @Override
>>        protected boolean doDecode(IoSession session, IoBuffer in,
>> ProtocolDecoderOutput out) throws Exception {
>>
>>                String s = new String( in.array() );
>>                logger.debug("Choclo:" + s  );
>>
>>            if (in.prefixedDataAvailable(2, MAX_MESSAGE_SIZE)) {
>>
>>                        int length = in.getUnsignedShort();
>>                        byte[] bytes = new byte[length];
>>                        in.get(bytes);
>>
>>                        ISOMsg isoMsg = new ISOMsg();
>>                        isoMsg.setPackager( isoPackager );
>>
>>                        //TODO Si no puede realizar el unpack lanza ISOException
y entra
>> por exceptionCaught del conector
>>                        //Ver somo manejarlo
>>                        isoMsg.unpack( bytes );
>>
>>                        out.write(isoMsg);
>>
>>                        return true;
>>                }
>>            else{
>>                        return false;
>>            }
>>        }
>>
>> }
>>
>> Problem description:
>>
>> 1.- The application message (tcp payload) consist in two bytes
>> indicating the size of the data and the data itself.
>> 2.- I have a test application that sends five messages to the mina application:
>> * Message 1 (700 bytes - well formed)
>> * Message 2 (100 bytes - purposely malformed ISO message)
>> * Message 3 (700 bytes - well formed)
>> * Message 4 (700 bytes - well formed)
>> * Message 5 (700 bytes - well formed)
>> 3.- An IoBuffer (size = 2048) is fullfilled with msg1, msg2, msg3 and
>> a chunk of msg4
>> 4.- msg1 and msg2 are processed correctly (unpacked to a isomsg and
>> writed to the output)
>> 5.- The unpacking of msg3 throws and exception ( isoMsg.unpack( bytes
>> ) ) as expected. This exception is handled by the exceptionCaught in
>> the IoHandler
>> 6.- In the next call of the doDecode method the IoBuffer is filled
>> with rest of msg4 and msg5 (the beginning of the msg4 is lost). This
>> cause that 2 bytes of the msg4's data are considered
>> as the data size of the next message (in this case the data size,
>> wrongly deducted,  is >>> MAX_MESSAGE_SIZE and the
>> prefixedDataAvailable method throws an BufferDataException exception)
>>
>> Can someone tell me if there is an error in my code, is this the
>> expected behaviour (some workaround?) or if it is a bug?
>>
>> Thank you very much in advance
>>
>> Sorry for my bad English
>>
>> Best regards
>>
>

Mime
View raw message