cziegeler 2002/07/15 06:41:40
Modified: src/java/org/apache/cocoon/servlet CocoonServlet.java
Log:
Corrected error handling
Revision Changes Path
1.31 +76 -83
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.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- CocoonServlet.java 13 Jul 2002 13:13:21 -0000 1.30
+++ CocoonServlet.java 15 Jul 2002 13:41:40 -0000 1.31
@@ -918,29 +918,27 @@
// Check if cocoon was initialized
if (this.cocoon == null) {
- if(manageExceptions){
- res.reset();
+ 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("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();
+ 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("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
@@ -1003,28 +1001,27 @@
log.fatalError("The Cocoon engine said it failed to process the
request for an unknown reason.");
if(manageExceptions){
- res.reset();
+ 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;
+ 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;
}
} catch (ResourceNotFoundException rse) {
@@ -1032,36 +1029,34 @@
log.warn("The resource was not found", rse);
}
- if(manageExceptions){
- res.reset();
+ 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 \""
+ 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);
+ 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");
- }
- else{
+ 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;
- }
+ }
+ return;
} catch (ConnectionResetException cre) {
if (log.isDebugEnabled()) {
log.debug("The connection was reset", cre);
- }
- else if (log.isWarnEnabled()) {
+ } else if (log.isWarnEnabled()) {
log.warn("The connection was reset.");
}
@@ -1070,30 +1065,29 @@
log.error("Problem with Cocoon servlet", e);
}
- if(manageExceptions){
- res.reset();
+ 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{
+ 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;
- }
+ }
+ return;
}
long end = System.currentTimeMillis();
@@ -1125,9 +1119,8 @@
ServletOutputStream out = res.getOutputStream();
out.flush();
out.close();
- }
- catch(Exception e){
- log.error("Cocoon servlet threw an Exception while trying to close
stream.", e);
+ } catch(Exception e) {
+ log.error("Cocoon servlet threw an Exception while trying to
close stream.", e);
}
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]