Cedric et.al;

Enclosed are two proposed patches for the "swallowing exception"
behavior of taglib/tiles/InsertTag.java (Bugzilla #13279).  The first,
"InsertTagNoFuncChange.txt", does what I originally suggested: merely
move the real handling of processException to a method outside of the
inner class to a protected method in InsertTag where sub-classing and
overriding the default behavior can easily be done.  

The second patch ("InsertTagFuncChange.txt") does change the behavior by
only "swallowing" the exception when the log4j debug level is enabled
for the class.  If debug is not enabled, the exception will be wrapped
and "re-thrown" as the root cause of a JspException.  

I think the second alternative is the better one because a default
behavior of broadcasting exceptions on the web page is not particularly
desirable.  However, I will be happy if either alternative is applied

I have provided complete javadoc comments for both alternatives that you
may change as required.

Thank you,
Jay  


Index: InsertTag.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-struts/src/share/org/apache/struts/taglib/tiles/InsertTag.java,v
retrieving revision 1.10
diff -u -r1.10 InsertTag.java
--- InsertTag.java      1 Feb 2003 15:42:44 -0000       1.10
+++ InsertTag.java      3 Feb 2003 20:40:58 -0000
@@ -849,31 +849,13 @@
                        return EVAL_PAGE;
                }
                /**
-                * Process an exception.
-                * Depending of debug attribute, print full exception trace, or only
-                * its message in output page.
+                * Process an exception.  This method wraps call to 
+<code>processTileInsertException()</code>.
                 * @param ex Exception
                 * @param msg An additional message to show in console, and to 
propagate if we can't output exception.
+                 * @see #processTileInsertException(Throwable,String)
                 */
                protected void processException(Throwable ex, String msg) throws 
JspException {
-                       try {
-                               if (msg == null)
-                                       msg = ex.getMessage();
-
-                               if (log.isDebugEnabled()) { // show full trace
-                                       log.debug(msg, ex);
-                                       pageContext.getOut().println(msg);
-                                       ex.printStackTrace(new 
PrintWriter(pageContext.getOut(), true));
-                               } else { // show only message
-                                       pageContext.getOut().println(msg);
-                               } // end if
-                       } catch (IOException ioex) { // problems. Propagate original 
exception
-                               pageContext.setAttribute(
-                                       ComponentConstants.EXCEPTION_KEY,
-                                       ex,
-                                       PageContext.REQUEST_SCOPE);
-                               throw new JspException(msg);
-                       }
+                        processTileInsertException(ex,msg);
                }
        }
 
@@ -947,4 +929,47 @@
                        return EVAL_PAGE;
                }
        }
+
+
+    /** Handles exceptions generated during the insertion of a particular tile.
+     * The behavior implemented here is to print the exception information on the 
+page output not re-throw
+     * the exception. If the <code>log4j</code> debug level is set, stack trace 
+information will written to 
+     * page output along with the message.  <code>JspException</code> is only thrown 
+in the case of an 
+     * <code>IOException</code> generated while writing to the page output.  
+Sub-classes may override this 
+     * method if re-throwing the exception is desired.  For example:
+     * <pre>
+     *   protected void processTileInsertException(Throwable ex, String msg) throws 
+JspException {
+     *         if (msg == null)
+     *                 msg = ex.getMessage();
+     *         if (ex instanceof JspException) 
+     *                  throw (JspException) JspException;
+     *          throw new JspException(msg,ex);
+     *  }
+     * </pre>
+     * To implement your override, replace <code>tagclass</code> element entry under 
+the tag name 
+     * <code>insert</code> in <code>struts-tiles.tld</code> with the name of your 
+class. 
+     * @param ex <code>Exception</code> thrown.
+     * @param msg Error message, usually showing error context.
+     */
+     protected void processTileInsertException(Throwable ex, String msg) throws 
+JspException {
+               try {
+                       if (msg == null)
+                               msg = ex.getMessage();
+
+                       if (log.isDebugEnabled()) { // show full trace
+                               log.debug(msg, ex);
+                               pageContext.getOut().println(msg);
+                               ex.printStackTrace(new 
+PrintWriter(pageContext.getOut(), true));
+                       } else { // show only message
+                               pageContext.getOut().println(msg);
+                       } // end if
+               } catch (IOException ioex) { // problems. Propagate original exception
+                       pageContext.setAttribute(
+                               ComponentConstants.EXCEPTION_KEY,
+                               ex,
+                               PageContext.REQUEST_SCOPE);
+                       throw new JspException(msg);
+               }
+    }
+
 }
