nbubna      2003/12/03 16:59:35

  Modified:    src/java/org/apache/velocity/tools/view/servlet
                        VelocityViewServlet.java
  Log:
  clean up error() output and handle MethodInvocationExceptions intelligently
  
  Revision  Changes    Path
  1.19      +23 -13    
jakarta-velocity-tools/src/java/org/apache/velocity/tools/view/servlet/VelocityViewServlet.java
  
  Index: VelocityViewServlet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity-tools/src/java/org/apache/velocity/tools/view/servlet/VelocityViewServlet.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- VelocityViewServlet.java  18 Nov 2003 00:52:29 -0000      1.18
  +++ VelocityViewServlet.java  4 Dec 2003 00:59:35 -0000       1.19
  @@ -667,40 +667,50 @@
        */
       protected void error(HttpServletRequest request, 
                            HttpServletResponse response, 
  -                         Exception cause)
  +                         Exception e)
           throws ServletException
       {
           try
           {
               StringBuffer html = new StringBuffer();
  -            html.append("<html>");
  -            html.append("<title>Error</title>");
  -            html.append("<body bgcolor=\"#ffffff\">");
  -            html.append("<h2>VelocityViewServlet : Error processing the 
template</h2>");
  -            html.append("<pre>");
  +            html.append("<html>\n");
  +            html.append("<head><title>Error</title></head>\n");
  +            html.append("<body>\n");
  +            html.append("<h2>VelocityViewServlet : Error processing the 
template</h2>\n");
  +
  +            Throwable cause = e;
  +
               String why = cause.getMessage();
               if (why != null && why.trim().length() > 0)
               {
                   html.append(why);
  -                html.append("<br>");
  +                html.append("\n<br>\n");
  +            }
  +
  +            // if it's an MIE, i want the real stack trace!
  +            if (cause instanceof MethodInvocationException) 
  +            {
  +                // get the real cause
  +                cause = ((MethodInvocationException)cause).getWrappedThrowable();
               }
   
               StringWriter sw = new StringWriter();
               cause.printStackTrace(new PrintWriter(sw));
   
  +            html.append("<pre>\n");
               html.append(sw.toString());
  -            html.append("</pre>");
  -            html.append("</body>");
  +            html.append("</pre>\n");
  +            html.append("</body>\n");
               html.append("</html>");
               getResponseWriter(response).write(html.toString());
           }
  -        catch (Exception e)
  +        catch (Exception e2)
           {
               // clearly something is quite wrong.
               // let's log the new exception then give up and
               // throw a servlet exception that wraps the first one
  -            Velocity.error("VelocityViewServlet: Exception while printing error 
screen: "+e);
  -            throw new ServletException(cause);
  +            Velocity.error("VelocityViewServlet: Exception while printing error 
screen: "+e2);
  +            throw new ServletException(e);
           }
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to