cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Philippe Lavoie <philippe.lav...@cactus.ca>
Subject RE: "internal problem handling" change suggestion
Date Wed, 26 Jan 2000 21:43:17 GMT
> -----Original Message-----
> From: Donald Ball [mailto:balld@webslingerZ.com]
> Sent: Wednesday, January 26, 2000 2:53 PM
> To: Cocoon-Dev (E-mail)
> Subject: Re: "internal problem handling" change suggestion
> 
> 
> On Wed, 26 Jan 2000, Pascal Houde wrote:
> 
> > When you specify the Cocoon engine to not handle errors internally
> > (handle.errors.internally property in the 
> cocoon.properties) it just sends
> > the error code to the web server. It would be useful to 
> send the stack trace
> > information as well when an exception is raised in 
> Engine.handle(req, res)
> > method. This results in having a call to 
> HttpServletResponse.sendError(int,
> > String) instead of the actual 
> HttpServletResponse.sendError(int) in the
> > Cocoon service method.
> > 
> > Could that be included in the next release?
> 
> Sounds good to me. +1 if you send in a patch. :)
> 

I hope it's ok if I send it for Pascal :)
Two files are modified, Cocoon.java and Utils.java
(it's just cleaner that way).

Phil 'May the source be with you'

*** Cocoon.java Sun Jan 02 20:39:41 2000
--- ../my-cocoon/Cocoon.java    Wed Jan 26 16:33:14 2000
***************
*** 147,165 ****
                      if (errorsInternally) {
                          Frontend.error(response, "File not found.", e);
                      } else {
!                         response.sendError(404);
                      }
                  } catch (Throwable t) {
                      if (errorsInternally) {
                          Frontend.error(response, "Error found handling the
request.", t)
;
                      } else {
!                         response.sendError(500);
                      }
                  }
              }
          }
      }
!
      /**
       * Method called to show the servlet status.
       */
--- 147,165 ----
                      if (errorsInternally) {
                          Frontend.error(response, "File not found.", e);
                      } else {
!                         response.sendError(404,
Utils.getStackTraceAsString(e));
                      }
                  } catch (Throwable t) {
                      if (errorsInternally) {
                          Frontend.error(response, "Error found handling the
request.", t)
;
                      } else {
!                         response.sendError(500,
Utils.getStackTraceAsString(t));
                      }
                  }
              }
          }
      }
!
      /**
       * Method called to show the servlet status.
       */
*** Utils.java  Wed Jan 26 16:17:24 2000
--- ../my-cocoon/Utils.java     Wed Jan 26 16:48:01 2000
***************
*** 251,254 ****
--- 251,265 ----
              return request.getPathTranslated().replace('\\','/');
          }
      }
+
+     /*
+       Returns the stack trace as a string
+     */
+     public static final String getStackTraceAsString(Throwable e) {
+       ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+       PrintWriter writer = new PrintWriter(bytes, true);
+       e.printStackTrace(writer);
+       return bytes.toString();
+     }
+
  }

Mime
View raw message