*/
public boolean process(long socket)
throws IOException {
ThreadWithAttributes thrA=
(ThreadWithAttributes)Thread.currentThread();
RequestInfo rp = request.getRequestProcessor();
thrA.setCurrentStage(endpoint, "parsing http request");
rp.setStage(org.apache.coyote.Constants.STAGE_PARSE);
// Setting up the socket
this.socket = socket;
// Error flag
error = false;
long soTimeout = endpoint.getSoTimeout();
int limit = 0;
if (endpoint.getFirstReadTimeout() > 0) {
limit = endpoint.getMaxThreads() / 2;
}
boolean openSocket = true;
boolean keptAlive = false;
while (started && !error) {
// Parsing the request header
try {
// Get first message of the request
if (!readMessage(requestHeaderMessage, true,
keptAlive && (endpoint.getCurrentThreadsBusy() > limit))) {
// This means that no data is available right now
// (long keepalive), so that the processor should be recycled
// and the method should return true
rp.setStage(org.apache.coyote.Constants.STAGE_ENDED);
break;
}
// Check message type, process right away and break if
// not regular request processing
int type = requestHeaderMessage.getByte();
if (type == Constants.JK_AJP13_CPING_REQUEST) {
if (Socket.sendb(socket, pongMessageBuffer, 0,
pongMessageBuffer.position()) < 0) {
error = true;
}
continue;
}
keptAlive = true;
request.setStartTime(System.currentTimeMillis());
} catch (IOException e) {
error = true;
break;
} catch (Throwable t) {
log.debug(sm.getString("ajpprocessor.header.error"), t);
// 400 - Bad Request
response.setStatus(400);
error = true;
}
// Setting up filters, and parse some request headers
thrA.setCurrentStage(endpoint, "prepareRequest");
rp.setStage(org.apache.coyote.Constants.STAGE_PREPARE);
try {
prepareRequest();
thrA.setParam(endpoint, request.requestURI());
} catch (Throwable t) {
log.debug(sm.getString("ajpprocessor.request.prepare"), t);
// 400 - Internal Server Error
response.setStatus(400);
error = true;
}
// Process the request in the adapter
if (!error) {
try {
thrA.setCurrentStage(endpoint, "service");
rp.setStage(org.apache.coyote.Constants.STAGE_SERVICE);
adapter.service(request, response);
} catch (InterruptedIOException e) {
error = true;
} catch (Throwable t) {
log.error(sm.getString("ajpprocessor.request.process"), t);
// 500 - Internal Server Error
response.setStatus(500);
error = true;
}
}
// Finish the response if not done yet
if (!finished) {
try {
finish();
} catch (Throwable 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(endpoint, "ended");
rp.setStage(org.apache.coyote.Constants.STAGE_KEEPALIVE);
recycle();
}
// Add the socket to the poller
if (!error) {
endpoint.getPoller().add(socket);
} else {
openSocket = false;
}
rp.setStage(org.apache.coyote.Constants.STAGE_ENDED);
recycle();
return openSocket;
}