// Check if cocoon was initialized
if (this.cocoon == null) {
res.setStatus(res.SC_INTERNAL_SERVER_ERROR);
SimpleNotifyingBean n= new SimpleNotifyingBean(this);
n.setType("fatal");
n.setTitle("Internal servlet error");
n.setSource("Cocoon servlet");
n.setMessage("Cocoon was not initialized.");
n.setDescription("Cocoon was not initialized. Cannot process request.");
n.addExtraDescription("request-uri", request.getRequestURI());
res.setContentType(Notifier.notify(n, res.getOutputStream()));
return;
}
// We got it... Process the request
String uri = request.getServletPath();
if (uri == null) {
uri = "";
}
String pathInfo = request.getPathInfo();
if (pathInfo != null) {
// VG: WebLogic fix: Both uri and pathInfo starts with '/'
// This problem exists only in WL6.1sp2, not in WL6.0sp2 or WL7.0b.
if (uri.length() > 0 && uri.charAt(0) == '/') {
uri = uri.substring(1);
}
uri += pathInfo;
}
if (uri.length() == 0) {
/* empty relative URI
-> HTTP-redirect from /cocoon to /cocoon/ to avoid
StringIndexOutOfBoundsException when calling
"".charAt(0)
else process URI normally
*/
String prefix = request.getRequestURI();
if (prefix == null) {
prefix = "";
}
res.sendRedirect(res.encodeRedirectURL(prefix + "/"));
return;
}
String contentType = null;
ContextMap ctxMap = null;
try {
try {
if (uri.charAt(0) == '/') {
uri = uri.substring(1);
}
Environment env = this.getEnvironment(uri, request, res);
// Initialize a fresh log context containing the object model : it
// will be used by the CocoonLogFormatter
ctxMap = ContextMap.getCurrentContext();
// Add thread name (default content for empty context)
String threadName = Thread.currentThread().getName();
ctxMap.set("threadName", threadName);
// Add the object model
ctxMap.set("objectModel", env.getObjectModel());
// Add a unique request id (threadName + currentTime
ctxMap.set("request-id", threadName + System.currentTimeMillis());
if (this.cocoon.process(env)) {
contentType = env.getContentType();
} else {
// Should not get here!
// means SC_NOT_FOUND
res.sendError(res.SC_NOT_FOUND);
SimpleNotifyingBean n = new SimpleNotifyingBean(this);
n.setType("error");
n.setTitle("Resource not found");
n.setSource("Cocoon servlet");
n.setMessage("The requested resource not found.");
n.setDescription("The requested URI \""
+ request.getRequestURI()
+ "\" was not found.");
n.addExtraDescription("request-uri", request.getRequestURI());
n.addExtraDescription("path-info", uri);
// send the notification but don't include it in the output stream
// as the status SC_NOT_FOUND is enough
res.setContentType(Notifier.notify(n, (OutputStream)null));
}
} catch (ResourceNotFoundException rse) {
if (log.isWarnEnabled()) {
log.warn("The resource was not found", rse);
}
res.sendError(res.SC_NOT_FOUND);
SimpleNotifyingBean n = new SimpleNotifyingBean(this);
n.setType("resource-not-found");
n.setTitle("Resource not found");
n.setSource("Cocoon servlet");
n.setMessage("Resource not found");
n.setDescription("The requested URI \""
+ request.getRequestURI()
+ "\" was not found.");
n.addExtraDescription("request-uri", request.getRequestURI());
n.addExtraDescription("path-info", uri);
StringWriter writer = new StringWriter();
rse.printStackTrace(new PrintWriter(writer));
n.addExtraDescription("stack-trace",writer.toString());
// send the notification but don't include it in the output stream
// as the status SC_NOT_FOUND is enough
res.setContentType(Notifier.notify(n, (OutputStream)null));
} catch (ConnectionResetException cre) {
if (log.isWarnEnabled()) {
log.warn("The connection was reset", cre);
}
SimpleNotifyingBean n = new SimpleNotifyingBean(this);
n.setType("error");
n.setTitle("Resource not found");
n.setSource("Cocoon servlet");
n.setMessage("Resource not found");
n.setDescription("The requested URI \""
+ request.getRequestURI()
+ "\" was not found.");
n.addExtraDescription("request-uri", request.getRequestURI());
n.addExtraDescription("path-info", uri);
// send the notification but don't include it in the output stream
// as the connection was reset anyway
res.setContentType(Notifier.notify(n, (OutputStream)null));
} catch (Exception e) {
if (log.isErrorEnabled()) {