in blocks/cocoon-portal/cocoon-portal-portlet-env/src/main/java/org/apache/cocoon/portlet/CocoonPortlet.java [353:506]
public void render(RenderRequest req, RenderResponse res)
throws PortletException, IOException {
// remember when we started (used for timing the processing)
long start = System.currentTimeMillis();
// add the cocoon header timestamp
res.setProperty("X-Cocoon-Version", Constants.VERSION);
// get the request (wrapped if contains multipart-form data)
RenderRequest request = req;
// Get the cocoon engine instance
try {
this.exception = null;
// FIXME
this.cocoon = (Cocoon)this.coreUtil.getProcessor(request.getParameter(Constants.RELOAD_PARAM) != null);
} catch (Exception e) {
this.exception = e;
}
// Check if cocoon was initialized
if (this.cocoon == null) {
manageException(request, res, null, null,
"Initialization Problem",
null /* "Cocoon was not initialized" */,
null /* "Cocoon was not initialized, cannot process request" */,
this.exception);
return;
}
// We got it... Process the request
String servletPath = this.servletPath;
if (servletPath == null) {
servletPath = "portlets/" + getPortletConfig().getPortletName();
}
String pathInfo = getPathInfo(request);
String uri = servletPath;
if (pathInfo != null) {
uri += pathInfo;
}
String contentType = null;
Environment env;
try {
if (uri.charAt(0) == '/') {
uri = uri.substring(1);
}
env = getEnvironment(servletPath, pathInfo, uri, request, res);
} catch (Exception e) {
if (getLogger().isErrorEnabled()) {
getLogger().error("Problem with Cocoon portlet", e);
}
manageException(request, res, null, uri,
"Problem in creating the Environment", null, null, e);
return;
}
try {
try {
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,
"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 rse) {
if (getLogger().isWarnEnabled()) {
getLogger().warn("The resource was not found", rse);
}
manageException(request, res, env, uri,
"Resource Not Found",
"Resource Not Found",
"The requested portlet could not be found",
rse);
return;
} catch (ConnectionResetException e) {
if (getLogger().isDebugEnabled()) {
getLogger().debug(e.getMessage(), e);
} else if (getLogger().isWarnEnabled()) {
getLogger().warn(e.getMessage());
}
} catch (IOException e) {
// Tomcat5 wraps SocketException into ClientAbortException which extends IOException.
if (getLogger().isDebugEnabled()) {
getLogger().debug(e.getMessage(), e);
} else if (getLogger().isWarnEnabled()) {
getLogger().warn(e.getMessage());
}
} catch (Exception e) {
if (getLogger().isErrorEnabled()) {
getLogger().error("Internal Cocoon Problem", e);
}
manageException(request, res, env, uri,
"Internal Server Error", null, null, e);
return;
}
long end = System.currentTimeMillis();
String timeString = processTime(end - start);
if (getLogger().isInfoEnabled()) {
getLogger().info("'" + uri + "' " + timeString);
}
res.setProperty("X-Cocoon-Time", timeString);
if (contentType != null && contentType.equals("text/html")) {
String showTime = request.getParameter(Constants.SHOWTIME_PARAM);
boolean show = this.settings.isShowTime();
if (showTime != null) {
show = !showTime.equalsIgnoreCase("no");
}
if (show) {
boolean hide = this.settings.isHideShowTime();
if (showTime != null) {
hide = showTime.equalsIgnoreCase("hide");
}
PrintStream out = new PrintStream(res.getPortletOutputStream());
out.print((hide) ? "<!-- " : "<p>");
out.print(timeString);
out.println((hide) ? " -->" : "</p>\n");
}
}
} finally {
if (request instanceof MultipartActionRequest) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Deleting uploaded file(s).");
}
((MultipartActionRequest) request).cleanup();
}
/*
* Portlet Specification 1.0, PLT.12.3.2 Output Stream and Writer Objects:
* The termination of the render method of the portlet indicates
* that the portlet has satisfied the request and that the output
* object is to be closed.
*
* Portlet container will close the stream, no need to close it here.
*/
}
}