struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [2/3] struts git commit: WW-4105 Removes SpringUtils to ProxyUtil
Date Wed, 17 May 2017 17:49:33 GMT
WW-4105 Removes SpringUtils to ProxyUtil


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/9a8b4f4e
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/9a8b4f4e
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/9a8b4f4e

Branch: refs/heads/master
Commit: 9a8b4f4ebcb3787bef76198a7374bb5dcb69908e
Parents: c2f2de0
Author: Yasser Zamani <yasser.zamani@live.com>
Authored: Thu May 11 12:49:46 2017 +0430
Committer: Yasser Zamani <yasser.zamani@live.com>
Committed: Thu May 11 12:49:46 2017 +0430

----------------------------------------------------------------------
 .../xwork2/interceptor/ChainingInterceptor.java |  6 +-
 .../opensymphony/xwork2/spring/SpringUtils.java | 89 -------------------
 .../com/opensymphony/xwork2/util/ProxyUtil.java | 90 ++++++++++++++++++++
 .../xwork2/spring/SpringProxyUtilTest.java      | 85 ++++++++++++++++++
 .../xwork2/spring/SpringUtilsTest.java          | 84 ------------------
 5 files changed, 178 insertions(+), 176 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/9a8b4f4e/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java
b/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java
index b90e2b6..59b1d88 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java
@@ -20,7 +20,7 @@ import com.opensymphony.xwork2.ActionInvocation;
 import com.opensymphony.xwork2.Result;
 import com.opensymphony.xwork2.Unchainable;
 import com.opensymphony.xwork2.inject.Inject;
-import com.opensymphony.xwork2.spring.SpringUtils;
+import com.opensymphony.xwork2.util.ProxyUtil;
 import com.opensymphony.xwork2.util.CompoundRoot;
 import com.opensymphony.xwork2.util.TextParseUtil;
 import com.opensymphony.xwork2.util.ValueStack;
