In our method
_org.apache.http.nio.protocol.HttpAsyncService.exception(NHttpServerConnection,
Exception)_ the log() method does not always get called:
@Override
public void exception(
final NHttpServerConnection conn, final Exception cause) {
final State state = getState(conn);
if (state == null) {
shutdownConnection(conn);
log(cause);
return;
}
state.setTerminated();
closeHandlers(state, cause);
final Cancellable cancellable = state.getCancellable();
if (cancellable != null) {
cancellable.cancel();
}
final Queue<PipelineEntry> pipeline = state.getPipeline();
if (!pipeline.isEmpty()
|| conn.isResponseSubmitted()
|| state.getResponseState().compareTo(MessageState.INIT) >
0) {
// There is not much that we can do if a response
// has already been submitted or pipelining is being used.
shutdownConnection(conn);
} else {
try {
final Incoming incoming = state.getIncoming();
final HttpRequest request = incoming != null ?
incoming.getRequest() : null;
final HttpContext context = incoming != null ?
incoming.getContext() : new BasicHttpContext();
final HttpAsyncResponseProducer responseProducer =
handleException(cause, context);
final HttpResponse response =
responseProducer.generateResponse();
final Outgoing outgoing = new Outgoing(request, response,
responseProducer, context);
state.setResponseState(MessageState.INIT);
state.setOutgoing(outgoing);
commitFinalResponse(conn, state);
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
// log() has not been called by the time we get here
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
} catch (final Exception ex) {
shutdownConnection(conn);
closeHandlers(state);
if (ex instanceof RuntimeException) {
throw (RuntimeException) ex;
} else {
log(ex);
}
}
}
}
So I propose we move the call to log from:
if (state == null) {
shutdownConnection(conn);
log(cause);
return;
}
To the first line of the method:
@Override
public void exception(
final NHttpServerConnection conn, final Exception cause) {
log(cause);
final State state = getState(conn);
if (state == null) {
shutdownConnection(conn);
return;
}
Thoughts?
Gary
--
E-Mail: [email protected] | [email protected]
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory