📄 ajp13processor.java
字号:
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) {
logger.log("process: ajp13.close", e);
}
try {
if (debug > 0) {
logger.log("closing socket...");
}
socket.close();
if (debug > 0) {
logger.log("socket closed.");
}
} catch (IOException e) {
logger.log("process: socket.close", e);
}
socket = null;
if (debug > 0) {
logger.log("process: done");
}
}
// ---------------------------------------------- Background Thread Methods
/**
* The background thread that listens for incoming TCP/IP connections and
* hands them off to an appropriate processor.
*/
public void run() {
// Process requests until we receive a shutdown signal
while (!stopped.value()) {
// Wait for the next socket to be assigned
if (debug > 0) {
logger.log("waiting for next socket to be assigned...");
}
Socket socket = await();
if (socket == null)
continue;
if (debug > 0) {
logger.log("socket assigned.");
}
// Process the request from this socket
process(socket);
// Finish up this request
if (debug > 0) {
logger.log("recycling myself ...");
}
connector.recycle(this);
}
// Tell threadStop() we have shut ourselves down successfully
synchronized (threadSync) {
threadSync.notifyAll();
}
}
/**
* Start the background processing thread.
*/
private void threadStart() {
logger.log(sm.getString("ajp13Processor.starting"));
stopped.set(false);
thread = new Thread(threadGroup, this, threadName);
thread.setDaemon(true);
thread.start();
if (debug > 0)
logger.log(" Background thread has been started");
}
/**
* Stop the background processing thread.
*/
private void threadStop() {
logger.log(sm.getString("ajp13Processor.stopping"));
stopped.set(true);
assign(null);
synchronized (threadSync) {
try {
if (handlingRequest.value()) {
if (debug > 0) {
logger.log
("currentling handling a request, so waiting....");
}
threadSync.wait(5000);
} else {
if (debug > 0) {
logger.log
("not currently handling a request, not waiting.");
}
}
} catch (InterruptedException e) {
;
}
}
thread = null;
}
// ------------------------------------------------------ Lifecycle Methods
/**
* Add a lifecycle event listener to this component.
*
* @param listener The listener to add
*/
public void addLifecycleListener(LifecycleListener listener) {
lifecycle.addLifecycleListener(listener);
}
/**
* Get the lifecycle listeners associated with this lifecycle. If this
* Lifecycle has no listeners registered, a zero-length array is returned.
*/
public LifecycleListener[] findLifecycleListeners() {
return null; // FIXME: lifecycle.findLifecycleListeners();
}
/**
* Remove a lifecycle event listener from this component.
*
* @param listener The listener to add
*/
public void removeLifecycleListener(LifecycleListener listener) {
lifecycle.removeLifecycleListener(listener);
}
/**
* Start the background thread we will use for request processing.
*
* @exception LifecycleException if a fatal startup error occurs
*/
public void start() throws LifecycleException {
if (started)
throw new LifecycleException
(sm.getString("ajp13Processor.alreadyStarted"));
lifecycle.fireLifecycleEvent(START_EVENT, null);
started = true;
threadStart();
}
/**
* Stop the background thread we will use for request processing.
*
* @exception LifecycleException if a fatal shutdown error occurs
*/
public void stop() throws LifecycleException {
if (!started)
throw new LifecycleException
(sm.getString("ajp13Processor.notStarted"));
lifecycle.fireLifecycleEvent(STOP_EVENT, null);
started = false;
threadStop();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -