On 10/28/10 1:34 PM, Björn Thelberg wrote:
Hello
Hi,
I am writing a client implementation for a binary protocol using a
ProtocolCodecFilter with a DemuxingProtocolCodecFactory and a list of
MessageDecoder's in the same way as the Mina SumUp example.
I also use a DemuxingIoHandler to handle the responses and I am in general very
pleased with how this works.
Fine !
My question is as follows.
If I for some reason get an exception in one of my MessageDecoder's
decode()-method due to a broken response of some sort, what is supposed to
happen next?
The ExceptionCaught event is generated, and you can handle it in your
handler.
What happens for me is that the exception is passed to my ExceptionHandler and
decoding of this message quits. Fine so far.
Ok, works as expected :)
But the subsequent decode operation (following a new request) is immediately
passed on to the same MessageDecoder instance's decode().
Makes sense. I guess it's on the same session.
This is of course a problem if the next response is of another type because the
chain of MessageDecoder's decodable() are never called.
Also it sometimes seems as if remaining bytes in the IoBuffer from decoding#1
(that threw Exception) are still in the buffer in decoding#2 and my decoding
crashes (again).
You may have to clenup the session when you get the exception in your
decoder, otherwise the cumulative buffer will keep the faulty data.
I interpret the Javadoc for MessageDecoder.decode() as if throwing exception
would mean roughly the same thing as returning MessageDecoderResult.NOT_OK.
Do they not both indicate a "protocol specification violation"?
It seems as throwing exception in the decode()-method acts more like returning
MessageDecoderResult.NEED_DATA.
I quess I can solve this problem by catching all exceptions in decode() and
returning MessageDecoderResult.NOT_OK but then my ExceptionHandler is never
called.
You can also try to catch the exception, clean the session, and rethrow
the initial exception ?
Let me know if it works.
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com