nicolaken 2002/05/31 12:00:00 Modified: . changes.xml src/java/org/apache/cocoon/servlet CocoonServlet.java src/java/org/apache/cocoon/components/notification Notifier.java src/java/org/apache/cocoon/components/treeprocessor/sitemap PipelineNode.java Log: <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="Stephan Michels" 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 1.180 +13 -1 xml-cocoon2/changes.xml Index: changes.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/changes.xml,v retrieving revision 1.179 retrieving revision 1.180 diff -u -r1.179 -r1.180 --- changes.xml 31 May 2002 14:25:15 -0000 1.179 +++ changes.xml 31 May 2002 18:59:59 -0000 1.180 @@ -4,7 +4,7 @@ <!-- History of Cocoon changes - $Id: changes.xml,v 1.179 2002/05/31 14:25:15 vgritsenko Exp $ + $Id: changes.xml,v 1.180 2002/05/31 18:59:59 nicolaken Exp $ --> <changes title="History of Changes"> @@ -38,6 +38,18 @@ </devs> <release version="@version@" date="@date@"> + <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="Stephan Michels" 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> 1.24 +29 -37 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.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- CocoonServlet.java 22 May 2002 15:07:17 -0000 1.23 +++ CocoonServlet.java 31 May 2002 18:59:59 -0000 1.24 @@ -113,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.23 2002/05/22 15:07:17 vgritsenko Exp $ + * @version CVS $Id: CocoonServlet.java,v 1.24 2002/05/31 18:59:59 nicolaken Exp $ */ public class CocoonServlet extends HttpServlet { @@ -1009,31 +1009,27 @@ 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."); + 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"); } } catch (ResourceNotFoundException rse) { if (log.isWarnEnabled()) { log.warn("The resource was not found", rse); } - res.sendError(res.SC_NOT_FOUND); - SimpleNotifyingBean n = new SimpleNotifyingBean(this); n.setType("resource-not-found"); n.setTitle("Resource not found"); @@ -1047,33 +1043,20 @@ 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"); } 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); HashMap extraDescriptions = new HashMap(3); extraDescriptions.put("request-uri", request.getRequestURI()); @@ -1085,7 +1068,9 @@ 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"); } long end = System.currentTimeMillis(); @@ -1109,12 +1094,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); + } + } } 1.8 +28 -8 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.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- Notifier.java 17 May 2002 09:28:35 -0000 1.7 +++ Notifier.java 31 May 2002 19:00:00 -0000 1.8 @@ -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.7 2002/05/17 09:28:35 morrijr Exp $ + * @version CVS $Id: Notifier.java,v 1.8 2002/05/31 19:00:00 nicolaken Exp $ */ public class Notifier { @@ -77,11 +77,22 @@ * @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 { StringBuffer sb = new StringBuffer(); @@ -115,15 +126,21 @@ 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; @@ -179,4 +196,7 @@ ch.endDocument(); } } + + + 1.9 +4 -3 xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelineNode.java Index: PipelineNode.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelineNode.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- PipelineNode.java 29 May 2002 12:02:15 -0000 1.8 +++ PipelineNode.java 31 May 2002 19:00:00 -0000 1.9 @@ -77,7 +77,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a> * @author <a href="mailto:[EMAIL PROTECTED]">Gianugo Rabellino</a> * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: PipelineNode.java,v 1.8 2002/05/29 12:02:15 cziegeler Exp $ + * @version CVS $Id: PipelineNode.java,v 1.9 2002/05/31 19:00:00 nicolaken Exp $ */ public class PipelineNode extends AbstractParentProcessingNode @@ -219,7 +219,7 @@ // notifying-generator is added in HandleErrorsNode return node.invoke(env, errorContext); } catch (Exception subEx) { - getLogger().error("error notifier barfs", subEx); + getLogger().error("Error notifier is unable to notify the problem. Please check the logs. In the default webapp, look in the WEB-INF/logs dir.", subEx); return false; } finally { if (errorContext != null) { @@ -228,4 +228,5 @@ } } -} \ No newline at end of file +} +
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]