struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [1/2] struts git commit: Inject Container in constructor of the ObjectFactory
Date Thu, 03 Aug 2017 07:01:37 GMT
Repository: struts
Updated Branches:
  refs/heads/master 8216ec1c4 -> 81718c62b


Inject Container in constructor of the ObjectFactory


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

Branch: refs/heads/master
Commit: 6f91d0776a545c911ca4f2875ed9976614711ef9
Parents: f5ade7d
Author: Aleksandr Mashchenko <amashchenko@apache.org>
Authored: Thu Jul 27 22:22:33 2017 +0300
Committer: Aleksandr Mashchenko <amashchenko@apache.org>
Committed: Thu Jul 27 22:22:33 2017 +0300

----------------------------------------------------------------------
 .../java/com/opensymphony/xwork2/ObjectFactory.java     | 12 ++++++------
 .../opensymphony/xwork2/spring/SpringObjectFactory.java |  6 ++++++
 .../xwork2/spring/SpringProxyableObjectFactory.java     |  8 ++++++++
 .../spring/interceptor/ActionAutowiringInterceptor.java |  2 +-
 .../com/opensymphony/xwork2/ProxyObjectFactory.java     |  8 ++++++++
 .../interceptor/ScopedModelDrivenInterceptorTest.java   |  2 +-
 .../org/apache/struts2/dispatcher/DispatcherTest.java   |  8 ++++++--
 .../java/org/apache/struts2/cdi/CdiObjectFactory.java   |  6 ++++--
 .../org/apache/struts2/cdi/CdiObjectFactoryTest.java    |  6 +++---
 .../convention/PackageBasedActionConfigBuilderTest.java |  9 ++++++---
 .../apache/struts2/osgi/DelegatingObjectFactory.java    |  5 +++++
 .../apache/struts2/osgi/SpringOsgiObjectFactory.java    |  6 ++++++
 .../org/apache/struts2/plexus/PlexusObjectFactory.java  |  6 ++++++
 .../struts2/spring/StrutsSpringObjectFactory.java       |  2 +-
 14 files changed, 67 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/6f91d077/core/src/main/java/com/opensymphony/xwork2/ObjectFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/ObjectFactory.java b/core/src/main/java/com/opensymphony/xwork2/ObjectFactory.java
