Improve logging of unhandled servlet exceptions by including the context name. For...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 7 Jul 2010 23:33:28 +0000 (23:33 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 7 Jul 2010 23:33:28 +0000 (23:33 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@961535 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/Globals.java
java/org/apache/catalina/core/LocalStrings.properties
java/org/apache/catalina/core/StandardWrapperValve.java
java/org/apache/jasper/Constants.java
java/org/apache/jasper/compiler/JavacErrorDetail.java
java/org/apache/jasper/servlet/JspServletWrapper.java
webapps/docs/changelog.xml

index 6f45f48..fb64253 100644 (file)
@@ -177,6 +177,12 @@ public final class Globals {
 
 
     /**
+     * Platform specific new line sequence.
+     */
+    public static final String NEWLINE = System.getProperty("line.separator");
+    
+    
+    /**
      * The request attribute under which the request URI of the included
      * servlet is stored on an included dispatcher request.
      */
index b1a794d..9a993b0 100644 (file)
@@ -226,7 +226,8 @@ standardWrapper.notContext=Parent container of a Wrapper must be a Context
 standardWrapper.notFound=Servlet {0} is not available
 standardWrapper.notServlet=Class {0} is not a Servlet
 standardWrapper.releaseFilters=Release filters exception for servlet {0}
-standardWrapper.serviceException=Servlet.service() for servlet {0} threw exception
+standardWrapper.serviceException=Servlet.service() for servlet [{0}] in context with path [{1}] threw exception
+standardWrapper.serviceExceptionRoot=Servlet.service() for servlet [{0}] in context with path [{1}] threw exception [{2}] with root cause
 standardWrapper.statusHeader=HTTP Status {0} - {1}
 standardWrapper.statusTitle=Tomcat Error Report
 standardWrapper.unavailable=Marking servlet {0} as unavailable
index e847dc8..9c65583 100644 (file)
@@ -253,14 +253,16 @@ final class StandardWrapperValve
             exception(request, response, e);
         } catch (IOException e) {
                request.removeAttribute(Globals.JSP_FILE_ATTR);
-            container.getLogger().error(sm.getString("standardWrapper.serviceException",
-                             wrapper.getName()), e);
+            container.getLogger().error(sm.getString(
+                    "standardWrapper.serviceException", wrapper.getName(),
+                    context.getName()), e);
             throwable = e;
             exception(request, response, e);
         } catch (UnavailableException e) {
                request.removeAttribute(Globals.JSP_FILE_ATTR);
-            container.getLogger().error(sm.getString("standardWrapper.serviceException",
-                             wrapper.getName()), e);
+            container.getLogger().error(sm.getString(
+                    "standardWrapper.serviceException", wrapper.getName(),
+                    context.getName()), e);
             //            throwable = e;
             //            exception(request, response, e);
             wrapper.unavailable(e);
@@ -281,15 +283,18 @@ final class StandardWrapperValve
                request.removeAttribute(Globals.JSP_FILE_ATTR);
             Throwable rootCause = StandardWrapper.getRootCause(e);
             if (!(rootCause instanceof ClientAbortException)) {
-                container.getLogger().error(sm.getString("standardWrapper.serviceException",
-                                 wrapper.getName()), rootCause);
+                container.getLogger().error(sm.getString(
+                        "standardWrapper.serviceExceptionRoot",
+                        wrapper.getName(), context.getName(), e.getMessage()),
+                        rootCause);
             }
             throwable = e;
             exception(request, response, e);
         } catch (Throwable e) {
             request.removeAttribute(Globals.JSP_FILE_ATTR);
-            container.getLogger().error(sm.getString("standardWrapper.serviceException",
-                             wrapper.getName()), e);
+            container.getLogger().error(sm.getString(
+                    "standardWrapper.serviceException", wrapper.getName(),
+                    context.getName()), e);
             throwable = e;
             exception(request, response, e);
         }
@@ -437,29 +442,34 @@ final class StandardWrapperValve
             exception(request, response, e);
         } catch (IOException e) {
             request.removeAttribute(Globals.JSP_FILE_ATTR);
-            container.getLogger().error(sm.getString("standardWrapper.serviceException",
-                             wrapper.getName()), e);
+            container.getLogger().error(sm.getString(
+                    "standardWrapper.serviceException", wrapper.getName(),
+                    context.getName()), e);
             throwable = e;
             exception(request, response, e);
         } catch (UnavailableException e) {
             request.removeAttribute(Globals.JSP_FILE_ATTR);
-            container.getLogger().error(sm.getString("standardWrapper.serviceException",
-                             wrapper.getName()), e);
+            container.getLogger().error(sm.getString(
+                    "standardWrapper.serviceException", wrapper.getName(),
+                    context.getName()), e);
             // Do not save exception in 'throwable', because we
             // do not want to do exception(request, response, e) processing
         } catch (ServletException e) {
             request.removeAttribute(Globals.JSP_FILE_ATTR);
             Throwable rootCause = StandardWrapper.getRootCause(e);
             if (!(rootCause instanceof ClientAbortException)) {
-                container.getLogger().error(sm.getString("standardWrapper.serviceException",
-                                 wrapper.getName()), rootCause);
+                container.getLogger().error(sm.getString(
+                        "standardWrapper.serviceExceptionRoot",
+                        wrapper.getName(), context.getName(), e.getMessage()),
+                        rootCause);
             }
             throwable = e;
             exception(request, response, e);
         } catch (Throwable e) {
             request.removeAttribute(Globals.JSP_FILE_ATTR);
-            container.getLogger().error(sm.getString("standardWrapper.serviceException",
-                             wrapper.getName()), e);
+            container.getLogger().error(sm.getString(
+                    "standardWrapper.serviceException", wrapper.getName(),
+                    context.getName()), e);
             throwable = e;
             exception(request, response, e);
         }
index e1da650..cea3a50 100644 (file)
@@ -97,6 +97,11 @@ public class Constants {
     public static final int MAX_POOL_SIZE = 5;
 
     /**
+     * Platform specific new line sequence.
+     */
+    public static final String NEWLINE = System.getProperty("line.separator");
+
+    /**
      * The query parameter that causes the JSP engine to just
      * pregenerated the servlet but not invoke it. 
      */
index 4042b06..6c6b96d 100644 (file)
@@ -25,6 +25,7 @@ import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.jasper.Constants;
 import org.apache.jasper.JspCompilationContext;
 
 /**
@@ -129,7 +130,7 @@ public class JavacErrorDetail {
                     fragment.append(i+1);
                     fragment.append(": ");
                     fragment.append(jspLines[i]);
-                    fragment.append("\n");
+                    fragment.append(Constants.NEWLINE);
                 }
                 jspExtract = fragment.toString();
     
index 78919b2..322528c 100644 (file)
@@ -30,6 +30,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.jsp.tagext.TagInfo;
 
+import org.apache.jasper.Constants;
 import org.apache.jasper.JasperException;
 import org.apache.jasper.JspCompilationContext;
 import org.apache.jasper.Options;
@@ -509,9 +510,10 @@ public class JspServletWrapper {
             if (options.getDisplaySourceFragment()) {
                 return new JasperException(Localizer.getMessage
                         ("jsp.exception", detail.getJspFileName(),
-                                "" + jspLineNumber) +
-                                "\n\n" + detail.getJspExtract() +
-                                "\n\nStacktrace:", ex);
+                                "" + jspLineNumber) + Constants.NEWLINE +
+                                Constants.NEWLINE + detail.getJspExtract() +
+                                Constants.NEWLINE + Constants.NEWLINE + 
+                                "Stacktrace:", ex);
                 
             }
 
index 9b30ea2..ebe9ea6 100644 (file)
         <bug>49551</bug>: Allow default context.xml location to be specified
         using an absolute path. (markt)
       </fix>
+      <add>
+        Improve logging of unhandled exceptions in servlets by including the
+        path of the context where the error occurred. (markt)
+      </add>
     </changelog>
   </subsection>
   <subsection name="Jasper">
         <bug>49217</bug>: Ensure that identifiers used in EL meet the
         requirements of the Java Language Specification. (markt)
       </fix>
+      <add>
+        Improve logging of JSP exceptions by including JSP snippet (if enabled)
+        rather than just the root cause in the host log. (markt)
+      </add>
     </changelog>
   </subsection>
   <subsection name="Cluster">