res.sendRedirect(res.encodeRedirectURL(prefix + "/"));
return;
}
String contentType = null;
ContextMap ctxMap = null;
Environment env;
try{
if (uri.charAt(0) == '/') {
uri = uri.substring(1);
}
// Pass uri into environment without URLDecoding, as it is already decoded.
env = getEnvironment(uri, request, res);
} catch (Exception e) {
if (getLogger().isErrorEnabled()) {
getLogger().error("Problem with Cocoon servlet", e);
}
manageException(request, res, null, uri,
HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Problem in creating the Environment", null, null, e);
return;
}
try {
try {
// 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 {
// We reach this when there is nothing in the processing change that matches
// the request. For example, no matcher matches.
getLogger().fatalError("The Cocoon engine failed to process the request.");
manageException(request, res, env, uri,
HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Request Processing Failed",
"Cocoon engine failed in process the request",
"The processing engine failed to process the request. This could be due to lack of matching or bugs in the pipeline engine.",
null);
return;
}
} catch (ResourceNotFoundException e) {
if (getLogger().isDebugEnabled()) {
getLogger().warn(e.getMessage(), e);
} else if (getLogger().isWarnEnabled()) {
getLogger().warn(e.getMessage());
}
manageException(request, res, env, uri,
HttpServletResponse.SC_NOT_FOUND,
"Resource Not Found",
"Resource Not Found",
"The requested resource \"" + request.getRequestURI() + "\" could not be found",
e);
return;
} catch (ConnectionResetException e) {
if (getLogger().isDebugEnabled()) {
getLogger().debug(e.toString(), e);
} else if (getLogger().isWarnEnabled()) {
getLogger().warn(e.toString());
}
} catch (IOException e) {
// Tomcat5 wraps SocketException into ClientAbortException which extends IOException.
if (getLogger().isDebugEnabled()) {
getLogger().debug(e.toString(), e);
} else if (getLogger().isWarnEnabled()) {
getLogger().warn(e.toString());
}
} catch (Exception e) {
if (getLogger().isErrorEnabled()) {
getLogger().error("Internal Cocoon Problem", e);
}
manageException(request, res, env, uri,
HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Internal Server Error", null, null, e);
return;
}
stopWatch.stop();
String timeString = null;
if (getLogger().isInfoEnabled()) {
timeString = processTime(stopWatch.getTime());
getLogger().info("'" + uri + "' " + timeString);
}
if (contentType != null && contentType.equals("text/html")) {
String showTime = request.getParameter(Constants.SHOWTIME_PARAM);
boolean show = this.showTime;
if (showTime != null) {
show = !showTime.equalsIgnoreCase("no");
}
if (show) {
if (timeString == null) {
timeString = processTime(stopWatch.getTime());
}
boolean hide = this.hiddenShowTime;
if (showTime != null) {
hide = showTime.equalsIgnoreCase("hide");
}
ServletOutputStream out = res.getOutputStream();
out.print((hide) ? "<!-- " : "<p>");
out.print(timeString);
out.println((hide) ? " -->" : "</p>");
}
}
} finally {
if (ctxMap != null) {
ctxMap.clear();
}
try {
if (request instanceof MultipartHttpServletRequest) {
if (getLogger().isDebugEnabled()) {