// Check if cocoon was initialized
if (this.cocoon == null) {
if(manageExceptions){
res.reset();
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("text/html");
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
Notifier.notify(n, res.getOutputStream(), "text/html");
} else {
res.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"The Cocoon engine said it failed to process the request for an unknown reason." );
res.flushBuffer();
}
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 = getEnvironment(URLDecoder.decode(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 {
//NKB Should not get here?
log.fatalError("The Cocoon engine said it failed to process the request for an unknown reason.");
if(manageExceptions){
res.reset();
SimpleNotifyingBean n = new SimpleNotifyingBean(this);
n.setType("error");
n.setTitle("Cocoon confusion");
n.setSource("Cocoon servlet");
n.setMessage("Cocoon engine failed in process.");
n.setDescription("The Cocoon engine said it failed to process the request for an unknown reason.");
n.addExtraDescription("request-uri", request.getRequestURI());
n.addExtraDescription("path-info", uri);
res.setContentType("text/html");
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
Notifier.notify(n, res.getOutputStream(), "text/html");
} else {
res.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"The Cocoon engine said it failed to process the request for an unknown reason." );
res.flushBuffer();
}
return;
}
} catch (ResourceNotFoundException rse) {
if (log.isWarnEnabled()) {
log.warn("The resource was not found", rse);
}
if(manageExceptions){
res.reset();
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);
res.setContentType("text/html");
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
Notifier.notify(n, res.getOutputStream(), "text/html");
} else {