nicolaken 2002/06/06 01:47:41 Modified: . Tag: cocoon_2_0_3_branch .cvsignore changes.xml todo.xml src/java/org/apache/cocoon/servlet Tag: cocoon_2_0_3_branch CocoonServlet.java src/java/org/apache/cocoon/components/notification Tag: cocoon_2_0_3_branch Notifier.java src/webapp/WEB-INF Tag: cocoon_2_0_3_branch 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> <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 notification info and the stream. It was added to the method using a ContentHandler, since it could output svg for example. The old methods were deprecated. </action> <action dev="NKB" type="fix" due-to="J.Pietschmann" due-to-email="[EMAIL PROTECTED]"> Fixed error reporting in CocoonServlet: stream is now closed at the end of the service method, the content-type is sent before sending the error and the notification messages are now more descriptive. </action> Revision Changes Path No revision No revision 1.5.2.1 +1 -0 xml-cocoon2/.cvsignore Index: .cvsignore =================================================================== RCS file: /home/cvs/xml-cocoon2/.cvsignore,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -r1.5 -r1.5.2.1 --- .cvsignore 24 Jan 2002 14:17:36 -0000 1.5 +++ .cvsignore 6 Jun 2002 08:47:40 -0000 1.5.2.1 @@ -2,4 +2,5 @@ dist tools/anttasks .ant.properties +prj.el 1.138.2.18 +22 -1 xml-cocoon2/changes.xml Index: changes.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/changes.xml,v retrieving revision 1.138.2.17 retrieving revision 1.138.2.18 diff -u -r1.138.2.17 -r1.138.2.18 --- changes.xml 5 Jun 2002 01:14:45 -0000 1.138.2.17 +++ changes.xml 6 Jun 2002 08:47:40 -0000 1.138.2.18 @@ -4,7 +4,7 @@ <!-- History of Cocoon changes - $Id: changes.xml,v 1.138.2.17 2002/06/05 01:14:45 vgritsenko Exp $ + $Id: changes.xml,v 1.138.2.18 2002/06/06 08:47:40 nicolaken Exp $ --> <changes title="History of Changes"> @@ -21,6 +21,7 @@ <person name="Vadim Gritsenko" email="[EMAIL PROTECTED]" id="VG"/> <person name="Christian Haul" email="[EMAIL PROTECTED]" id="CH"/> <person name="Bernhard Huber" email="[EMAIL PROTECTED]" id="BH"/> + <person name="Ivelin Ivanov" email="[EMAIL PROTECTED]" id="II"/> <person name="Berin Loritsch" email="[EMAIL PROTECTED]" id="BL"/> <person name="Stefano Mazzocchi" email="[EMAIL PROTECTED]" id="SM"/> <person name="Giacomo Pati" email="[EMAIL PROTECTED]" id="GP"/> @@ -33,6 +34,7 @@ <person name="Davanum Srinivas" email="[EMAIL PROTECTED]" id="DM"/> <person name="Sylvain Wallez" email="[EMAIL PROTECTED]" id="SW"/> <person name="Carsten Ziegeler" email="[EMAIL PROTECTED]" id="CZ"/> + <person name="John Morrison" email="[EMAIL PROTECTED]" id="JM"/> </devs> @@ -40,6 +42,24 @@ <action dev="VG" type="fix" fixes-bug="9539" due-to="Stuart Roebuck" due-to-email="[EMAIL PROTECTED]"> ResourceReader incorrectly advertised byte ranges support. </action> + <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 + notification info and the stream. + It was added to the method using a ContentHandler, since it could output svg for example. + The old methods were deprecated. + </action> + <action dev="NKB" type="fix" due-to="J.Pietschmann" due-to-email="[EMAIL PROTECTED]"> + Fixed error reporting in CocoonServlet: stream is now closed at the end of the service method, + the content-type is sent before sending the error and the notification messages are now more + descriptive. + </action> <action dev="VG" type="fix" fixes-bug="8639"> Support Parameterizable URLFactories. </action> @@ -1046,3 +1066,4 @@ </release> </changes> + 1.28.2.1 +21 -4 xml-cocoon2/todo.xml Index: todo.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/todo.xml,v retrieving revision 1.28 retrieving revision 1.28.2.1 diff -u -r1.28 -r1.28.2.1 --- todo.xml 27 Mar 2002 15:13:40 -0000 1.28 +++ todo.xml 6 Jun 2002 08:47:40 -0000 1.28.2.1 @@ -4,7 +4,7 @@ <!-- History of Cocoon changes - $Id: todo.xml,v 1.28 2002/03/27 15:13:40 sylvain Exp $ + $Id: todo.xml,v 1.28.2.1 2002/06/06 08:47:40 nicolaken Exp $ --> @@ -26,11 +26,28 @@ <person name="Davanum Srinivas" email="[EMAIL PROTECTED]" id="DM"/> <person name="Sylvain Wallez" email="[EMAIL PROTECTED]" id="SW"/> <person name="Carsten Ziegeler" email="[EMAIL PROTECTED]" id="CZ"/> - <person name="Volunteer needed" email="[EMAIL PROTECTED]" id="open"/> + <person name="Volunteer needed" email="[EMAIL PROTECTED]" id="open"/> </devs> <actions priority="high"> <action context="code" assigned-to="open"> + Rewrite the FilesystemStore. The current implementations relies on + a correct implementation of the toString() method of the used + keys. A correct version should rely on hashCode() and equals(). + (This is actually an Avalon action as the code is in Excalibur) + </action> + + <action context="code" assigned-to="open"> + Implement the smart-caching for the processing pipeline and + iron out bugs. + </action> + + <action context="docs" assigned-to="open"> + Attend to any high+ issues in the + <link href="plan/todo-doc.html">Documentation To Do List</link> + </action> + + <action context="code" assigned-to="open"> Correct the sitemap DTD which is now broken and make sitemap validated. </action> @@ -78,7 +95,7 @@ </action> <action context="code" assigned-to="NKB"> - Make all the examples in WIP work again, and finish refactoring. + Make all the samples in WIP (Work In Progress) work again, and finish refactoring. </action> </actions> @@ -103,7 +120,7 @@ One solution could be a configurable intermediate output stream. </action> - <action context="code"> + <action context="code" assigned-to="CZ"> Redesign pipeline configuration and management: (1) Move pipeline definitions from cocoon.xconf into sitemap.xmap, <map:components> section; and (2) allow usage of different pipeline implementations in No revision No revision 1.19.2.3 +100 -48 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.19.2.2 retrieving revision 1.19.2.3 diff -u -r1.19.2.2 -r1.19.2.3 --- CocoonServlet.java 22 May 2002 15:06:55 -0000 1.19.2.2 +++ CocoonServlet.java 6 Jun 2002 08:47:40 -0000 1.19.2.3 @@ -62,7 +62,6 @@ import org.apache.cocoon.Constants; import org.apache.cocoon.components.notification.Notifying; import org.apache.cocoon.components.notification.SimpleNotifyingBean; -import org.apache.cocoon.components.notification.NotifyingBuilder; import org.apache.cocoon.components.notification.DefaultNotifyingBuilder; import org.apache.cocoon.components.notification.Notifier; import org.apache.cocoon.components.request.RequestFactory; @@ -114,11 +113,11 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a> * (Apache Software Foundation, Exoffice Technologies) * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a> - * @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a> * @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.19.2.2 2002/05/22 15:06:55 vgritsenko Exp $ + * @version CVS $Id: CocoonServlet.java,v 1.19.2.3 2002/06/06 08:47:40 nicolaken Exp $ */ public class CocoonServlet extends HttpServlet { @@ -172,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. @@ -420,6 +425,14 @@ } } + 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(); } @@ -851,8 +864,6 @@ * If you need to force more than one class to load, then * separate each entry with whitespace, a comma, or a semi-colon. * Cocoon will strip any whitespace from the entry. - * - * @throws ServletException */ private void forceLoad() { if (this.forceLoadParameter != null) { @@ -882,8 +893,6 @@ * If you need to force more than one property to load, then * separate each entry with whitespace, a comma, or a semi-colon. * Cocoon will strip any whitespace from the entry. - * - * @throws ServletException */ private void forceProperty() { if (this.forceSystemProperty != null) { @@ -944,7 +953,8 @@ // Check if cocoon was initialized if (this.cocoon == null) { - res.setStatus(res.SC_INTERNAL_SERVER_ERROR); + if(manageExceptions){ + res.reset(); SimpleNotifyingBean n= new SimpleNotifyingBean(this); n.setType("fatal"); @@ -953,11 +963,21 @@ 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 String uri = request.getServletPath(); if (uri == null) { @@ -1014,30 +1034,41 @@ if (this.cocoon.process(env)) { contentType = env.getContentType(); } else { - // Should not get here! - // means SC_NOT_FOUND - res.sendError(res.SC_NOT_FOUND); + //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("Resource not found"); + n.setTitle("Cocoon confusion"); n.setSource("Cocoon servlet"); - n.setMessage("The requested resource not found."); - n.setDescription("The requested URI \"" - + request.getRequestURI() - + "\" was not found."); + 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); - // send the notification but don't include it in the output stream - // as the status SC_NOT_FOUND is enough - res.setContentType(Notifier.notify(n, (OutputStream)null)); + + 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); } - res.sendError(res.SC_NOT_FOUND); + if(manageExceptions){ + res.reset(); SimpleNotifyingBean n = new SimpleNotifyingBean(this); n.setType("resource-not-found"); @@ -1049,36 +1080,30 @@ + "\" 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()); - // send the notification but don't include it in the output stream - // as the status SC_NOT_FOUND is enough - res.setContentType(Notifier.notify(n, (OutputStream)null)); + + 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); } - SimpleNotifyingBean n = new SimpleNotifyingBean(this); - n.setType("error"); - 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); - // send the notification but don't include it in the output stream - // as the connection was reset anyway - res.setContentType(Notifier.notify(n, (OutputStream)null)); } catch (Exception e) { if (log.isErrorEnabled()) { - log.error("Problem with servlet", e); + log.error("Problem with Cocoon servlet", e); } - //res.setStatus(res.SC_INTERNAL_SERVER_ERROR); + + if(manageExceptions){ + res.reset(); HashMap extraDescriptions = new HashMap(3); extraDescriptions.put("request-uri", request.getRequestURI()); @@ -1090,7 +1115,17 @@ Notifying n=new DefaultNotifyingBuilder().build( this, e, "fatal","Internal server error","Cocoon servlet",null,null,extraDescriptions); - res.setContentType(contentType = 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, + "Internal server error."); + res.flushBuffer(); + return; + } } long end = System.currentTimeMillis(); @@ -1114,12 +1149,19 @@ out.print((hide) ? "<!-- " : "<p>"); out.print(timeString); out.println((hide) ? " -->" : "</p>"); - out.flush(); - out.close(); } } } finally { if (ctxMap != null) ctxMap.clear(); + try{ + ServletOutputStream out = res.getOutputStream(); + out.flush(); + out.close(); + } + catch(Exception e){ + log.error("Cocoon servlet threw an Exception while trying to close stream.", e); + } + } } @@ -1204,9 +1246,7 @@ Thread.currentThread().setContextClassLoader(this.classLoader); } catch (Exception e){} - this.appContext.put(Constants.CONTEXT_CLASS_LOADER, classLoader); - this.appContext.put(Constants.CONTEXT_CLASSPATH, this.getClassPath()); - + this.updateEnvironment(); this.forceLoad(); this.forceProperty(); @@ -1240,6 +1280,18 @@ this.disposeCocoon(); } } + + /** + * Method to update the environment before Cocoon instances are created. + * + * This is also useful if you wish to customize any of the 'protected' + * variables from this class before a Cocoon instance is built in a derivative + * of this class (eg. Cocoon Context). + */ + protected void updateEnvironment() throws ServletException { + this.appContext.put(Constants.CONTEXT_CLASS_LOADER, classLoader); + this.appContext.put(Constants.CONTEXT_CLASSPATH, getClassPath()); + } private String processTime(long time) throws IOException { No revision No revision 1.6.2.1 +40 -10 xml-cocoon2/src/java/org/apache/cocoon/components/notification/Notifier.java Index: Notifier.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/notification/Notifier.java,v retrieving revision 1.6 retrieving revision 1.6.2.1 diff -u -r1.6 -r1.6.2.1 --- Notifier.java 22 Feb 2002 07:00:10 -0000 1.6 +++ Notifier.java 6 Jun 2002 08:47:40 -0000 1.6.2.1 @@ -66,7 +66,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a> Aisa * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a> - * @version CVS $Id: Notifier.java,v 1.6 2002/02/22 07:00:10 cziegeler Exp $ + * @version CVS $Id: Notifier.java,v 1.6.2.1 2002/06/06 08:47:40 nicolaken Exp $ */ public class Notifier { @@ -77,11 +77,35 @@ * @param n The <code>Notifying</code> object * @param outputStream The output stream the notification is written to * This could be <code>null</code>. - * @return The content type for this notification - * (currently always text/html) + * @deprecated There is no way in which this method could understand what mime/type to use. Instead use void notify(Notifying n, OutputStream outputStream, String mimetype), where the mime/type is requested. + * @see notify(Notifying n, OutputStream outputStream, String mimetype) */ - public static String notify(Notifying n, - OutputStream outputStream) throws IOException { + public static String notify(Notifying n, OutputStream outputStream) throws IOException { + notify(n, outputStream, "text/html") ; + return "text/html"; + } + + /** + * Generate notification information as a response. + * The notification is directly written to the OutputStream. + * @param n The <code>Notifying</code> object + * @param outputStream The output stream the notification is written to + * This could be <code>null</code>. + */ + public static void notify(Notifying n, OutputStream outputStream, String mimetype) throws IOException { + //(NKB) FIXME should use error page templates, one per mime-type + // currently uses hardcoded html, should be used only as last resort. + notifyHTML(n, outputStream); + } + + /** + * Generate notification information as html. + * The notification is directly written to the OutputStream. + * @param n The <code>Notifying</code> object + * @param outputStream The output stream the notification is written to + * This could be <code>null</code>. + */ + private static void notifyHTML(Notifying n, OutputStream outputStream) throws IOException { StringBuffer sb = new StringBuffer(); @@ -93,7 +117,7 @@ sb.append("--></STYLE> "); sb.append("</head><body>"); sb.append("<h1>Cocoon 2 - ").append(n.getTitle()).append("</h1>"); - sb.append("<HR size=\"1\" noshade=\"noshade\">"); + sb.append("<hr size=\"1\" noshade=\"noshade\"/>"); sb.append("<p><b>type</b> ").append(n.getType()).append("</p>"); sb.append("<p><b>message</b> <u>").append(n.getMessage()).append("</u></p>"); sb.append("<p><b>description</b> <u>").append(n.getDescription()).append("</u></p>"); @@ -110,20 +134,26 @@ extraDescriptions.get(key)).append("</pre></p>"); } - sb.append("<HR size=\"1\" noshade>"); + sb.append("<hr size=\"1\" noshade=\"true\"/>"); sb.append("</body></html>"); if (outputStream != null) outputStream.write(sb.toString().getBytes()); - // FIXME (SM) how can we send the error with the proper content type? - - return "text/html"; } /** * Generate notification information in XML format. + * @deprecated Using a ContentHandler doesn't mean that a mimetype cannot be specified; it could be svg or + * @see notify(Notifying n, ContentHandler ch, String mimetype) */ public static void notify(Notifying n, ContentHandler ch) throws SAXException { + notify(n, ch, "text/xml"); + } + + /** + * Generate notification information in XML format. + */ + public static void notify(Notifying n, ContentHandler ch, String mimetype) throws SAXException { final String PREFIX = Constants.ERROR_NAMESPACE_PREFIX; final String URI = Constants.ERROR_NAMESPACE_URI; No revision No revision 1.8.2.2 +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.8.2.1 retrieving revision 1.8.2.2 diff -u -r1.8.2.1 -r1.8.2.2 --- web.xml 20 Apr 2002 08:12:36 -0000 1.8.2.1 +++ web.xml 6 Jun 2002 08:47:40 -0000 1.8.2.2 @@ -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]