You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2006/12/23 19:22:27 UTC
svn commit: r489912 - in
/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet:
RequestProcessor.java RequestUtil.java multipart/MultipartFilter.java
Author: cziegeler
Date: Sat Dec 23 10:22:26 2006
New Revision: 489912
URL: http://svn.apache.org/viewvc?view=rev&rev=489912
Log:
Fix exception handling in multipart filter and extract manageExceptions method
Modified:
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartFilter.java
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java?view=diff&rev=489912&r1=489911&r2=489912
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestProcessor.java Sat Dec 23 10:22:26 2006
@@ -17,7 +17,6 @@
package org.apache.cocoon.servlet;
import java.io.IOException;
-import java.util.HashMap;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
@@ -31,9 +30,6 @@
import org.apache.cocoon.Processor;
import org.apache.cocoon.RequestListener;
import org.apache.cocoon.ResourceNotFoundException;
-import org.apache.cocoon.components.notification.DefaultNotifyingBuilder;
-import org.apache.cocoon.components.notification.Notifier;
-import org.apache.cocoon.components.notification.Notifying;
import org.apache.cocoon.configuration.Settings;
import org.apache.cocoon.core.container.spring.avalon.AvalonUtils;
import org.apache.cocoon.environment.Context;
@@ -144,9 +140,10 @@
getLogger().error("Problem with Cocoon servlet", e);
}
- manageException(request, res, null, uri,
+ RequestUtil.manageException(request, res, null, uri,
HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
- "Problem in creating the Environment", null, null, e);
+ "Problem in creating the Environment", null, null, e,
+ this.settings, this.getLogger(), this);
return;
}
@@ -157,12 +154,13 @@
// 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,
+ RequestUtil.manageException(request, res, env, uri,
HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Request Processing Failed",
- "Cocoon engine failed in process the request",
+ "Cocoon engine failed in processing 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);
+ null,
+ this.settings, this.getLogger(), this);
return;
}
} catch (ResourceNotFoundException e) {
@@ -172,12 +170,13 @@
getLogger().warn(e.getMessage());
}
- manageException(request, res, env, uri,
+ RequestUtil.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);
+ e,
+ this.settings, this.getLogger(), this);
return;
} catch (ConnectionResetException e) {
@@ -200,9 +199,10 @@
getLogger().error("Internal Cocoon Problem", e);
}
- manageException(request, res, env, uri,
+ RequestUtil.manageException(request, res, env, uri,
HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
- "Internal Server Error", null, null, e);
+ "Internal Server Error", null, null, e,
+ this.settings, this.getLogger(), this);
return;
}
@@ -255,58 +255,6 @@
protected String getURI(HttpServletRequest request, HttpServletResponse res) throws IOException {
return RequestUtil.getCompleteUri(request, res);
- }
-
- protected void manageException(HttpServletRequest req, HttpServletResponse res, Environment env,
- String uri, int errorStatus,
- String title, String message, String description,
- Exception e)
- throws IOException {
- if (this.settings.isManageExceptions()) {
- if (env != null) {
- env.tryResetResponse();
- } else {
- res.reset();
- }
-
- String type = Notifying.FATAL_NOTIFICATION;
- HashMap extraDescriptions = null;
-
- if (errorStatus == HttpServletResponse.SC_NOT_FOUND) {
- type = "resource-not-found";
- // Do not show the exception stacktrace for such common errors.
- e = null;
- } else {
- extraDescriptions = new HashMap(2);
- extraDescriptions.put(Notifying.EXTRA_REQUESTURI, req.getRequestURI());
- if (uri != null) {
- extraDescriptions.put("Request URI", uri);
- }
-
- // Do not show exception stack trace when log level is WARN or above. Show only message.
- if (!getLogger().isInfoEnabled()) {
- Throwable t = DefaultNotifyingBuilder.getRootCause(e);
- if (t != null) extraDescriptions.put(Notifying.EXTRA_CAUSE, t.getMessage());
- e = null;
- }
- }
-
- Notifying n = new DefaultNotifyingBuilder().build(this,
- e,
- type,
- title,
- "Cocoon Servlet",
- message,
- description,
- extraDescriptions);
-
- res.setContentType("text/html");
- res.setStatus(errorStatus);
- Notifier.notify(n, res.getOutputStream(), "text/html");
- } else {
- res.sendError(errorStatus, title);
- res.flushBuffer();
- }
}
/**
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java?view=diff&rev=489912&r1=489911&r2=489912
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/RequestUtil.java Sat Dec 23 10:22:26 2006
@@ -17,10 +17,19 @@
package org.apache.cocoon.servlet;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.cocoon.components.notification.DefaultNotifyingBuilder;
+import org.apache.cocoon.components.notification.Notifier;
+import org.apache.cocoon.components.notification.Notifying;
+import org.apache.cocoon.configuration.Settings;
+import org.apache.cocoon.environment.Environment;
+
/**
* Some utility methods for request handling etc.
*
@@ -91,4 +100,65 @@
}
return new UriHttpServletRequestWrapper(request, newServletPath, newPathInfo);
}
+
+ public static void manageException(HttpServletRequest req,
+ HttpServletResponse res,
+ Environment env,
+ String uri,
+ int errorStatus,
+ String title,
+ String message,
+ String description,
+ Exception e,
+ Settings settings,
+ Logger logger,
+ Object sender)
+ throws IOException {
+ if (settings.isManageExceptions()) {
+ if (env != null) {
+ env.tryResetResponse();
+ } else {
+ res.reset();
+ }
+
+ String type = Notifying.FATAL_NOTIFICATION;
+ Map extraDescriptions = null;
+
+ if (errorStatus == HttpServletResponse.SC_NOT_FOUND) {
+ type = "resource-not-found";
+ // Do not show the exception stacktrace for such common errors.
+ e = null;
+ } else {
+ extraDescriptions = new HashMap(2);
+ extraDescriptions.put(Notifying.EXTRA_REQUESTURI, req.getRequestURI());
+ if (uri != null) {
+ extraDescriptions.put("Request URI", uri);
+ }
+
+ // Do not show exception stack trace when log level is WARN or above. Show only message.
+ if ( logger.isInfoEnabled()) {
+ Throwable t = DefaultNotifyingBuilder.getRootCause(e);
+ if (t != null) extraDescriptions.put(Notifying.EXTRA_CAUSE, t.getMessage());
+ e = null;
+ }
+ }
+
+ Notifying n = new DefaultNotifyingBuilder().build(sender,
+ e,
+ type,
+ title,
+ "Cocoon Servlet",
+ message,
+ description,
+ extraDescriptions);
+
+ res.setContentType("text/html");
+ res.setStatus(errorStatus);
+ Notifier.notify(n, res.getOutputStream(), "text/html");
+ } else {
+ res.sendError(errorStatus, title);
+ res.flushBuffer();
+ }
+ }
+
}
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartFilter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartFilter.java?view=diff&rev=489912&r1=489911&r2=489912
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartFilter.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartFilter.java Sat Dec 23 10:22:26 2006
@@ -18,7 +18,6 @@
import java.io.File;
import java.io.IOException;
-import java.util.HashMap;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@@ -31,12 +30,9 @@
import javax.servlet.http.HttpServletResponse;
import org.apache.avalon.framework.logger.Logger;
-import org.apache.cocoon.components.notification.DefaultNotifyingBuilder;
-import org.apache.cocoon.components.notification.Notifier;
-import org.apache.cocoon.components.notification.Notifying;
import org.apache.cocoon.configuration.Settings;
import org.apache.cocoon.core.container.spring.avalon.AvalonUtils;
-import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.servlet.RequestUtil;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.web.context.support.WebApplicationContextUtils;
@@ -101,15 +97,15 @@
HttpServletResponse response = (HttpServletResponse) res;
try{
request = this.requestFactory.getServletRequest(request);
- filterChain.doFilter(request, response);
} catch (Exception e) {
if (getLogger().isErrorEnabled()) {
- getLogger().error("Problem with Cocoon servlet", e);
+ getLogger().error("Problem in multipart filter. Unable to create request.", e);
}
- manageException(request, response, null, null,
- HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
- "Problem in creating the Request", null, null, e);
+ RequestUtil.manageException(request, response, null, null,
+ HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+ "Problem in creating the Request",
+ null, null, e, this.settings, getLogger(), this);
} finally {
try {
if (request instanceof MultipartHttpServletRequest) {
@@ -119,63 +115,10 @@
((MultipartHttpServletRequest) request).cleanup();
}
} catch (IOException e) {
- getLogger().error("Cocoon got an Exception while trying to cleanup the uploaded files.", e);
+ getLogger().error("MultipartFilter got an exception while trying to cleanup the uploaded files.", e);
}
}
- }
-
- // FIXME: This method is a copy from the RequestProcessor, it should be factored out
- // to some utility class.
- protected void manageException(HttpServletRequest req, HttpServletResponse res, Environment env,
- String uri, int errorStatus,
- String title, String message, String description,
- Exception e)
- throws IOException {
- if (this.settings.isManageExceptions()) {
- if (env != null) {
- env.tryResetResponse();
- } else {
- res.reset();
- }
-
- String type = Notifying.FATAL_NOTIFICATION;
- HashMap extraDescriptions = null;
-
- if (errorStatus == HttpServletResponse.SC_NOT_FOUND) {
- type = "resource-not-found";
- // Do not show the exception stacktrace for such common errors.
- e = null;
- } else {
- extraDescriptions = new HashMap(2);
- extraDescriptions.put(Notifying.EXTRA_REQUESTURI, req.getRequestURI());
- if (uri != null) {
- extraDescriptions.put("Request URI", uri);
- }
-
- // Do not show exception stack trace when log level is WARN or above. Show only message.
- if (!getLogger().isInfoEnabled()) {
- Throwable t = DefaultNotifyingBuilder.getRootCause(e);
- if (t != null) extraDescriptions.put(Notifying.EXTRA_CAUSE, t.getMessage());
- e = null;
- }
- }
-
- Notifying n = new DefaultNotifyingBuilder().build(this,
- e,
- type,
- title,
- "Cocoon Servlet",
- message,
- description,
- extraDescriptions);
-
- res.setContentType("text/html");
- res.setStatus(errorStatus);
- Notifier.notify(n, res.getOutputStream(), "text/html");
- } else {
- res.sendError(errorStatus, title);
- res.flushBuffer();
- }
+ filterChain.doFilter(request, response);
}
protected Logger getLogger() {