*
* @throws IOException error during an I/O operation
*/
public void process(Socket socket)
throws IOException {
RequestInfo rp = request.getRequestProcessor();
rp.setStage(org.apache.coyote.Constants.STAGE_PARSE);
// Setting up the socket
this.socket = socket;
input = socket.getInputStream();
output = socket.getOutputStream();
int soTimeout = -1;
if (keepAliveTimeout > 0) {
soTimeout = socket.getSoTimeout();
}
// Error flag
error = false;
while (started && !error) {
// Parsing the request header
try {
// Set keep alive timeout if enabled
if (keepAliveTimeout > 0) {
socket.setSoTimeout(keepAliveTimeout);
}
// Get first message of the request
if (!readMessage(requestHeaderMessage)) {
// This means a connection timeout
rp.setStage(org.apache.coyote.Constants.STAGE_ENDED);
break;
}
// Set back timeout if keep alive timeout is enabled
if (keepAliveTimeout > 0) {
socket.setSoTimeout(soTimeout);
}
// Check message type, process right away and break if
// not regular request processing
int type = requestHeaderMessage.getByte();
if (type == Constants.JK_AJP13_CPING_REQUEST) {
try {
output.write(pongMessageArray);
} catch (IOException e) {
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;
}
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();
}
rp.setStage(org.apache.coyote.Constants.STAGE_ENDED);
recycle();
input = null;
output = null;
}