Commits

musachy  committed ff8e5c7

XW-659 Log exeception when calling methods using OGNL

Thanks to Gabriel Belingueres for the patch

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@1883e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits 18b77c2

Comments (0)

Files changed (1)

File src/java/com/opensymphony/xwork2/ognl/accessor/XWorkMethodAccessor.java

  */
 package com.opensymphony.xwork2.ognl.accessor;
 
-import com.opensymphony.xwork2.util.logging.Logger;
-import com.opensymphony.xwork2.util.logging.LoggerFactory;
-import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
-import ognl.*;
-
 import java.beans.PropertyDescriptor;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Map;
 
+import ognl.MethodFailedException;
+import ognl.ObjectMethodAccessor;
+import ognl.OgnlContext;
+import ognl.OgnlRuntime;
+import ognl.PropertyAccessor;
+
+import com.opensymphony.xwork2.util.logging.Logger;
+import com.opensymphony.xwork2.util.logging.LoggerFactory;
+import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
+
 
 /**
  * Allows methods to be executed under normal cirumstances, except when {@link ReflectionContextState#DENY_METHOD_EXECUTION}
             Boolean exec = (Boolean) context.get(ReflectionContextState.DENY_INDEXED_ACCESS_EXECUTION);
             boolean e = ((exec == null) ? false : exec.booleanValue());
             if (!e) {
-                return super.callMethod(context, object, string, objects);
+                return callMethodWithDebugInfo(context, object, string, objects);
             }
         }
         Boolean exec = (Boolean) context.get(ReflectionContextState.DENY_METHOD_EXECUTION);
         boolean e = ((exec == null) ? false : exec.booleanValue());
 
         if (!e) {
-            return super.callMethod(context, object, string, objects);
+            return callMethodWithDebugInfo(context, object, string, objects);
         } else {
             return null;
         }
     }
 
+	private Object callMethodWithDebugInfo(Map context, Object object, String methodName,
+			Object[] objects) throws MethodFailedException {
+		try {
+			return super.callMethod(context, object, methodName, objects);
+		}
+		catch(MethodFailedException e) {
+			if (LOG.isDebugEnabled()) {
+				if (!(e.getReason() instanceof NoSuchMethodException)) {
+					// the method exists on the target object, but something went wrong
+					String s = "Error calling method through OGNL: object: [#0] method: [#1] args: [#2]";
+					LOG.debug(s, e.getReason(), object.toString(), methodName, Arrays.toString(objects));
+				}
+			}
+			throw e;
+		}
+	}
+
     @Override
     public Object callStaticMethod(Map context, Class aClass, String string, Object[] objects) throws MethodFailedException {
         Boolean exec = (Boolean) context.get(ReflectionContextState.DENY_METHOD_EXECUTION);
         boolean e = ((exec == null) ? false : exec.booleanValue());
 
         if (!e) {
-            return super.callStaticMethod(context, aClass, string, objects);
+            return callStaticMethodWithDebugInfo(context, aClass, string, objects);
         } else {
             return null;
         }
     }
+
+	private Object callStaticMethodWithDebugInfo(Map context, Class aClass, String methodName,
+			Object[] objects) throws MethodFailedException {
+		try {
+			return super.callStaticMethod(context, aClass, methodName, objects);
+		}
+		catch(MethodFailedException e) {
+			if (LOG.isDebugEnabled()) {
+				if (!(e.getReason() instanceof NoSuchMethodException)) {
+					// the method exists on the target class, but something went wrong
+					String s = "Error calling method through OGNL, class: [#0] method: [#1] args: [#2]";
+					LOG.debug(s, e.getReason(), aClass.getName(), methodName, Arrays.toString(objects));
+				}
+			}
+			throw e;
+		}
+	}
 }