Author: lukaszlenart
Date: Fri Sep  6 06:55:55 2013
New Revision: 1520499

URL: http://svn.apache.org/r1520499
Log:
WW-4103, WW-4191 Reduces noise in the logs when action/result is missing

Modified:
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java

Modified: 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java?rev=1520499&r1=1520498&r2=1520499&view=diff
==============================================================================
--- 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
 (original)
+++ 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
 Fri Sep  6 06:55:55 2013
@@ -568,18 +568,7 @@ public class Dispatcher {
                 
request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack);
             }
         } catch (ConfigurationException e) {
-               // WW-2874 Only log error if in devMode
-            if (devMode) {
-                String reqStr = request.getRequestURI();
-                if (request.getQueryString() != null) {
-                    reqStr = reqStr + "?" + request.getQueryString();
-                }
-                LOG.error("Could not find action or result\n" + reqStr, e);
-            } else {
-                if (LOG.isWarnEnabled()) {
-                    LOG.warn("Could not find action or result", e);
-                }
-            }
+            logConfigurationException(request, e);
             sendError(request, response, context, 
HttpServletResponse.SC_NOT_FOUND, e);
         } catch (Exception e) {
             if (handleException || devMode) {
@@ -593,6 +582,25 @@ public class Dispatcher {
     }
 
     /**
+     * Performs logging of missing action/result configuration exception
+     *
+     * @param request current {@link HttpServletRequest}
+     * @param e {@link ConfigurationException} that occurred
+     */
+    protected void logConfigurationException(HttpServletRequest request, 
ConfigurationException e) {
+        // WW-2874 Only log error if in devMode
+        String uri = request.getRequestURI();
+        if (request.getQueryString() != null) {
+            uri = uri + "?" + request.getQueryString();
+        }
+        if (devMode) {
+            LOG.error("Could not find action or result\n#0", e, uri);
+        } else if (LOG.isWarnEnabled()) {
+            LOG.warn("Could not find action or result: #0", e, uri);
+        }
+    }
+
+    /**
      * Create a context map containing all the wrapped request objects
      *
      * @param request The servlet request
@@ -889,11 +897,12 @@ public class Dispatcher {
             }
         } else {
             try {
-                if (LOG.isErrorEnabled()) {
-                    LOG.error("Exception occurred during processing request: 
#0", e, e.getMessage());
-                }
                 // WW-1977: Only put errors in the request when code is a 500 
error
                 if (code == HttpServletResponse.SC_INTERNAL_SERVER_ERROR) {
+                    // WW-4103: Only logs error when application error 
occurred, not Struts error
+                    if (LOG.isErrorEnabled()) {
+                        LOG.error("Exception occurred during processing 
request: #0", e, e.getMessage());
+                    }
                     // send a http error response to use the servlet defined 
error handler
                     // make the exception availible to the web.xml defined 
error page
                     request.setAttribute("javax.servlet.error.exception", e);


Reply via email to