@@ -163,8 +163,8 @@ public class ChainingInterceptor extends AbstractInterceptor {
         for (Object object : list) {
             if (shouldCopy(object)) {
                 Object action = invocation.getAction();
-                if(SpringUtils.isAopProxy(action)) {
-                    action = SpringUtils.getUltimateTargetObject(action);
+                if(ProxyUtil.isSpringAopProxy(action)) {
+                    action = ProxyUtil.getSpringUltimateTargetObject(action);
                 }
                 reflectionProvider.copy(object, action, ctxMap, prepareExcludes(), includes);
             }

http://git-wip-us.apache.org/repos/asf/struts/blob/9a8b4f4e/core/src/main/java/com/opensymphony/xwork2/spring/SpringUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/spring/SpringUtils.java b/core/src/main/java/com/opensymphony/xwork2/spring/SpringUtils.java
deleted file mode 100644
index bb6584d..0000000
--- a/core/src/main/java/com/opensymphony/xwork2/spring/SpringUtils.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright 2017 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.
- */
-package com.opensymphony.xwork2.spring;
-
-import com.opensymphony.xwork2.util.ClassLoaderUtil;
-import org.apache.commons.lang3.reflect.MethodUtils;
-
-import java.lang.reflect.Proxy;
-
-/**
- * <code>SpringUtils</code>
- * <p>
- * Various utility methods dealing with spring framework
- * </p>
- *
- */
-public class SpringUtils {
-    /**
-     * Get the ultimate <em>target</em> object of the supplied {@code candidate}
-     * object, unwrapping not only a top-level proxy but also any number of
-     * nested proxies.
-     * <p>If the supplied {@code candidate} is a Spring proxy, the ultimate target
of all
-     * nested proxies will be returned; otherwise, the {@code candidate}
-     * will be returned <em>as is</em>.
-     * @param candidate the instance to check (potentially a Spring AOP proxy;
-     * never {@code null})
-     * @return the target object or the {@code candidate} (never {@code null})
-     * @throws IllegalStateException if an error occurs while unwrapping a proxy
-     */
-    public static <T> T getUltimateTargetObject(Object candidate) {
-        try {
-            if (isAopProxy(candidate) &&
-                    implementsInterface(candidate.getClass(), "org.springframework.aop.framework.Advised"))
{
-                Object targetSource = MethodUtils.invokeMethod(candidate, "getTargetSource");
-                Object target = MethodUtils.invokeMethod(targetSource, "getTarget");
-                return getUltimateTargetObject(target);
-            }
-        }
-        catch (Throwable ex) {
-            throw new IllegalStateException("Failed to unwrap proxied object", ex);
-        }
-        return (T) candidate;
-    }
-
-    /**
-     * Check whether the given object is a Spring proxy.
-     * @param object the object to check
-     */
-    public static boolean isAopProxy(Object object) {
-        Class<?> clazz = object.getClass();
-        return (implementsInterface(clazz, "org.springframework.aop.SpringProxy") &&
-                (Proxy.isProxyClass(clazz) || isCglibProxyClass(clazz)));
-    }
-
-    /**
-     * Check whether the specified class is a CGLIB-generated class.
-     * @param clazz the class to check
-     */
-    private static boolean isCglibProxyClass(Class<?> clazz) {
-        return (clazz != null && clazz.getName().contains("$$"));
-    }
-
-    /**
-     * Check whether the given class implements an interface with a given class name.
-     * @param clazz the class to check
-     * @param ifaceClassName the interface class name to check
-     */
-    private static boolean implementsInterface(Class<?> clazz, String ifaceClassName)
{
-        try {
-            Class ifaceClass = ClassLoaderUtil.loadClass(ifaceClassName, SpringUtils.class);
-            return ifaceClass.isAssignableFrom(clazz);
-        } catch (ClassNotFoundException e) {
-            return false;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/struts/blob/9a8b4f4e/core/src/main/java/com/opensymphony/xwork2/util/ProxyUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/util/ProxyUtil.java b/core/src/main/java/com/opensymphony/xwork2/util/ProxyUtil.java
new file mode 100644
index 0000000..6a8ac53
--- /dev/null
+++ b/core/src/main/java/com/opensymphony/xwork2/util/ProxyUtil.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2017 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.
+ */
+package com.opensymphony.xwork2.util;
+
+import org.apache.commons.lang3.reflect.MethodUtils;
+
+import java.lang.reflect.Proxy;
+
+/**
+ * <code>ProxyUtil</code>
+ * <p>
+ * Various utility methods dealing with proxies
+ * </p>
+ *
+ */
+public class ProxyUtil {
+    private static final String SPRING_ADVISED_CLASS_NAME = "org.springframework.aop.framework.Advised";
+    private static final String SPRING_SPRINGPROXY_CLASS_NAME = "org.springframework.aop.SpringProxy";
+
+    /**
+     * Get the ultimate <em>target</em> object of the supplied {@code candidate}
+     * object, unwrapping not only a top-level proxy but also any number of
+     * nested proxies.
+     * <p>If the supplied {@code candidate} is a Spring proxy, the ultimate target
of all
+     * nested proxies will be returned; otherwise, the {@code candidate}
+     * will be returned <em>as is</em>.
+     * @param candidate the instance to check (potentially a Spring AOP proxy;
+     * never {@code null})
+     * @return the target object or the {@code candidate} (never {@code null})
+     * @throws IllegalStateException if an error occurs while unwrapping a proxy
+     */
+    public static <T> T getSpringUltimateTargetObject(Object candidate) {
+        try {
+            if (isSpringAopProxy(candidate) && implementsInterface(candidate.getClass(),
SPRING_ADVISED_CLASS_NAME)) {
+                Object targetSource = MethodUtils.invokeMethod(candidate, "getTargetSource");
+                Object target = MethodUtils.invokeMethod(targetSource, "getTarget");
+                return getSpringUltimateTargetObject(target);
+            }
+        }
+        catch (Throwable ex) {
+            throw new IllegalStateException("Failed to unwrap proxied object", ex);
+        }
+        return (T) candidate;
+    }
+
+    /**
+     * Check whether the given object is a Spring proxy.
+     * @param object the object to check
+     */
+    public static boolean isSpringAopProxy(Object object) {
+        Class<?> clazz = object.getClass();
+        return (implementsInterface(clazz, SPRING_SPRINGPROXY_CLASS_NAME) && (Proxy.isProxyClass(clazz)
+                || isCglibProxyClass(clazz)));
+    }
+
+    /**
+     * Check whether the specified class is a CGLIB-generated class.
+     * @param clazz the class to check
+     */
+    private static boolean isCglibProxyClass(Class<?> clazz) {
+        return (clazz != null && clazz.getName().contains("$$"));
+    }
+
+    /**
+     * Check whether the given class implements an interface with a given class name.
+     * @param clazz the class to check
+     * @param ifaceClassName the interface class name to check
+     */
+    private static boolean implementsInterface(Class<?> clazz, String ifaceClassName)
{
+        try {
+            Class ifaceClass = ClassLoaderUtil.loadClass(ifaceClassName, ProxyUtil.class);
+            return ifaceClass.isAssignableFrom(clazz);
+        } catch (ClassNotFoundException e) {
+            return false;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/struts/blob/9a8b4f4e/core/src/test/java/com/opensymphony/xwork2/spring/SpringProxyUtilTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/spring/SpringProxyUtilTest.java b/core/src/test/java/com/opensymphony/xwork2/spring/SpringProxyUtilTest.java
new file mode 100644
index 0000000..9c047b8
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/spring/SpringProxyUtilTest.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2017 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.
+ */
+package com.opensymphony.xwork2.spring;
+
+import com.opensymphony.xwork2.*;
+import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
+import com.opensymphony.xwork2.util.ProxyUtil;
+import org.springframework.context.ApplicationContext;
+
+/**
+ * Test various utility methods dealing with spring proxies.
+ *
+ */
+public class SpringProxyUtilTest extends XWorkTestCase {
+    private ApplicationContext appContext;
+
+    @Override public void setUp() throws Exception {
+        super.setUp();
+
+        // Set up XWork
+        XmlConfigurationProvider provider = new XmlConfigurationProvider("com/opensymphony/xwork2/spring/actionContext-xwork.xml");
+        container.inject(provider);
+        loadConfigurationProviders(provider);
+        appContext = ((SpringObjectFactory)container.getInstance(ObjectFactory.class)).appContext;
+    }
+
+    public void testIsSpringAopProxy() throws Exception {
+        Object simpleAction = appContext.getBean("simple-action");
+        assertFalse(ProxyUtil.isSpringAopProxy(simpleAction));
+
+        Object proxiedAction = appContext.getBean("proxied-action");
+        assertTrue(ProxyUtil.isSpringAopProxy(proxiedAction));
+
+        Object autoProxiedAction = appContext.getBean("auto-proxied-action");
+        assertTrue(ProxyUtil.isSpringAopProxy(autoProxiedAction));
+
+        Object pointcuttedTestBean = appContext.getBean("pointcutted-test-bean");
+        assertTrue(ProxyUtil.isSpringAopProxy(pointcuttedTestBean));
+
+        Object pointcuttedTestSubBean = appContext.getBean("pointcutted-test-sub-bean");
+        assertTrue(ProxyUtil.isSpringAopProxy(pointcuttedTestSubBean));
+
+        Object aspectedTestSubBean = appContext.getBean("aspected-test-sub-bean");
+        assertFalse(ProxyUtil.isSpringAopProxy(aspectedTestSubBean));
+    }
+
+    public void testGetSpringUltimateTargetObject() throws Exception {
+        Object simpleAction = appContext.getBean("simple-action");
+        Object simpleActionUltimateTargetObject = ProxyUtil.getSpringUltimateTargetObject(simpleAction);
+        assertEquals(simpleAction, simpleActionUltimateTargetObject);
+
+        Object proxiedAction = appContext.getBean("proxied-action");
+        Object proxiedActionUltimateTargetObject = ProxyUtil.getSpringUltimateTargetObject(proxiedAction);
+        assertEquals(SimpleAction.class, proxiedActionUltimateTargetObject.getClass());
+
+        Object autoProxiedAction = appContext.getBean("auto-proxied-action");
+        Object autoProxiedActionUltimateTargetObject = ProxyUtil.getSpringUltimateTargetObject(autoProxiedAction);
+        assertEquals(SimpleAction.class, autoProxiedActionUltimateTargetObject.getClass());
+
+        Object pointcuttedTestBean = appContext.getBean("pointcutted-test-bean");
+        Object pointcuttedTestBeanUltimateTargetObject = ProxyUtil.getSpringUltimateTargetObject(pointcuttedTestBean);
+        assertEquals(TestBean.class, pointcuttedTestBeanUltimateTargetObject.getClass());
+
+        Object pointcuttedTestSubBean = appContext.getBean("pointcutted-test-sub-bean");
+        Object pointcuttedTestSubBeanUltimateTargetObject = ProxyUtil.getSpringUltimateTargetObject(pointcuttedTestSubBean);
+        assertEquals(TestSubBean.class, pointcuttedTestSubBeanUltimateTargetObject.getClass());
+
+        Object aspectedTestSubBean = appContext.getBean("aspected-test-sub-bean");
+        Object aspectedTestSubBeanUltimateTargetObject = ProxyUtil.getSpringUltimateTargetObject(aspectedTestSubBean);
+        assertEquals(aspectedTestSubBean, aspectedTestSubBeanUltimateTargetObject);
+    }
+}

http://git-wip-us.apache.org/repos/asf/struts/blob/9a8b4f4e/core/src/test/java/com/opensymphony/xwork2/spring/SpringUtilsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/spring/SpringUtilsTest.java b/core/src/test/java/com/opensymphony/xwork2/spring/SpringUtilsTest.java
deleted file mode 100644
index 7a1e0d7..0000000
--- a/core/src/test/java/com/opensymphony/xwork2/spring/SpringUtilsTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright 2017 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.
- */
-package com.opensymphony.xwork2.spring;
-
-import com.opensymphony.xwork2.*;
-import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
-import org.springframework.context.ApplicationContext;
-
-/**
- * Test various utility methods dealing with spring framework.
- *
- */
-public class SpringUtilsTest extends XWorkTestCase {
-    private ApplicationContext appContext;
-
-    @Override public void setUp() throws Exception {
-        super.setUp();
-
-        // Set up XWork
-        XmlConfigurationProvider provider = new XmlConfigurationProvider("com/opensymphony/xwork2/spring/actionContext-xwork.xml");
-        container.inject(provider);
-        loadConfigurationProviders(provider);
-        appContext = ((SpringObjectFactory)container.getInstance(ObjectFactory.class)).appContext;
-    }
-
-    public void testIsAopProxy() throws Exception {
-        Object simpleAction = appContext.getBean("simple-action");
-        assertFalse(SpringUtils.isAopProxy(simpleAction));
-
-        Object proxiedAction = appContext.getBean("proxied-action");
-        assertTrue(SpringUtils.isAopProxy(proxiedAction));
-
-        Object autoProxiedAction = appContext.getBean("auto-proxied-action");
-        assertTrue(SpringUtils.isAopProxy(autoProxiedAction));
-
-        Object pointcuttedTestBean = appContext.getBean("pointcutted-test-bean");
-        assertTrue(SpringUtils.isAopProxy(pointcuttedTestBean));
-
-        Object pointcuttedTestSubBean = appContext.getBean("pointcutted-test-sub-bean");
-        assertTrue(SpringUtils.isAopProxy(pointcuttedTestSubBean));
-
-        Object aspectedTestSubBean = appContext.getBean("aspected-test-sub-bean");
-        assertFalse(SpringUtils.isAopProxy(aspectedTestSubBean));
-    }
-
-    public void testGetUltimateTargetObject() throws Exception {
-        Object simpleAction = appContext.getBean("simple-action");
-        Object simpleActionUltimateTargetObject = SpringUtils.getUltimateTargetObject(simpleAction);
-        assertEquals(simpleAction, simpleActionUltimateTargetObject);
-
-        Object proxiedAction = appContext.getBean("proxied-action");
-        Object proxiedActionUltimateTargetObject = SpringUtils.getUltimateTargetObject(proxiedAction);
-        assertEquals(SimpleAction.class, proxiedActionUltimateTargetObject.getClass());
-
-        Object autoProxiedAction = appContext.getBean("auto-proxied-action");
-        Object autoProxiedActionUltimateTargetObject = SpringUtils.getUltimateTargetObject(autoProxiedAction);
-        assertEquals(SimpleAction.class, autoProxiedActionUltimateTargetObject.getClass());
-
-        Object pointcuttedTestBean = appContext.getBean("pointcutted-test-bean");
-        Object pointcuttedTestBeanUltimateTargetObject = SpringUtils.getUltimateTargetObject(pointcuttedTestBean);
-        assertEquals(TestBean.class, pointcuttedTestBeanUltimateTargetObject.getClass());
-
-        Object pointcuttedTestSubBean = appContext.getBean("pointcutted-test-sub-bean");
-        Object pointcuttedTestSubBeanUltimateTargetObject = SpringUtils.getUltimateTargetObject(pointcuttedTestSubBean);
-        assertEquals(TestSubBean.class, pointcuttedTestSubBeanUltimateTargetObject.getClass());
-
-        Object aspectedTestSubBean = appContext.getBean("aspected-test-sub-bean");
-        Object aspectedTestSubBeanUltimateTargetObject = SpringUtils.getUltimateTargetObject(aspectedTestSubBean);
-        assertEquals(aspectedTestSubBean, aspectedTestSubBeanUltimateTargetObject);
-    }
-}


Mime
View raw message