index c5ffbb9..652ef94 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ObjectFactory.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ObjectFactory.java
@@ -49,7 +49,7 @@ public class ObjectFactory implements Serializable {
     private static final Logger LOG = LogManager.getLogger(ObjectFactory.class);
 
     private transient ClassLoader ccl;
-    private Container container;
+    private final Container container;
 
     private ActionFactory actionFactory;
     private ResultFactory resultFactory;
@@ -58,15 +58,15 @@ public class ObjectFactory implements Serializable {
     private ConverterFactory converterFactory;
     private UnknownHandlerFactory unknownHandlerFactory;
 
+    @Inject
+    public ObjectFactory(Container container) {
+        this.container = container;
+    }
+
     @Inject(value="objectFactory.classloader", required=false)
     public void setClassLoader(ClassLoader cl) {
         this.ccl = cl;
     }
-    
-    @Inject
-    public void setContainer(Container container) {
-        this.container = container;
-    }
 
     @Inject
     public void setActionFactory(ActionFactory actionFactory) {

http://git-wip-us.apache.org/repos/asf/struts/blob/6f91d077/core/src/main/java/com/opensymphony/xwork2/spring/SpringObjectFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/spring/SpringObjectFactory.java b/core/src/main/java/com/opensymphony/xwork2/spring/SpringObjectFactory.java
index 51a4751..fffb037 100644
--- a/core/src/main/java/com/opensymphony/xwork2/spring/SpringObjectFactory.java
+++ b/core/src/main/java/com/opensymphony/xwork2/spring/SpringObjectFactory.java
@@ -16,6 +16,7 @@
 package com.opensymphony.xwork2.spring;
 
 import com.opensymphony.xwork2.ObjectFactory;
+import com.opensymphony.xwork2.inject.Container;
 import com.opensymphony.xwork2.inject.Inject;
 import org.apache.commons.lang3.BooleanUtils;
 import org.apache.logging.log4j.LogManager;
@@ -72,6 +73,11 @@ public class SpringObjectFactory extends ObjectFactory implements ApplicationCon
         this.enableAopSupport = BooleanUtils.toBoolean(enableAopSupport);
     }
 
+    @Inject
+    public SpringObjectFactory(Container container) {
+        super(container);
+    }
+
     /**
      * Set the Spring ApplicationContext that should be used to look beans up with.
      *

http://git-wip-us.apache.org/repos/asf/struts/blob/6f91d077/core/src/main/java/com/opensymphony/xwork2/spring/SpringProxyableObjectFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/spring/SpringProxyableObjectFactory.java
b/core/src/main/java/com/opensymphony/xwork2/spring/SpringProxyableObjectFactory.java
index ced7516..b6ec986 100644
--- a/core/src/main/java/com/opensymphony/xwork2/spring/SpringProxyableObjectFactory.java
+++ b/core/src/main/java/com/opensymphony/xwork2/spring/SpringProxyableObjectFactory.java
@@ -23,6 +23,9 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
 import org.springframework.beans.factory.support.RootBeanDefinition;
 import org.springframework.context.ApplicationContext;
 
+import com.opensymphony.xwork2.inject.Container;
+import com.opensymphony.xwork2.inject.Inject;
+
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -38,6 +41,11 @@ public class SpringProxyableObjectFactory extends SpringObjectFactory {
 
     private List<String> skipBeanNames = new ArrayList<>();
 
+    @Inject
+    public SpringProxyableObjectFactory(Container container) {
+        super(container);
+    }
+
     @Override
     public Object buildBean(String beanName, Map<String, Object> extraContext) throws
Exception {
         LOG.debug("Building bean for name {}", beanName);

http://git-wip-us.apache.org/repos/asf/struts/blob/6f91d077/core/src/main/java/com/opensymphony/xwork2/spring/interceptor/ActionAutowiringInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/spring/interceptor/ActionAutowiringInterceptor.java
b/core/src/main/java/com/opensymphony/xwork2/spring/interceptor/ActionAutowiringInterceptor.java
index 1628678..b3de475 100644
--- a/core/src/main/java/com/opensymphony/xwork2/spring/interceptor/ActionAutowiringInterceptor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/spring/interceptor/ActionAutowiringInterceptor.java
@@ -106,7 +106,7 @@ public class ActionAutowiringInterceptor extends AbstractInterceptor implements
                 LOG.warn("ApplicationContext could not be found.  Action classes will not
be autowired.");
             } else {
                 setApplicationContext(applicationContext);
-                factory = new SpringObjectFactory();
+                factory = new SpringObjectFactory(ActionContext.getContext().getContainer());
                 factory.setApplicationContext(getApplicationContext());
                 if (autowireStrategy != null) {
                     factory.setAutowireStrategy(autowireStrategy);

http://git-wip-us.apache.org/repos/asf/struts/blob/6f91d077/core/src/test/java/com/opensymphony/xwork2/ProxyObjectFactory.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/ProxyObjectFactory.java b/core/src/test/java/com/opensymphony/xwork2/ProxyObjectFactory.java
index 37821c8..93200ae 100644
--- a/core/src/test/java/com/opensymphony/xwork2/ProxyObjectFactory.java
+++ b/core/src/test/java/com/opensymphony/xwork2/ProxyObjectFactory.java
@@ -5,11 +5,19 @@ import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.util.Map;
 
+import com.opensymphony.xwork2.inject.Container;
+import com.opensymphony.xwork2.inject.Inject;
+
 /**
  * ObjectFactory that returns a FooProxy in the buildBean if the clazz is FooAction 
  */
 public class ProxyObjectFactory extends ObjectFactory {
 
+    @Inject
+    public ProxyObjectFactory(Container container) {
+        super(container);
+    }
+
     /**
      * It returns an instance of the bean except if the class is FooAction. 
      * In this case, it returns a FooProxy of it.

http://git-wip-us.apache.org/repos/asf/struts/blob/6f91d077/core/src/test/java/com/opensymphony/xwork2/interceptor/ScopedModelDrivenInterceptorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/interceptor/ScopedModelDrivenInterceptorTest.java
b/core/src/test/java/com/opensymphony/xwork2/interceptor/ScopedModelDrivenInterceptorTest.java
index 9413f75..4f44aa2 100644
--- a/core/src/test/java/com/opensymphony/xwork2/interceptor/ScopedModelDrivenInterceptorTest.java
+++ b/core/src/test/java/com/opensymphony/xwork2/interceptor/ScopedModelDrivenInterceptorTest.java
@@ -36,7 +36,7 @@ public class ScopedModelDrivenInterceptorTest extends XWorkTestCase {
     public void setUp() throws Exception {
         super.setUp();
         inter = new ScopedModelDrivenInterceptor();
-        inter.setObjectFactory(new ProxyObjectFactory());
+        inter.setObjectFactory(new ProxyObjectFactory(container));
     }
 
     public void testResolveModel() throws Exception {

http://git-wip-us.apache.org/repos/asf/struts/blob/6f91d077/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java b/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java
index 4f043cb..b920dcc 100644
--- a/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java
+++ b/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java
@@ -221,7 +221,6 @@ public class DispatcherTest extends StrutsInternalTestCase {
     
     public void testObjectFactoryDestroy() throws Exception {
 
-        final InnerDestroyableObjectFactory destroyedObjectFactory = new InnerDestroyableObjectFactory();
         ConfigurationManager cm = new ConfigurationManager(Container.DEFAULT_NAME);
         Dispatcher du = new MockDispatcher(new MockServletContext(), new HashMap<String,
String>(), cm);
         Mock mockConfiguration = new Mock(Configuration.class);
@@ -231,6 +230,7 @@ public class DispatcherTest extends StrutsInternalTestCase {
         String reloadConfigs = container.getInstance(String.class, XWorkConstants.RELOAD_XML_CONFIGURATION);
         mockContainer.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(XWorkConstants.RELOAD_XML_CONFIGURATION)),
                 reloadConfigs);
+        final InnerDestroyableObjectFactory destroyedObjectFactory = new InnerDestroyableObjectFactory((Container)
mockContainer.proxy());
         mockContainer.expectAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), destroyedObjectFactory);
 
         mockConfiguration.expectAndReturn("getContainer", mockContainer.proxy());
@@ -261,7 +261,7 @@ public class DispatcherTest extends StrutsInternalTestCase {
         packageConfigs.put("test", packageConfig);
 
         Mock mockContainer = new Mock(Container.class);
-        mockContainer.matchAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), new
ObjectFactory());
+        mockContainer.matchAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), new
ObjectFactory((Container) mockContainer.proxy()));
         String reloadConfigs = container.getInstance(String.class, XWorkConstants.RELOAD_XML_CONFIGURATION);
         mockContainer.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(XWorkConstants.RELOAD_XML_CONFIGURATION)),
                 reloadConfigs);
@@ -316,6 +316,10 @@ public class DispatcherTest extends StrutsInternalTestCase {
     public static class InnerDestroyableObjectFactory extends ObjectFactory implements ObjectFactoryDestroyable
{
         public boolean destroyed = false;
 
+        public InnerDestroyableObjectFactory(Container container) {
+            super(container);
+        }
+
         public void destroy() {
             destroyed = true;
         }

http://git-wip-us.apache.org/repos/asf/struts/blob/6f91d077/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java
----------------------------------------------------------------------
diff --git a/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java b/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java
index 91601b3..b26581c 100644
--- a/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java
+++ b/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java
@@ -20,6 +20,7 @@
 package org.apache.struts2.cdi;
 
 import com.opensymphony.xwork2.ObjectFactory;
+import com.opensymphony.xwork2.inject.Container;
 import com.opensymphony.xwork2.inject.Inject;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -73,8 +74,9 @@ public class CdiObjectFactory extends ObjectFactory {
 
     Map<Class<?>, InjectionTarget<?>> injectionTargetCache = new ConcurrentHashMap<Class<?>,
InjectionTarget<?>>();
 
-    public CdiObjectFactory() {
-        super();
+    @Inject
+    public CdiObjectFactory(Container container) {
+        super(container);
         LOG.info("Initializing Struts2 CDI integration...");
         this.beanManager = findBeanManager();
         if (beanManager != null) {

http://git-wip-us.apache.org/repos/asf/struts/blob/6f91d077/plugins/cdi/src/test/java/org/apache/struts2/cdi/CdiObjectFactoryTest.java
----------------------------------------------------------------------
diff --git a/plugins/cdi/src/test/java/org/apache/struts2/cdi/CdiObjectFactoryTest.java b/plugins/cdi/src/test/java/org/apache/struts2/cdi/CdiObjectFactoryTest.java
index f35ac55..74c6f02 100644
--- a/plugins/cdi/src/test/java/org/apache/struts2/cdi/CdiObjectFactoryTest.java
+++ b/plugins/cdi/src/test/java/org/apache/struts2/cdi/CdiObjectFactoryTest.java
@@ -27,19 +27,19 @@ public class CdiObjectFactoryTest {
 
     @Test
     public void testFindBeanManager() throws Exception {
-        assertNotNull(new CdiObjectFactory().findBeanManager());
+        assertNotNull(new CdiObjectFactory(null).findBeanManager());
     }
 
     @Test
     public void testGetBean() throws Exception {
-        final CdiObjectFactory cdiObjectFactory = new CdiObjectFactory();
+        final CdiObjectFactory cdiObjectFactory = new CdiObjectFactory(null);
         FooConsumer fooConsumer = (FooConsumer) cdiObjectFactory.buildBean(FooConsumer.class.getCanonicalName(),
null, false);
         assertNotNull(fooConsumer);
         assertNotNull(fooConsumer.fooService);
     }
 
     @Test public void testGetInjectionTarget() throws Exception {
-        final CdiObjectFactory cdiObjectFactory = new CdiObjectFactory();
+        final CdiObjectFactory cdiObjectFactory = new CdiObjectFactory(null);
         final InjectionTarget<?> injectionTarget = cdiObjectFactory.getInjectionTarget(FooConsumer.class);
         assertNotNull(injectionTarget);
         assertTrue(cdiObjectFactory.injectionTargetCache.containsKey(FooConsumer.class));

http://git-wip-us.apache.org/repos/asf/struts/blob/6f91d077/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java
----------------------------------------------------------------------
diff --git a/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java
b/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java
index dfa1ad6..f6bbbcc 100644
--- a/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java
+++ b/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java
@@ -338,7 +338,7 @@ public class PackageBasedActionConfigBuilderTest extends TestCase {
         configuration.addPackageConfig("class-level", classLevelParentPkg);
 
         ActionNameBuilder actionNameBuilder = new SEOActionNameBuilder("true", "-");
-        ObjectFactory of = new ObjectFactory();
+        ObjectFactory of = new ObjectFactory(mockContainer);
         DefaultInterceptorMapBuilder interceptorBuilder = new DefaultInterceptorMapBuilder();
         interceptorBuilder.setConfiguration(configuration);
 
@@ -778,8 +778,9 @@ public class PackageBasedActionConfigBuilderTest extends TestCase {
                 if (type == FileManagerFactory.class) {
                     return (T) fileManagerFactory;
                 }
-                T obj = type.newInstance();
-                if (obj instanceof ObjectFactory) {
+                T obj;
+                if (type == ObjectFactory.class) {
+                    obj = type.getConstructor(Container.class).newInstance(this);
                     OgnlReflectionProvider rp = new OgnlReflectionProvider() {
 
                         @Override
@@ -809,6 +810,8 @@ public class PackageBasedActionConfigBuilderTest extends TestCase {
 
                     ((ObjectFactory) obj).setInterceptorFactory(dif);
                     ((ObjectFactory) obj).setResultFactory(drf);
+                } else {
+                    obj = type.newInstance();
                 }
                 return obj;
             } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/struts/blob/6f91d077/plugins/osgi/src/main/java/org/apache/struts2/osgi/DelegatingObjectFactory.java
----------------------------------------------------------------------
diff --git a/plugins/osgi/src/main/java/org/apache/struts2/osgi/DelegatingObjectFactory.java
b/plugins/osgi/src/main/java/org/apache/struts2/osgi/DelegatingObjectFactory.java
index 079e257..ed82d1b 100644
--- a/plugins/osgi/src/main/java/org/apache/struts2/osgi/DelegatingObjectFactory.java
+++ b/plugins/osgi/src/main/java/org/apache/struts2/osgi/DelegatingObjectFactory.java
@@ -36,6 +36,11 @@ public class DelegatingObjectFactory extends ObjectFactory implements ObjectFact
     private OsgiConfigurationProvider osgiConfigurationProvider;
 
     @Inject
+    public DelegatingObjectFactory(Container container) {
+        super(container);
+    }
+
+    @Inject
     public void setDelegateObjectFactory(@Inject Container container,
                                          @Inject("struts.objectFactory.delegate") String
delegate) {
         if (delegate == null) {

http://git-wip-us.apache.org/repos/asf/struts/blob/6f91d077/plugins/osgi/src/main/java/org/apache/struts2/osgi/SpringOsgiObjectFactory.java
----------------------------------------------------------------------
diff --git a/plugins/osgi/src/main/java/org/apache/struts2/osgi/SpringOsgiObjectFactory.java
b/plugins/osgi/src/main/java/org/apache/struts2/osgi/SpringOsgiObjectFactory.java
index 3cebb32..ac596e2 100644
--- a/plugins/osgi/src/main/java/org/apache/struts2/osgi/SpringOsgiObjectFactory.java
+++ b/plugins/osgi/src/main/java/org/apache/struts2/osgi/SpringOsgiObjectFactory.java
@@ -23,6 +23,7 @@ package org.apache.struts2.osgi;
 
 import com.opensymphony.xwork2.ObjectFactory;
 import com.opensymphony.xwork2.util.ClassLoaderUtil;
+import com.opensymphony.xwork2.inject.Container;
 import com.opensymphony.xwork2.inject.Inject;
 import org.osgi.framework.ServiceReference;
 
@@ -38,6 +39,11 @@ public class SpringOsgiObjectFactory extends ObjectFactory {
 
     private BundleAccessor bundleAccessor;
 
+    @Inject
+    public SpringOsgiObjectFactory(Container container) {
+        super(container);
+    }
+
     public Object buildBean(String className, Map<String, Object> extraContext, boolean
injectInternal) throws Exception {
         if (containsBean(className))
             return getBean(className);

http://git-wip-us.apache.org/repos/asf/struts/blob/6f91d077/plugins/plexus/src/main/java/org/apache/struts2/plexus/PlexusObjectFactory.java
----------------------------------------------------------------------
diff --git a/plugins/plexus/src/main/java/org/apache/struts2/plexus/PlexusObjectFactory.java
b/plugins/plexus/src/main/java/org/apache/struts2/plexus/PlexusObjectFactory.java
index 506850f..7131f57 100644
--- a/plugins/plexus/src/main/java/org/apache/struts2/plexus/PlexusObjectFactory.java
+++ b/plugins/plexus/src/main/java/org/apache/struts2/plexus/PlexusObjectFactory.java
@@ -28,6 +28,7 @@ import com.opensymphony.xwork2.config.ConfigurationException;
 import com.opensymphony.xwork2.config.entities.ActionConfig;
 import com.opensymphony.xwork2.config.entities.InterceptorConfig;
 import com.opensymphony.xwork2.config.entities.ResultConfig;
+import com.opensymphony.xwork2.inject.Container;
 import com.opensymphony.xwork2.inject.Inject;
 import com.opensymphony.xwork2.interceptor.Interceptor;
 import org.apache.logging.log4j.Logger;
@@ -81,6 +82,11 @@ public class PlexusObjectFactory extends ObjectFactory {
     private ReflectionProvider reflectionProvider;
 
     @Inject
+    public PlexusObjectFactory(Container container) {
+        super(container);
+    }
+
+    @Inject
     public void setReflectionProvider(ReflectionProvider reflectionProvider) {
         this.reflectionProvider = reflectionProvider;
     }

http://git-wip-us.apache.org/repos/asf/struts/blob/6f91d077/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java
----------------------------------------------------------------------
diff --git a/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java
b/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java
index 83b2853..cd524dd 100644
--- a/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java
+++ b/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java
@@ -71,7 +71,7 @@ public class StrutsSpringObjectFactory extends SpringObjectFactory {
             @Inject(StrutsConstants.STRUTS_DEVMODE) String devMode,
             @Inject Container container) {
           
-        super();
+        super(container);
         boolean useClassCache = BooleanUtils.toBoolean(useClassCacheStr);
         LOG.info("Initializing Struts-Spring integration...");
 


Mime
View raw message