HttpCore NIO: "Status Code May Not Be Negative"
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;
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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?
Thanks,
Chas