// close
success = false;
Throwable t = (Throwable)req.getAttribute(
RequestDispatcher.ERROR_EXCEPTION);
req.getAttributes().remove(RequestDispatcher.ERROR_EXCEPTION);
ReadListener readListener = req.getReadListener();
if (readListener != null) {
ClassLoader oldCL = null;
try {
oldCL = request.getContext().bind(false, null);
readListener.onError(t);
} finally {
request.getContext().unbind(false, oldCL);
}
}
if (t != null) {
asyncConImpl.setErrorState(t, true);
}
} else if (status==SocketStatus.ASYNC_WRITE_ERROR) {
// A async write error is an IO error which means the socket
// needs to be closed so set success to false to trigger a
// close
success = false;
Throwable t = (Throwable)req.getAttribute(
RequestDispatcher.ERROR_EXCEPTION);
req.getAttributes().remove(RequestDispatcher.ERROR_EXCEPTION);
if (res.getWriteListener() != null) {
ClassLoader oldCL = null;
try {
oldCL = request.getContext().bind(false, null);
res.getWriteListener().onError(t);
} finally {
request.getContext().unbind(false, oldCL);
}
}
if (t != null) {
asyncConImpl.setErrorState(t, true);
}
}
// Check to see if non-blocking writes or reads are being used
if (!request.isAsyncDispatching() && request.isAsync()) {
WriteListener writeListener = res.getWriteListener();
ReadListener readListener = req.getReadListener();
if (writeListener != null && status == SocketStatus.OPEN_WRITE) {
ClassLoader oldCL = null;
try {
oldCL = request.getContext().bind(false, null);
res.onWritePossible();
if (request.isFinished() && req.sendAllDataReadEvent() &&
readListener != null) {
readListener.onAllDataRead();
}
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
writeListener.onError(t);
throw t;
} finally {
request.getContext().unbind(false, oldCL);
}
success = true;
} else if (readListener != null && status == SocketStatus.OPEN_READ) {
ClassLoader oldCL = null;
try {
oldCL = request.getContext().bind(false, null);
// If data is being read on a non-container thread a
// dispatch with status OPEN_READ will be used to get
// execution back on a container thread for the
// onAllDataRead() event. Therefore, make sure
// onDataAvailable() is not called in this case.
if (!request.isFinished()) {
readListener.onDataAvailable();
}
if (request.isFinished() && req.sendAllDataReadEvent()) {
readListener.onAllDataRead();
}
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
readListener.onError(t);
throw t;
} finally {
request.getContext().unbind(false, oldCL);
}
success = true;