/** *Updatethecurrenterrorstatetothenewerrorstateifthenewerrorstateismoreseverethanthecurrent *errorstate. * *@paramerrorStateTheerrorstatusdetails *@paramtTheerrorwhichoccurred
*/
@SuppressWarnings("deprecation") protectedvoid setErrorState(ErrorState errorState, Throwable t) { if (getLog().isDebugEnabled()) {
getLog().debug(sm.getString("abstractProcessor.setErrorState", errorState), t);
} // Use the return value to avoid processing more than one async error // in a single async cycle.
response.setError(); boolean blockIo = this.errorState.isIoAllowed() && !errorState.isIoAllowed(); this.errorState = this.errorState.getMostSevere(errorState); // Don't change the status code for IOException since that is almost // certainly a client disconnect in which case it is preferable to keep // the original status code http://markmail.org/message/4cxpwmxhtgnrwh7n if (response.getStatus() < 400 && !(t instanceof IOException)) {
response.setStatus(500);
} if (t != null) {
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
} if (blockIo && isAsync()) { if (asyncStateMachine.asyncError()) {
processSocketEvent(SocketEvent.ERROR, true);
}
}
}
if (status == SocketEvent.OPEN_WRITE && response.getWriteListener() != null) {
asyncStateMachine.asyncOperation(); try { if (flushBufferedWrite()) { return SocketState.LONG;
}
} catch (IOException ioe) { if (getLog().isDebugEnabled()) {
getLog().debug("Unable to write async data.", ioe);
}
status = SocketEvent.ERROR;
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, ioe);
}
} elseif (status == SocketEvent.OPEN_READ && request.getReadListener() != null) {
dispatchNonBlockingRead();
} elseif (status == SocketEvent.ERROR) { // An I/O error occurred on a non-container thread. This includes: // - read/write timeouts fired by the Poller in NIO // - completion handler failures in NIO2
if (request.getAttribute(RequestDispatcher.ERROR_EXCEPTION) == null) { // Because the error did not occur on a container thread the // request's error attribute has not been set. If an exception // is available from the socketWrapper, use it to set the // request's error attribute here so it is visible to the error // handling.
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, socketWrapper.getError());
}
if (request.getReadListener() != null || response.getWriteListener() != null) { // The error occurred during non-blocking I/O. Set the correct // state else the error handling will trigger an ISE.
asyncStateMachine.asyncOperation();
}
}
if (getErrorState().isError()) {
request.updateCounters();
state = SocketState.CLOSED;
} elseif (isAsync()) {
state = SocketState.LONG;
} else {
request.updateCounters();
state = dispatchEndRequest();
}
if (getLog().isDebugEnabled()) {
getLog().debug("Socket: [" + socketWrapper + "], Status in: [" + status + "], State out: [" + state + "]");
}
return state;
}
protectedvoid parseHost(MessageBytes valueMB) { if (valueMB == null || valueMB.isNull()) {
populateHost();
populatePort(); return;
} elseif (valueMB.getLength() == 0) { // Empty Host header so set sever name to empty string
request.serverName().setString("");
populatePort(); return;
}
ByteChunk valueBC = valueMB.getByteChunk(); byte[] valueB = valueBC.getBytes(); int valueL = valueBC.getLength(); int valueS = valueBC.getStart(); if (hostNameC.length < valueL) {
hostNameC = newchar[valueL];
}
try { // Validates the host name int colonPos = Host.parse(valueMB);
// Extract the port information first, if any if (colonPos != -1) { int port = 0; for (int i = colonPos + 1; i < valueL; i++) { char c = (char) valueB[i + valueS]; if (c < '0' || c > '9') {
response.setStatus(400);
setErrorState(ErrorState.CLOSE_CLEAN, null); return;
}
port = port * 10 + c - '0';
}
request.setServerPort(port);
// Only need to copy the host name up to the :
valueL = colonPos;
}
// Extract the host name for (int i = 0; i < valueL; i++) {
hostNameC[i] = (char) valueB[i + valueS];
}
request.serverName().setChars(hostNameC, 0, valueL);
} catch (IllegalArgumentException e) { // IllegalArgumentException indicates that the host name is invalid
UserDataHelper.Mode logMode = userDataHelper.getNextMode(); if (logMode != null) {
String message = sm.getString("abstractProcessor.hostInvalid", valueMB.toString()); switch (logMode) { case INFO_THEN_DEBUG:
message += sm.getString("abstractProcessor.fallToDebug"); //$FALL-THROUGH$ case INFO:
getLog().info(message, e); break; case DEBUG:
getLog().debug(message, e);
}
}
@Override publicfinalvoid action(ActionCode actionCode, Object param) { switch (actionCode) { // 'Normal' servlet support case COMMIT: { if (!response.isCommitted()) { try { // Validate and write response headers
prepareResponse();
} catch (IOException e) {
handleIOException(e);
}
} break;
} case CLOSE: {
action(ActionCode.COMMIT, null); try {
finishResponse();
} catch (IOException e) {
handleIOException(e);
} break;
} case ACK: {
ack((ContinueResponseTiming) param); break;
} case CLIENT_FLUSH: {
action(ActionCode.COMMIT, null); try {
flush();
} catch (IOException e) {
handleIOException(e);
response.setErrorException(e);
} break;
} case AVAILABLE: {
request.setAvailable(available(Boolean.TRUE.equals(param))); break;
} case REQ_SET_BODY_REPLAY: {
ByteChunk body = (ByteChunk) param;
setRequestBody(body); break;
}
// Error handling case IS_ERROR: {
((AtomicBoolean) param).set(getErrorState().isError()); break;
} case IS_IO_ALLOWED: {
((AtomicBoolean) param).set(getErrorState().isIoAllowed()); break;
} case CLOSE_NOW: { // Prevent further writes to the response
setSwallowResponse(); if (param instanceof Throwable) {
setErrorState(ErrorState.CLOSE_NOW, (Throwable) param);
} else {
setErrorState(ErrorState.CLOSE_NOW, null);
} break;
} case DISABLE_SWALLOW_INPUT: { // Cancelled upload or similar. // No point reading the remainder of the request.
disableSwallowRequest(); // This is an error state. Make sure it is marked as such.
setErrorState(ErrorState.CLOSE_CLEAN, null); break;
}
// Request attribute support case REQ_HOST_ADDR_ATTRIBUTE: { if (getPopulateRequestAttributesFromSocket() && socketWrapper != null) {
request.remoteAddr().setString(socketWrapper.getRemoteAddr());
} break;
} case REQ_PEER_ADDR_ATTRIBUTE: { if (getPopulateRequestAttributesFromSocket() && socketWrapper != null) {
request.peerAddr().setString(socketWrapper.getRemoteAddr());
} break;
} case REQ_HOST_ATTRIBUTE: {
populateRequestAttributeRemoteHost(); break;
} case REQ_LOCALPORT_ATTRIBUTE: { if (getPopulateRequestAttributesFromSocket() && socketWrapper != null) {
request.setLocalPort(socketWrapper.getLocalPort());
} break;
} case REQ_LOCAL_ADDR_ATTRIBUTE: { if (getPopulateRequestAttributesFromSocket() && socketWrapper != null) {
request.localAddr().setString(socketWrapper.getLocalAddr());
} break;
} case REQ_LOCAL_NAME_ATTRIBUTE: { if (getPopulateRequestAttributesFromSocket() && socketWrapper != null) {
request.localName().setString(socketWrapper.getLocalName());
} break;
} case REQ_REMOTEPORT_ATTRIBUTE: { if (getPopulateRequestAttributesFromSocket() && socketWrapper != null) {
request.setRemotePort(socketWrapper.getRemotePort());
} break;
}
// SSL request attribute support case REQ_SSL_ATTRIBUTE: {
populateSslRequestAttributes(); break;
} case REQ_SSL_CERTIFICATE: { try {
sslReHandShake();
} catch (IOException ioe) {
setErrorState(ErrorState.CLOSE_CONNECTION_NOW, ioe);
} break;
}
// Servlet 3.0 asynchronous support case ASYNC_START: {
asyncStateMachine.asyncStart((AsyncContextCallback) param); break;
} case ASYNC_COMPLETE: {
clearDispatches(); if (asyncStateMachine.asyncComplete()) {
processSocketEvent(SocketEvent.OPEN_READ, true);
} break;
} case ASYNC_DISPATCH: { if (asyncStateMachine.asyncDispatch()) {
processSocketEvent(SocketEvent.OPEN_READ, true);
} break;
} case ASYNC_DISPATCHED: {
asyncStateMachine.asyncDispatched(); break;
} case ASYNC_ERROR: {
asyncStateMachine.asyncError(); break;
} case ASYNC_IS_ASYNC: {
((AtomicBoolean) param).set(asyncStateMachine.isAsync()); break;
} case ASYNC_IS_COMPLETING: {
((AtomicBoolean) param).set(asyncStateMachine.isCompleting()); break;
} case ASYNC_IS_DISPATCHING: {
((AtomicBoolean) param).set(asyncStateMachine.isAsyncDispatching()); break;
} case ASYNC_IS_ERROR: {
((AtomicBoolean) param).set(asyncStateMachine.isAsyncError()); break;
} case ASYNC_IS_STARTED: {
((AtomicBoolean) param).set(asyncStateMachine.isAsyncStarted()); break;
} case ASYNC_IS_TIMINGOUT: {
((AtomicBoolean) param).set(asyncStateMachine.isAsyncTimingOut()); break;
} case ASYNC_RUN: {
asyncStateMachine.asyncRun((Runnable) param); break;
} case ASYNC_SETTIMEOUT: { if (param == null) { return;
} long timeout = ((Long) param).longValue();
setAsyncTimeout(timeout); break;
} case ASYNC_TIMEOUT: {
AtomicBoolean result = (AtomicBoolean) param;
result.set(asyncStateMachine.asyncTimeout()); break;
} case ASYNC_POST_PROCESS: {
asyncStateMachine.asyncPostProcess(); break;
}
// Servlet 3.1 non-blocking I/O case REQUEST_BODY_FULLY_READ: {
AtomicBoolean result = (AtomicBoolean) param;
result.set(isRequestBodyFullyRead()); break;
} case NB_READ_INTEREST: {
AtomicBoolean isReady = (AtomicBoolean) param;
isReady.set(isReadyForRead()); break;
} case NB_WRITE_INTEREST: {
AtomicBoolean isReady = (AtomicBoolean) param;
isReady.set(isReadyForWrite()); break;
} case DISPATCH_READ: {
addDispatch(DispatchType.NON_BLOCKING_READ); break;
} case DISPATCH_WRITE: {
addDispatch(DispatchType.NON_BLOCKING_WRITE); break;
} case DISPATCH_EXECUTE: {
executeDispatches(); break;
}
// Servlet 4.0 Push requests case IS_PUSH_SUPPORTED: {
AtomicBoolean result = (AtomicBoolean) param;
result.set(isPushSupported()); break;
} case PUSH_REQUEST: {
doPush((Request) param); break;
}
// Servlet 4.0 Trailers case IS_TRAILER_FIELDS_READY: {
AtomicBoolean result = (AtomicBoolean) param;
result.set(isTrailerFieldsReady()); break;
} case IS_TRAILER_FIELDS_SUPPORTED: {
AtomicBoolean result = (AtomicBoolean) param;
result.set(isTrailerFieldsSupported()); break;
}
// Identifiers case PROTOCOL_REQUEST_ID: {
@SuppressWarnings("unchecked")
AtomicReference<Object> result = (AtomicReference<Object>) param;
result.set(getProtocolRequestId()); break;
} case SERVLET_CONNECTION: {
@SuppressWarnings("unchecked")
AtomicReference<Object> result = (AtomicReference<Object>) param;
result.set(getServletConnection()); break;
}
}
}
privatevoid handleIOException(IOException ioe) { if (ioe instanceof CloseNowException) { // Close the channel but keep the connection open
setErrorState(ErrorState.CLOSE_NOW, ioe);
} else { // Close the connection and all channels within that connection
setErrorState(ErrorState.CLOSE_CONNECTION_NOW, ioe);
}
}
/** *{@inheritDoc}ProcessorsthatimplementHTTPupgrademustoverridethismethodandprovidethenecessarytoken.
*/
@Override public UpgradeToken getUpgradeToken() { // Should never reach this code but in case we do... thrownew IllegalStateException(sm.getString("abstractProcessor.httpupgrade.notsupported"));
}
/** *ProcessanHTTPupgrade.ProcessorsthatsupportHTTPupgradeshouldoverridethismethodandprocessthe *providedtoken. * *@paramupgradeTokenContainsalltheinformationnecessaryfortheProcessortoprocesstheupgrade * *@throwsUnsupportedOperationExceptioniftheprotocoldoesnotsupportHTTPupgrade
*/ protectedvoid doHttpUpgrade(UpgradeToken upgradeToken) { // Should never happen thrownew UnsupportedOperationException(sm.getString("abstractProcessor.httpupgrade.notsupported"));
}
/** *{@inheritDoc}ProcessorsthatimplementHTTPupgrademustoverridethismethod.
*/
@Override public ByteBuffer getLeftoverInput() { // Should never reach this code but in case we do... thrownew IllegalStateException(sm.getString("abstractProcessor.httpupgrade.notsupported"));
}
@SuppressWarnings("deprecation")
@Override protectedfinalvoid logAccess(SocketWrapperBase<?> socketWrapper) throws IOException { // Set the socket wrapper so the access log can read the socket related // information (e.g. client IP)
setSocketWrapper(socketWrapper); // Setup the minimal request information
request.setStartTimeNanos(System.nanoTime()); // Setup the minimal response information
response.setStatus(400);
response.setError();
getAdapter().log(request, response, 0);
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.22 Sekunden
(vorverarbeitet am 2026-09-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.