Hi Stefan,

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

Hi,

I am working on programming an ICAP-server (a HTTP-like protocol). So
far I just adapted the HTTP codec example. I created IcapRequestDecoder,
IcapResponseEncoder and ServerHandler (just like the HTTP example).


Sounds cool!

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());
}

I've never thought about using MessageDecoderResult.NOT_OK, but using
ProtocolDecoderException is better IMHO.  It sounds interesting though.

HTH,
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