// synchronization object
Object o = null;
try {
Reply reply = srResp.getReply();
if (reply != null) {
o = reply.getState(JigsawHttpServletResponse.MONITOR);
}
ClassLoader loader = switchContext(srServlet);
try {
srServlet.service(srReq , srResp);
}
finally {
resetContext(loader);
}
// processing done, release the servlet
try {
int duration = (int)Math.min(System.currentTimeMillis() - start, Integer.MAX_VALUE);
servletPool.releaseServlet(srServlet, duration);
} finally {
srServlet = null;
}
// and remove the timer
if ( stimer != null ) {
server.timer.recallTimer(stimer);
stimer = null;
}
srResp.flushStream(true);
} catch (UnavailableException uex) {
String message = null;
srResp.setStatus(HTTP.SERVICE_UNAVAILABLE);
if (uex.isPermanent()) {
message = "<h2>The servlet is permanently "+
"unavailable :</h2>"+
"Details: <b>"+uex.getMessage()+"</b>";
try {
srResp.sendError(HTTP.SERVICE_UNAVAILABLE, message);
} catch (IOException ioex) {
// not much to do now...
}
} else {
int delay = uex.getUnavailableSeconds();
if (delay > 0) {
message = "<h2>The servlet is temporarily "+
"unavailable :</h2>"+
"Delay : "+delay+
" seconds<br><br>Details: <b>"+
uex.getMessage()+"</b>";
srResp.getReply().setRetryAfter(delay);
try {
srResp.sendError(HTTP.SERVICE_UNAVAILABLE,message);
} catch (IOException ioex) {
// not much to do now...
}
} else {
message = "<h2>The servlet is temporarily "+
"unavailable :</h2>"+
"Details: <b>"+uex.getMessage()+
"</b>";
try {
srResp.sendError(HTTP.SERVICE_UNAVAILABLE,message);
} catch (IOException ioex) {
// not much to do now...
}
}
}
} catch (Exception ex) {
if (debug) {
ex.printStackTrace();
}
if (srResp.isStreamObtained()) {
try {
srResp.flushStream(false);
OutputStream os = srResp.getRawOutputStream();
if (os != null) {
synchronized (os) {
PrintWriter pw = new PrintWriter(os);
ex.printStackTrace(pw);
pw.flush();
}
}
srResp.flushStream(true);
} catch (IOException ioex) {}
} else {
try {
srResp.sendError(HTTP.INTERNAL_SERVER_ERROR,
"Servlet has thrown exception:" +
ex.toString());
} catch (IOException ioex) {
// no stream to write on, fail silently
}
}
} finally {
if ( stimer != null ) {
server.timer.recallTimer(stimer);
stimer = null;
}
if (srServlet != null) {
try {
int duration = (int)Math.min(System.currentTimeMillis() - start, Integer.MAX_VALUE);
servletPool.releaseServlet(srServlet, duration);
}
catch (ServletException ex) {
// ignore
}
}
// release the monitor waiting for the end of the reply setup
if (o != null) {
synchronized (o) {
o.notifyAll();
}
}
srServlet = null;
srReq = null;
// adds the END state
Reply r = srResp.getReply();
if (r != null) {
r.setState(ENDED, new Object());
}
srResp = null;
}
}