return repi;
if (! checkRequest(req))
return null;
Request request = (Request) req;
PipedInputStream pis = null;
if (wrapper == null) {
Reply reply = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
reply.setContent("Servlet Wrapper Frame not configured properly: "+
"must be attached to a ServletWrapper.");
throw new HTTPException(reply);
}
try {
wrapper.checkServlet();
} catch (ClassNotFoundException ex) {
Reply reply = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
reply.setContent("The server was unable to find the "+
"servlet class : "+ex.getMessage());
if ( wrapper.debug )
ex.printStackTrace();
throw new HTTPException(reply);
} catch (ServletException ex) {
Reply reply = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
reply.setContent("The server was unable to initialize the "+
"servlet : "+ex.getMessage());
if ( wrapper.debug )
ex.printStackTrace();
throw new HTTPException(reply);
}
// Check that the servlet has been initialized properly:
if ( ! wrapper.isInited() ) {
Reply reply = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
reply.setContent("Servlet not configured properly");
throw new HTTPException(reply);
}
// Dispatch the request:
Reply reply = createDefaultReply(request, HTTP.OK);
reply.setContentType(MimeType.TEXT_HTML);
try {
if (request.hasState(JigsawHttpServletResponse.INCLUDED)) {
wrapper.service(request, reply);
} else {
pis = new PipedInputStream();
request.setState(JigsawHttpServletResponse.STREAM, pis);
PipedOutputStream pos = new PipedOutputStream(pis);
reply.setState(JigsawHttpServletResponse.STREAM, pos);
reply.setStream(pis);
Object o = new Object();
reply.setState(JigsawHttpServletResponse.MONITOR, o);
// wait until the reply is constructed by the processing thread
ServerInterface server = getServer();
if (server instanceof httpd) {
synchronized (o) {
wrapper.service(request, reply);
o.wait((long)((httpd)server).getRequestTimeOut());
}
Object strm;
strm = reply.getState(JigsawHttpServletResponse.STREAM);
if (strm != null) {
// it is a timeout
try {
pis.close();
pos.close();
} catch (IOException ex) {};
if (strm instanceof PipedOutputStream) {
ServletWrapper.ServletRunner r;
r = (ServletWrapper.ServletRunner)
reply.getState(ServletWrapper.RUNNER);
if (r != null) {
r.signalTimeout();
}
throw new ServletException("Timed out");
}
}
} else {
synchronized (o) {
wrapper.service(request, reply);
o.wait();
}
}
}
} catch (UnavailableException uex) {
reply = request.makeReply(HTTP.SERVICE_UNAVAILABLE);
if (uex.isPermanent()) {
reply.setContent("<h2>The servlet is permanently "+
"unavailable :</h2>"+
"Details: <b>"+uex.getMessage()+"</b>");
} else {
int delay = uex.getUnavailableSeconds();
if (delay > 0) {
reply.setRetryAfter(delay);
reply.setContent("<h2>The servlet is temporarily "+
"unavailable :</h2>"+
"Delay : "+delay+
" seconds<br><br>Details: <b>"+
uex.getMessage()+"</b>");
} else {
reply.setContent("<h2>The servlet is temporarily "+
"unavailable :</h2>"+
"Details: <b>"+uex.getMessage()+"</b>");
}
}
if (pis != null) {
try {
pis.close();
} catch (IOException ioex) {}
}
} catch (Exception ex) {
if ( wrapper.debug )
ex.printStackTrace();
reply = request.makeReply(HTTP.INTERNAL_SERVER_ERROR);
reply.setContent("Servlet has thrown exception:" + ex.toString());
if (pis != null) {
try {
pis.close();
} catch (IOException ioex) {}