Author: yoavs Date: Mon Dec 25 06:06:34 2006 New Revision: 490149 URL: http://svn.apache.org/viewvc?view=rev&rev=490149 Log: Bugzilla 40241: catch Exceptions instead of Throwables in Default and SSI servlets, and log them better.
Modified: tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/servlets/DefaultServlet.java tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/ssi/SSIServlet.java tomcat/container/tc5.5.x/webapps/docs/changelog.xml Modified: tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/servlets/DefaultServlet.java URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/servlets/DefaultServlet.java?view=diff&rev=490149&r1=490148&r2=490149 ============================================================================== --- tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/servlets/DefaultServlet.java (original) +++ tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/servlets/DefaultServlet.java Mon Dec 25 06:06:34 2006 @@ -220,46 +220,65 @@ String value = null; try { value = getServletConfig().getInitParameter("debug"); - debug = Integer.parseInt(value); - } catch (Throwable t) { - ; + if (value != null) { + debug = Integer.parseInt(value); + } + } catch (Exception e) { + log("DefaultServlet.init: couldn't read debug from " + value); } + try { value = getServletConfig().getInitParameter("input"); - input = Integer.parseInt(value); - } catch (Throwable t) { - ; + if (value != null) { + input = Integer.parseInt(value); + } + } catch (Exception e) { + log("DefaultServlet.init: couldn't read input from " + value); } + try { value = getServletConfig().getInitParameter("listings"); - listings = (new Boolean(value)).booleanValue(); - } catch (Throwable t) { - ; + if (value != null) { + listings = (new Boolean(value)).booleanValue(); + } + } catch (Exception e) { + log("DefaultServlet.init: couldn't read listings from " + value); } + try { value = getServletConfig().getInitParameter("readonly"); - if (value != null) + if (value != null) { readOnly = (new Boolean(value)).booleanValue(); - } catch (Throwable t) { - ; + } + } catch (Exception e) { + log("DefaultServlet.init: couldn't read readonly from " + value); } + try { value = getServletConfig().getInitParameter("output"); - output = Integer.parseInt(value); - } catch (Throwable t) { - ; + if (value != null) { + output = Integer.parseInt(value); + } + } catch (Exception e) { + log("DefaultServlet.init: couldn't read output from " + value); } + try { value = getServletConfig().getInitParameter("sendfileSize"); - sendfileSize = Integer.parseInt(value) * 1024; - } catch (Throwable t) { - ; + if (value != null) { + sendfileSize = Integer.parseInt(value) * 1024; + } + } catch (Exception e) { + log("DefaultServlet.init: couldn't read sendfileSize from " + value); } + try { value = getServletConfig().getInitParameter("fileEncoding"); - fileEncoding = value; - } catch (Throwable t) { - ; + if (value != null) { + fileEncoding = value; + } + } catch (Exception e) { + log("DefaultServlet.init: couldn't read fileEncoding from " + value); } globalXsltFile = getServletConfig().getInitParameter("globalXsltFile"); @@ -284,6 +303,7 @@ } catch(ClassCastException e) { // Failed : Not the right type } + if (resources == null) { try { resources = @@ -1464,10 +1484,10 @@ return buffer.toString(); } - } catch(Throwable e) { - ; /* Should only be IOException or NamingException - * can be ignored - */ + } catch(IOException ioe) { + log("DefaultServlet.getReadme: IO exception: " + ioe.getMessage()); + } catch (NamingException ne) { + log("DefaultServlet.getReadme: Naming exception: " + ne.getMessage()); } } @@ -1488,10 +1508,10 @@ if (is!=null) return is; } - } catch(Throwable e) { - ; /* Should only be IOException or NamingException - * can be ignored - */ + } catch(IOException ioe) { + log("DefaultServlet.findXsltInputStream: IO exception: " + ioe.getMessage()); + } catch (NamingException ne) { + log("DefaultServlet.findXsltInputStream: Naming exception: " + ne.getMessage()); } } @@ -1509,15 +1529,17 @@ fis.read(b); return new ByteArrayInputStream(b); } - } catch(Throwable e) { - log("This shouldn't happen (?)...", e); + } catch(Exception e) { + log("DefaultServlet.findXsltInputStream: can't read " + + globalXsltFile); return null; } finally { try { if (fis!=null) fis.close(); - } catch(Throwable e){ - ; + } catch(Exception e) { + log("DefaultServlet.findXsltInputStream: " + + " exception closing input stream: " + e.getMessage()); } } } @@ -1772,14 +1794,15 @@ // Clean up the input stream try { istream.close(); - } catch (Throwable t) { - ; + } catch (Exception e) { + log("DefaultServlet.copy: exception closing input stream: " + + e.getMessage()); } // Rethrow any exception that has occurred - if (exception != null) + if (exception != null) { throw exception; - + } } @@ -1819,14 +1842,15 @@ // Clean up the reader try { reader.close(); - } catch (Throwable t) { - ; + } catch (Exception e) { + log("DefaultServlet.copy: exception closing reader: " + + e.getMessage()); } // Rethrow any exception that has occurred - if (exception != null) + if (exception != null) { throw exception; - + } } @@ -1854,14 +1878,15 @@ // Clean up the input stream try { istream.close(); - } catch (Throwable t) { - ; + } catch (Exception e) { + log("DefaultServlet.copy: exception closing input stream: " + + e.getMessage()); } // Rethrow any exception that has occurred - if (exception != null) + if (exception != null) { throw exception; - + } } @@ -1896,14 +1921,15 @@ // Clean up the input stream try { reader.close(); - } catch (Throwable t) { - ; + } catch (Exception e) { + log("DefaultServlet.copy: exception closing reader: " + + e.getMessage()); } // Rethrow any exception that has occurred - if (exception != null) + if (exception != null) { throw exception; - + } } @@ -1948,8 +1974,9 @@ try { istream.close(); - } catch (Throwable t) { - ; + } catch (Exception e) { + log("DefaultServlet.copy: exception closing input stream: " + + e.getMessage()); } } @@ -1958,9 +1985,9 @@ ostream.print("--" + mimeSeparation + "--"); // Rethrow any exception that has occurred - if (exception != null) + if (exception != null) { throw exception; - + } } @@ -2011,8 +2038,9 @@ try { reader.close(); - } catch (Throwable t) { - ; + } catch (Exception e) { + log("DefaultServlet.copy: exception closing reader: " + + e.getMessage()); } } @@ -2021,9 +2049,9 @@ writer.print("--" + mimeSeparation + "--"); // Rethrow any exception that has occurred - if (exception != null) + if (exception != null) { throw exception; - + } } Modified: tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/ssi/SSIServlet.java URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/ssi/SSIServlet.java?view=diff&rev=490149&r1=490148&r2=490149 ============================================================================== --- tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/ssi/SSIServlet.java (original) +++ tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/ssi/SSIServlet.java Mon Dec 25 06:06:34 2006 @@ -1,16 +1,21 @@ /* - * Copyright 1999,2004 The Apache Software Foundation. Licensed under the - * Apache License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of the License - * at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable - * law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the specific language - * governing permissions and limitations under the License. + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.catalina.ssi; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -25,6 +30,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.catalina.Globals; + /** * Servlet to process SSI requests within a webpage. Mapped to a path from * within web.xml. @@ -61,50 +67,64 @@ String value = null; try { value = getServletConfig().getInitParameter("debug"); - debug = Integer.parseInt(value); - } catch (Throwable t) { - ; + if (value != null) { + debug = Integer.parseInt(value); + } + } catch (Exception e) { + log("SSIServlet.init: error reading debug from " + value); } + try { value = getServletConfig().getInitParameter( "isVirtualWebappRelative"); - isVirtualWebappRelative = Integer.parseInt(value) > 0?true:false; - } catch (Throwable t) { - ; + if (value != null) { + isVirtualWebappRelative = Integer.parseInt(value) > 0?true:false; + } + } catch (Exception e) { + log("SSIServlet.init: error reading isVirtualWebappRelative from" + + value); } + try { value = getServletConfig().getInitParameter("expires"); - expires = Long.valueOf(value); + if (value != null) { + expires = Long.valueOf(value); + } } catch (NumberFormatException e) { expires = null; log("Invalid format for expires initParam; expected integer (seconds)"); - } catch (Throwable t) { - ; + } catch (Exception e) { + log("SSIServlet.init: error reading expires from " + value); } + try { value = getServletConfig().getInitParameter("buffered"); - buffered = Integer.parseInt(value) > 0?true:false; - } catch (Throwable t) { - ; + if (value != null) { + buffered = Integer.parseInt(value) > 0?true:false; + } + } catch (Exception e) { + log("SSIServlet.init: error reading buffered from " + value); } + try { inputEncoding = getServletConfig().getInitParameter("inputEncoding"); - } catch (Throwable t) { - ; + } catch (Exception e) { + log("SSIServlet.init: error reading inputEncoding: " + e.getMessage()); } + try { value = getServletConfig().getInitParameter("outputEncoding"); if (value != null) { outputEncoding = value; } - } catch (Throwable t) { - ; + } catch (Exception e) { + log("SSIServlet.init: error reading outputEncoding from " + value); } + if (debug > 0) log("SSIServlet.init() SSI invoker started with 'debug'=" + debug); } - /** * Process and forward the GET request to our <code>requestHandler()</code>* * @@ -229,4 +249,4 @@ res.getWriter().write(text); } } -} \ No newline at end of file +} Modified: tomcat/container/tc5.5.x/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/webapps/docs/changelog.xml?view=diff&rev=490149&r1=490148&r2=490149 ============================================================================== --- tomcat/container/tc5.5.x/webapps/docs/changelog.xml (original) +++ tomcat/container/tc5.5.x/webapps/docs/changelog.xml Mon Dec 25 06:06:34 2006 @@ -200,6 +200,10 @@ <bug>39402</bug>: Modify existing Vary HTTP header, rather than overwrite it, if it exists when using GZip compression. Patch by Matthew Cooke. (yoavs) </fix> + <fix> + <bug>40241</bug>: Catch Exceptions instead of Throwables in Default and SSI servlets. + Also improve relevant logging while we're at it. (yoavs) + </fix> </changelog> </subsection> <subsection name="Jasper"> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]