Index: InsertTag.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-struts/src/share/org/apache/struts/taglib/tiles/InsertTag.java,v
retrieving revision 1.10
diff -u -r1.10 InsertTag.java
--- InsertTag.java      1 Feb 2003 15:42:44 -0000       1.10
+++ InsertTag.java      3 Feb 2003 20:42:27 -0000
@@ -849,31 +849,13 @@
                        return EVAL_PAGE;
                }
                /**
-                * Process an exception.
-                * Depending of debug attribute, print full exception trace, or only
-                * its message in output page.
+                * Process an exception.  This method wraps call to 
+<code>processTileInsertException()</code>.
                 * @param ex Exception
                 * @param msg An additional message to show in console, and to 
propagate if we can't output exception.
+                 * @see #processTileInsertException(Throwable,String)
                 */
                protected void processException(Throwable ex, String msg) throws 
JspException {
-                       try {
-                               if (msg == null)
-                                       msg = ex.getMessage();
-
-                               if (log.isDebugEnabled()) { // show full trace
-                                       log.debug(msg, ex);
-                                       pageContext.getOut().println(msg);
-                                       ex.printStackTrace(new 
PrintWriter(pageContext.getOut(), true));
-                               } else { // show only message
-                                       pageContext.getOut().println(msg);
-                               } // end if
-                       } catch (IOException ioex) { // problems. Propagate original 
exception
-                               pageContext.setAttribute(
-                                       ComponentConstants.EXCEPTION_KEY,
-                                       ex,
-                                       PageContext.REQUEST_SCOPE);
-                               throw new JspException(msg);
-                       }
+                        processTileInsertException(ex,msg);
                }
        }
 
@@ -947,4 +929,38 @@
                        return EVAL_PAGE;
                }
        }
+
+
+    /** Handles exceptions generated during the insertion of a particular tile.  If 
+<code>log4j</code> debug
+     * level is <em>not</em> set, <code>JspException</code> will be thrown, wrapping
+     * the parameter exception as the root cause.  If the <code>log4j</code> debug 
+level is set, 
+     * the message and stack trace information will written to page output.  In the 
+latter case, 
+     * <code>JspException</code> wlll only be thrown if an <code>IOException</code> 
+is generated while 
+     * writing to the page output. 
+     * @param ex <code>Exception</code> thrown.
+     * @param msg Error message, usually showing error context.
+     * @throws JspException always when <code>log4j</code> debug level is not set, 
+wrapping the 
+     * parameter exception as the root cause.  
+     */
+     protected void processTileInsertException(Throwable ex, String msg) throws 
+JspException {
+               if (msg == null)
+                       msg = ex.getMessage();
+               pageContext.setAttribute(
+                               ComponentConstants.EXCEPTION_KEY,
+                               ex,
+                               PageContext.REQUEST_SCOPE);
+               if (log.isDebugEnabled()) { 
+                    log.debug(msg, ex);
+                     try {
+                       pageContext.getOut().println(msg);
+                       ex.printStackTrace(new PrintWriter(pageContext.getOut(), 
+true));
+                        return; // Swallow exception and continue
+                    } catch (IOException ioex) { // problems. Propagate original 
+exception
+                     }
+                }
+               if (ex instanceof JspException) 
+                      throw (JspException) ex;
+                throw new JspException(msg,ex);
+    }
+
 }

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

Reply via email to