ServerSocket server = new ServerSocket(8009);
TestAjp13.println("Ajp13Server running...");
Socket socket = server.accept();
Ajp13 ajp13 = new Ajp13();
MimeHeaders headers = new MimeHeaders();
BaseRequest request = new BaseRequest();
ajp13.setSocket(socket);
boolean moreRequests = true;
while (moreRequests && !shutdown) {
int status = 0;
try {
status = ajp13.receiveNextRequest(request);
} catch (IOException e) {
if (shutdown) {
TestAjp13.println("Ajp13Server told to shutdown");
break;
}
TestAjp13.println("process: ajp13.receiveNextRequest -> " + e);
}
if( status==-2) {
// special case - shutdown
// XXX need better communication, refactor it
// if( !doShutdown(socket.getLocalAddress(),
// socket.getInetAddress())) {
// moreRequests = false;
// continue;
// }
break;
}
// Special low level request allready handled (ie: PING/PONG)
if( status == 999 )
{
request.recycle();
continue;
}
if( status != 200 )
break;
TestAjp13.println(request.toString());
String message =
"<html><body><pre>" +
"hello from ajp13: " +
System.getProperty("line.separator") +
request.toString() +
"</pre></body></html>";
headers.addValue("content-type").setString( "text/html");
headers.addValue("content-length").setInt(message.length());
headers.addValue("my-header").setString( "my value");
ajp13.sendHeaders(200, headers);
byte[] b = message.getBytes();
ajp13.doWrite(b, 0, b.length);
ajp13.finish();
request.recycle();
headers.recycle();
}
try {
ajp13.close();