*
* @throws IOException error during an I/O operation
*/
public boolean process(long socket)
throws IOException {
RequestInfo rp = request.getRequestProcessor();
rp.setStage(org.apache.coyote.Constants.STAGE_PARSE);
// Setting up the socket
this.socket = socket;
Socket.setrbb(this.socket, inputBuffer);
Socket.setsbb(this.socket, outputBuffer);
// Error flag
error = false;
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)) {
// 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;
} else if(type != Constants.JK_AJP13_FORWARD_REQUEST) {
// Unexpected packet type. Unread body packets should have
// been swallowed in finish().
if (log.isDebugEnabled()) {
log.debug("Unexpected message: " + type);
}
error = true;
break;
}
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);
adapter.log(request, response, 0);
error = true;
}
// Setting up filters, and parse some request headers
if (!error) {
rp.setStage(org.apache.coyote.Constants.STAGE_PREPARE);
try {
prepareRequest();
} catch (Throwable t) {
log.debug(sm.getString("ajpprocessor.request.prepare"), t);
// 400 - Internal Server Error
response.setStatus(400);
adapter.log(request, response, 0);
error = true;
}
}
// Process the request in the adapter
if (!error) {
try {
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);
adapter.log(request, response, 0);
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();
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;
}