*
* @param socket The socket on which we are connected to the client
*/
private void process(Socket socket) {
Ajp13 ajp13 = new Ajp13();
ajp13.setDebug(debug);
ajp13.setLogger(new org.apache.ajp.Logger() {
public void log(String msg) {
logger.log("[Ajp13] " + msg);
}
public void log(String msg, Throwable t) {
logger.log("[Ajp13] " + msg, t);
}
});
Ajp13InputStream input = new Ajp13InputStream(ajp13);
Ajp13OutputStream output = new Ajp13OutputStream(ajp13);
response.setAjp13(ajp13);
try {
ajp13.setSocket(socket);
} catch (IOException e) {
logger.log("process: ajp13.setSocket", e);
}
boolean moreRequests = true;
String expectedSecret=connector.getSecret();
boolean needAuth= ( expectedSecret != null );
while (moreRequests && !stopped.value()) {
int status = 0;
try {
if (debug > 0) {
logger.log("waiting on next request...");
}
status = ajp13.receiveNextRequest(ajpRequest);
if (debug > 0) {
logger.log("received next request, status=" + status);
}
} catch (IOException e) {
logger.log("process: ajp13.receiveNextRequest", e);
}
if( needAuth ) {
String connSecret=ajp13.getSecret();
if( connSecret == null ) {
logger.log( "Connection without password, " +
"tomcat is configured to require one" );
break;
}
if( ! connSecret.equals(expectedSecret) ) {
logger.log( "Connection with wrong password" );
break;
}
needAuth=false;
}
if (stopped.value()) {
if (debug > 0) {
logger.log("process: received request, but we're stopped");
}
break;
}
if( status==-2) {
// special case - shutdown
// XXX need better communication, refactor it
// if( !doShutdown(socket.getLocalAddress(),
// socket.getInetAddress())) {
// moreRequests = false;
// continue;
// }
break;
}
// Allready handled by low level proto, don't go farther
if( status == 999 )
{
ajpRequest.recycle();
request.recycle();
// recycle ajp13 object
ajp13.recycle();
continue;
}
if( status != 200 )
break;
try {
// set flag
handlingRequest.set(true);
boolean bad_request = false;
// set up request
try {
request.setAjpRequest(ajpRequest);
} catch (IllegalArgumentException e) {
bad_request = true;
}
request.setResponse(response);
request.setStream(input);
// setup response
response.setRequest(request);
response.setStream(output);
if (debug > 0) {
logger.log("invoking...");
}
if (!bad_request) {
try {
connector.getContainer().invoke(request, response);
} catch (IOException ioe) {
// Pass the IOException through
throw ioe;
} catch (Throwable e) {
// A throwable here could be caused by a Valve,
// Filter, or other component in the chain.
// Processing of the request failed, return an
// Internal Server Error
logger.log("process: invoke", e);
response.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
} else {
response.sendError
(HttpServletResponse.SC_BAD_REQUEST);
}
if (debug > 0) {
logger.log("done invoking, finishing request/response....");
}
response.finishResponse();
request.finishRequest();
if (debug > 0) {
logger.log("finished handling request.");
}
} catch (IOException ioe) {
// Normally this catches a socket Broken Pipe caused by the
// remote client aborting the request. Don't print the stack
// trace in this case. Then let the Processor recycle.
logger.log("process: IOException " + ioe.getMessage());
moreRequests = false;
} catch (Throwable e) {
// Processing the request and sending the response failed.
// We don't know what the state of the Ajp Connector socket
// is in. Bail out and recycle the Processor.
logger.log("process: finish", e);
moreRequests = false;
}
// Recycling the request and the response objects
if (debug > 0) {
logger.log("recyling objects ...");
}
ajpRequest.recycle();
request.recycle();
response.recycle();
// recycle ajp13 object
ajp13.recycle();
// reset flag
handlingRequest.set(false);
}
try {
if (debug > 0) {
logger.log("closing ajp13 object...");
}
ajp13.close();
if (debug > 0) {
logger.log("ajp13 object closed.");
}
} catch (IOException e) {