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

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?


NOT_OK is for decodable().  It's not usually for decode().  We need to fix
the documentation.  Thanks for the info!

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


Very cool!

Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6

Reply via email to