*/
public void process(InputStream input, OutputStream output)
throws IOException {
ThreadWithAttributes thrA=
(ThreadWithAttributes)Thread.currentThread();
RequestInfo rp = request.getRequestProcessor();
thrA.setCurrentStage(threadPool, "parsing http request");
rp.setStage(org.apache.coyote.Constants.STAGE_PARSE);
// Set the remote address
remoteAddr = null;
remoteHost = null;
localAddr = null;
localName = null;
remotePort = -1;
localPort = -1;
// Setting up the I/O
inputBuffer.setInputStream(input);
outputBuffer.setOutputStream(output);
// Error flag
error = false;
keepAlive = true;
int keepAliveLeft = maxKeepAliveRequests;
int soTimeout = socket.getSoTimeout();
int oldSoTimeout = soTimeout;
int threadRatio = 0;
if (threadPool.getCurrentThreadsBusy() > 0) {
threadRatio = (threadPool.getCurrentThreadsBusy() * 100)
/ threadPool.getMaxThreads();
} else {
threadRatio = (endpoint.getCurrentThreadsBusy() * 100)
/ endpoint.getMaxThreads();
}
if ((threadRatio > 33) && (threadRatio <= 66)) {
soTimeout = soTimeout / 2;
} else if ((threadRatio > 66) && (threadRatio <= 90)) {
soTimeout = soTimeout / 3;
keepAliveLeft = 1;
} else if (threadRatio > 90) {
soTimeout = soTimeout / 20;
keepAliveLeft = 1;
}
if (soTimeout != oldSoTimeout) {
try {
socket.setSoTimeout(soTimeout);
} catch (Throwable t) {
log.debug(sm.getString("http11processor.socket.timeout"), t);
error = true;
}
}
boolean keptAlive = false;
while (started && !error && keepAlive) {
// Parsing the request header
try {
if( !disableUploadTimeout && keptAlive && soTimeout > 0 ) {
socket.setSoTimeout(soTimeout);
}
inputBuffer.parseRequestLine();
request.setStartTime(System.currentTimeMillis());
thrA.setParam( threadPool, request.requestURI() );
keptAlive = true;
if (!disableUploadTimeout) {
socket.setSoTimeout(timeout);
}
inputBuffer.parseHeaders();
} catch (IOException e) {
error = true;
break;
} catch (Throwable t) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("http11processor.header.parse"), t);
}
// 400 - Bad Request
response.setStatus(400);
error = true;
}
// Setting up filters, and parse some request headers
thrA.setCurrentStage(threadPool, "prepareRequest");
rp.setStage(org.apache.coyote.Constants.STAGE_PREPARE);
try {
prepareRequest();
} catch (Throwable t) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("http11processor.request.prepare"), t);
}
// 400 - Internal Server Error
response.setStatus(400);
error = true;
}
if (maxKeepAliveRequests > 0 && --keepAliveLeft == 0)
keepAlive = false;
// Process the request in the adapter
if (!error) {
try {
thrA.setCurrentStage(threadPool, "service");
rp.setStage(org.apache.coyote.Constants.STAGE_SERVICE);
adapter.service(request, response);
// Handle when the response was committed before a serious
// error occurred. Throwing a ServletException should both
// set the status to 500 and set the errorException.
// If we fail here, then the response is likely already
// committed, so we can't try and set headers.
if(keepAlive && !error) { // Avoid checking twice.
error = response.getErrorException() != null ||
statusDropsConnection(response.getStatus());
}
} catch (InterruptedIOException e) {
error = true;
} catch (Throwable t) {
log.error(sm.getString("http11processor.request.process"), t);
// 500 - Internal Server Error
response.setStatus(500);
error = true;
}
}
// Finish the handling of the request
try {
thrA.setCurrentStage(threadPool, "endRequestIB");
rp.setStage(org.apache.coyote.Constants.STAGE_ENDINPUT);
inputBuffer.endRequest();
} catch (IOException e) {
error = true;
} catch (Throwable t) {
log.error(sm.getString("http11processor.request.finish"), t);
// 500 - Internal Server Error
response.setStatus(500);
error = true;
}
try {
thrA.setCurrentStage(threadPool, "endRequestOB");
rp.setStage(org.apache.coyote.Constants.STAGE_ENDOUTPUT);
outputBuffer.endRequest();
} catch (IOException e) {
error = true;
} catch (Throwable t) {
log.error(sm.getString("http11processor.response.finish"), t);
error = true;
}
// If there was an error, make sure the request is counted as
// and error, and update the statistics counter
if (error) {
response.setStatus(500);
}
request.updateCounters();
thrA.setCurrentStage(threadPool, "ended");
rp.setStage(org.apache.coyote.Constants.STAGE_KEEPALIVE);
// Don't reset the param - we'll see it as ended. Next request
// will reset it
// thrA.setParam(null);
// Next request
inputBuffer.nextRequest();
outputBuffer.nextRequest();
}
rp.setStage(org.apache.coyote.Constants.STAGE_ENDED);
// Recycle
inputBuffer.recycle();
outputBuffer.recycle();