Hi Trustin,

Trustin Lee schrieb:
Hi Stefan,

On 2/1/07, Stefan Bischof <[EMAIL PROTECTED]> wrote:

Now I have a question regarding errors:

Scenario:
The client sends me a message which violates the protocol. As far as I
understood, this problem should be detected in
IcapRequestDecoder.decode. Right?


Yes, you can *detect* the problem, but you could also just do what you are supposed to do (i.e. parsing the message) and let the exception arise due to
a unexpected value.  You don't need to perform every integrity check on a
received message as long as an exception can be thrown.

Once an exception is throw from a ProtocolDecoder, MINA wraps the exception
with ProtocolDecoderException, and forward it to your IoHandler's
exceptionCaught() handler method.  You can check the type of the cause
(exception) using 'instanceof' keyword:

if (cause instanceof ProtocolDecoderException) {
   Throwable causeOfCause = cause.getCause(); // what is thrown from
ProtocolDecoder
   session.write(new FourOhOhMessage());
}
Thanks! I just tried and it naturally worked (after realizing some strange eclipse behaviour, but thats another story). I just wasn't sure about the 'MINA-way' of handling protocol decoding error issues.
I've never thought about using MessageDecoderResult.NOT_OK, but using
ProtocolDecoderException is better IMHO.  It sounds interesting though.
I wasn't sure what the NOT_OK is really for. But then I found a line in the Javadoc for MessageDecoder.decode (the returns-section): "Returns: [...] NOT_OK if you cannot decode current message due to protocol specification violation.", and I thought, "hey, this is what I need". In which case would you really need NOT_OK?
HTH,
Trustin
Thanks for your help.

BTW: If you are interested, I could translate tutorials to german (when they are ready).

regards,
Stefan Bischof

Reply via email to