Return-Path: Delivered-To: apmail-mina-users-archive@www.apache.org Received: (qmail 66263 invoked from network); 7 Aug 2009 16:44:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 7 Aug 2009 16:44:21 -0000 Received: (qmail 4621 invoked by uid 500); 7 Aug 2009 16:44:28 -0000 Delivered-To: apmail-mina-users-archive@mina.apache.org Received: (qmail 4579 invoked by uid 500); 7 Aug 2009 16:44:28 -0000 Mailing-List: contact users-help@mina.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@mina.apache.org Delivered-To: mailing list users@mina.apache.org Received: (qmail 4569 invoked by uid 99); 7 Aug 2009 16:44:28 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Aug 2009 16:44:28 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of pdcvgmh@gmail.com designates 209.85.211.186 as permitted sender) Received: from [209.85.211.186] (HELO mail-yw0-f186.google.com) (209.85.211.186) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Aug 2009 16:44:18 +0000 Received: by ywh16 with SMTP id 16so2484169ywh.24 for ; Fri, 07 Aug 2009 09:43:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=uHBaVIycvfmixTy/Hqgrqe1QwU7qEVsAa3/ZMEv8FCE=; b=pN8IMCIg7xltpfldX7PjKg/dvFA3h1D4lezPoKhTD2L0Jb8i2PAG/bsm6X0C9G5hUT JqyitOCR1q1qwpWwRDoK+4KrsYwdxD0AVEkLZaOvvVo9WU9mhFRbyS67md0aYZbBtzic IEJ/oTcZz6gFwds6QOUHaj3vxDBaOCeQN56Lo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=JHxxMd7kT8L7gmE468xvqFOIrdCPyz4NAas4mS2B2df00kRlHXy5vMmDJaGTKimqW4 aOtxaI78pQZgqi29MY56AvUbNlcMT5+w+/rFbwLPynMk6/JIQucsObMfRmPKKOIGc7Ge MVtNZf6cVRz4oU17FB9OA99NRv83xU3+w64b0= MIME-Version: 1.0 Received: by 10.100.178.2 with SMTP id a2mr586519anf.95.1249663437834; Fri, 07 Aug 2009 09:43:57 -0700 (PDT) In-Reply-To: References: Date: Fri, 7 Aug 2009 13:43:57 -0300 Message-ID: Subject: Re: CumulativeProtocolDecoder problem [MINA Version 2.0.0-M6] From: pablo caballero To: users@mina.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org 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 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 wrot= e: >> 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 { >> >> =A0 =A0 =A0 =A0private static final int MAX_MESSAGE_SIZE =3D 4196; >> =A0 =A0 =A0 =A0private Log logger =3D LogFactory.getLog(TandemProtocolDe= coder.class); >> >> =A0 =A0 =A0 =A0private ISOPackager isoPackager; >> >> =A0 =A0 =A0 =A0public TandemProtocolDecoder(ISOPackager isoPackager) { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0super(); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0this.isoPackager =3D isoPackager; >> =A0 =A0 =A0 =A0} >> >> =A0 =A0 =A0 =A0public ISOPackager getIsoPackager() { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return isoPackager; >> =A0 =A0 =A0 =A0} >> >> =A0 =A0 =A0 =A0public void setIsoPackager(ISOPackager isoPackager) { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0this.isoPackager =3D isoPackager; >> =A0 =A0 =A0 =A0} >> >> =A0 =A0 =A0 =A0public TandemProtocolDecoder() { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0super(); >> =A0 =A0 =A0 =A0} >> >> =A0 =A0 =A0 =A0@Override >> =A0 =A0 =A0 =A0protected boolean doDecode(IoSession session, IoBuffer in= , >> ProtocolDecoderOutput out) throws Exception { >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0String s =3D new String( in.array() ); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logger.debug("Choclo:" + s =A0); >> >> =A0 =A0 =A0 =A0 =A0 =A0if (in.prefixedDataAvailable(2, MAX_MESSAGE_SIZE)= ) { >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0int length =3D in.getUnsi= gnedShort(); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0byte[] bytes =3D new byte= [length]; >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0in.get(bytes); >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ISOMsg isoMsg =3D new ISO= Msg(); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0isoMsg.setPackager( isoPa= ckager ); >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0//TODO Si no puede realiz= ar el unpack lanza ISOException y entra >> por exceptionCaught del conector >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0//Ver somo manejarlo >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0isoMsg.unpack( bytes ); >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0out.write(isoMsg); >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return true; >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} >> =A0 =A0 =A0 =A0 =A0 =A0else{ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return false; >> =A0 =A0 =A0 =A0 =A0 =A0} >> =A0 =A0 =A0 =A0} >> >> } >> >> 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 appli= cation: >> * 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 =3D 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, =A0is >>> 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 >> >