nicolaken 2002/06/01 07:44:42
Modified: . changes.xml
src/java/org/apache/cocoon/servlet CocoonServlet.java
src/webapp/WEB-INF web.xml
Log:
<action dev="NKB" type="add">
Added a "handle-exceptions" init argument in web.xml, used by
CocoonServlet for the exceptions
that the core Cocoon class throws.
If true or not set, this class will try to catch and handle all Cocoon
exceptions.
If false, it will rethrow them to the servlet container.
</action>
Revision Changes Path
1.181 +7 -1 xml-cocoon2/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/xml-cocoon2/changes.xml,v
retrieving revision 1.180
retrieving revision 1.181
diff -u -r1.180 -r1.181
--- changes.xml 31 May 2002 18:59:59 -0000 1.180
+++ changes.xml 1 Jun 2002 14:44:41 -0000 1.181
@@ -4,7 +4,7 @@
<!--
History of Cocoon changes
- $Id: changes.xml,v 1.180 2002/05/31 18:59:59 nicolaken Exp $
+ $Id: changes.xml,v 1.181 2002/06/01 14:44:41 nicolaken Exp $
-->
<changes title="History of Changes">
@@ -38,6 +38,12 @@
</devs>
<release version="@version@" date="@date@">
+ <action dev="NKB" type="add">
+ Added a "handle-exceptions" init argument in web.xml, used by
CocoonServlet for the exceptions
+ that the core Cocoon class throws.
+ If true or not set, this class will try to catch and handle all Cocoon
exceptions.
+ If false, it will rethrow them to the servlet container.
+ </action>
<action dev="NKB" type="fix">
Changed the Notifier notify() methods to accept a mimetype instead of
returning it.
There is no way in which this method could understand what mime/type to
use from the
1.25 +105 -50
xml-cocoon2/src/java/org/apache/cocoon/servlet/CocoonServlet.java
Index: CocoonServlet.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/servlet/CocoonServlet.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- CocoonServlet.java 31 May 2002 18:59:59 -0000 1.24
+++ CocoonServlet.java 1 Jun 2002 14:44:42 -0000 1.25
@@ -117,7 +117,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Leo Sutic</a>
- * @version CVS $Id: CocoonServlet.java,v 1.24 2002/05/31 18:59:59 nicolaken
Exp $
+ * @version CVS $Id: CocoonServlet.java,v 1.25 2002/06/01 14:44:42 nicolaken
Exp $
*/
public class CocoonServlet extends HttpServlet {
@@ -171,6 +171,12 @@
private boolean addClassDirs;
/**
+ * If true or not set, this class will try to catch and handle all
Cocoon exceptions.
+ * If false, it will rethrow them to the servlet container.
+ */
+ private boolean manageExceptions;
+
+ /**
* This is the path to the servlet context (or the result
* of calling getRealPath('/') on the ServletContext.
* Note, that this can be null.
@@ -418,7 +424,15 @@
log.debug("form-encoding was not set - defaulting to null.");
}
}
-
+
+ value = conf.getInitParameter("manage-exceptions");
+ this.manageExceptions = (value == null ||
value.equalsIgnoreCase("yes") || value.equalsIgnoreCase("true"));
+ if (value == null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Parameter manageExceptions was not set -
defaulting to true.");
+ }
+ }
+
this.createCocoon();
}
@@ -939,18 +953,29 @@
// Check if cocoon was initialized
if (this.cocoon == null) {
- res.setStatus(res.SC_INTERNAL_SERVER_ERROR);
-
- SimpleNotifyingBean n= new SimpleNotifyingBean(this);
+ 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(Notifier.notify(n, res.getOutputStream()));
-
+
+ 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
@@ -1012,42 +1037,61 @@
//NKB Should not get here?
log.fatalError("The Cocoon engine said it failed to
process the request for an unknown reason.");
- 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);
+ 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;
+ }
- res.setContentType("text/html");
-
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- Notifier.notify(n, res.getOutputStream(), "text/html");
}
} catch (ResourceNotFoundException rse) {
if (log.isWarnEnabled()) {
log.warn("The resource was not found", rse);
}
-
- 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());
+
+ 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");
-
+ res.setContentType("text/html");
+ res.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ Notifier.notify(n, res.getOutputStream(), "text/html");
+ }
+ else{
+ res.sendError
+ (HttpServletResponse.SC_NOT_FOUND, "Resource not
found." );
+ res.flushBuffer();
+ return;
+ }
+
} catch (ConnectionResetException cre) {
if (log.isWarnEnabled()) {
log.warn("The connection was reset", cre);
@@ -1057,20 +1101,31 @@
if (log.isErrorEnabled()) {
log.error("Problem with Cocoon servlet", e);
}
-
- HashMap extraDescriptions = new HashMap(3);
- extraDescriptions.put("request-uri",
request.getRequestURI());
- extraDescriptions.put("path-info", uri);
- StringWriter writer = new StringWriter();
- e.printStackTrace(new PrintWriter(writer));
- extraDescriptions.put("stack-trace",writer.toString());
-
- Notifying n=new DefaultNotifyingBuilder().build(
- this, e, "fatal","Internal server error","Cocoon
servlet",null,null,extraDescriptions);
-
- res.setContentType("text/html");
- res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- Notifier.notify(n, res.getOutputStream(), "text/html");
+
+ if(manageExceptions){
+ res.reset();
+
+ HashMap extraDescriptions = new HashMap(3);
+ extraDescriptions.put("request-uri",
request.getRequestURI());
+ extraDescriptions.put("path-info", uri);
+ StringWriter writer = new StringWriter();
+ e.printStackTrace(new PrintWriter(writer));
+ extraDescriptions.put("stack-trace",writer.toString());
+
+ Notifying n=new DefaultNotifyingBuilder().build(
+ this, e, "fatal","Internal server error","Cocoon
servlet",null,null,extraDescriptions);
+
+ 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,
+ "Internal server error.");
+ res.flushBuffer();
+ return;
+ }
}
long end = System.currentTimeMillis();
1.12 +10 -0 xml-cocoon2/src/webapp/WEB-INF/web.xml
Index: web.xml
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/webapp/WEB-INF/web.xml,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- web.xml 22 May 2002 15:27:27 -0000 1.11
+++ web.xml 1 Jun 2002 14:44:42 -0000 1.12
@@ -215,6 +215,16 @@
-->
<!--
+ If true or not set, this class will try to catch and handle all
Cocoon exceptions.
+ If false, it will rethrow them to the servlet container.
+ -->
+ <init-param>
+ <param-name>manage-exceptions</param-name>
+ <param-value>true</param-value>
+ </init-param>
+
+
+ <!--
This parameter allows you to startup Cocoon2 immediately after startup
of your servlet engine.
-->
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]