hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: HttpCore NIO: "Status Code May Not Be Negative"
Date Wed, 01 Jul 2009 20:15:45 GMT
Chas Williams wrote:
> Well, that's embarrassing ;). Thanks Oleg.
> 

It is equally embarrassing to be responsible for having designed a 
non-intuitive API ;) Boolean return values are evil. I never get them right.

I made some changes to the SVN trunk to improve handling of negative 
HTTP status codes. As of 4.1-BETA1 HttpCore will throw a checked 
ProtocolException instead of IllegalArgumentExcpetion in such a case.

Cheers

Oleg


> On Tue, Jun 30, 2009 at 3:22 PM, Oleg Kalnichevski <olegk@apache.org> wrote:
> 
>> Chas Williams wrote:
>>
>>> Hi all,
>>>
>>>     I'm having an issue with a long-running piece of web-crawling software
>>> built using the HttpCore NIO extensions. Whenever the IOReactor encounters
>>> an http server that (incorrectly) returns a negative status code, the
>>> entire
>>> IOReactor shuts down.
>>>
>>>     I've tried overriding the default exception handler, which seems to
>>> have no effect.
>>>
>>> Here's the exception (from the IOReactor's audit log):
>>>
>>> java.lang.IllegalArgumentException: Status code may not be negative.
>>>        at
>>> org.apache.http.message.BasicStatusLine.<init>(BasicStatusLine.java:74)
>>>        at
>>>
>>> org.apache.http.message.BasicLineParser.createStatusLine(BasicLineParser.java:453)
>>>        at
>>>
>>> org.apache.http.message.BasicLineParser.parseStatusLine(BasicLineParser.java:431)
>>>        at
>>>
>>> org.apache.http.impl.nio.codecs.HttpResponseParser.createMessage(HttpResponseParser.java:75)
>>>        at
>>>
>>> org.apache.http.impl.nio.codecs.AbstractMessageParser.parseHeadLine(AbstractMessageParser.java:147)
>>>        at
>>>
>>> org.apache.http.impl.nio.codecs.AbstractMessageParser.parse(AbstractMessageParser.java:196)
>>>        at
>>>
>>> org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:160)
>>>        at
>>>
>>> org.apache.http.impl.nio.DefaultClientIOEventDispatch.inputReady(DefaultClientIOEventDispatch.java:146)
>>>        at
>>>
>>> org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:153)
>>>        at
>>>
>>> org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:314)
>>>        at
>>>
>>> org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:294)
>>>        at
>>>
>>> org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:256)
>>>        at
>>>
>>> org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:96)
>>>        at
>>>
>>> org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:556)
>>>        at java.lang.Thread.run(Thread.java:619)
>>>
>>>
>>> I used the setExceptionHandler() method to override the default exception
>>> handler for my ConnectingIOReactor object, here's my implementation:
>>>
>>>
>>> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>>>
>>> public class MyIOReactorExceptionHandler implements
>>> IOReactorExceptionHandler
>>> {
>>>
>>>    public boolean handle(IOException arg0)
>>>    {
>>>        System.err.println("MyIOReactorExceptionHandler encountered
>>> IOException: " + arg0);
>>>        return true;
>>>    }
>>>
>>>    public boolean handle(RuntimeException arg0)
>>>    {
>>>        System.err.println("MyIOReactorExceptionHandler encountered
>>> RuntimeException: " + arg0);
>>>
>>>        //Ignore this one
>>>        if (arg0 instanceof IllegalArgumentException &&
>>> arg0.getMessage().contains("Status code may not be negative."))
>>>        {
>>>            System.err.println("...ignoring recoverable error: " +
>>> arg0.getMessage());
>>>            return false;
>>>        }
>>>
>>>        System.err.println("Signaling unrecoverable error...");
>>>
>>>        return true;
>>>    }
>>>
>>> }
>>>
>>>
>> Chas,
>>
>> It is the other way around. The handler should return true if it is safe to
>> ignore the exception and continue execution of the I/O reactor and if the
>> I/O reactor must re-throw RuntimeException and terminate.
>>
>> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>>> Looking my program logs, it seems like the handle(RuntimeException) method
>>> is called, and "ignoring recoverable error: ..." is printed, but the
>>> IOReactor still shuts down.
>>>
>>> What am I missing here? Is there a better way to recover from this error
>>> without shutting down the IOReactor?
>>>
>>>
>> A better solution to this problem would be a custom message parser.
>>
>> Hope this helps
>>
>> Oleg
>>
>>
>>  Thanks,
>>> Chas
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
>> For additional commands, e-mail: dev-help@hc.apache.org
>>
>>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message