[ 
https://issues.apache.org/jira/browse/WW-4903?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16307440#comment-16307440
 ] 

ASF GitHub Bot commented on WW-4903:
------------------------------------

yasserzamani closed pull request #195: WW-4903: fixes 
PrefixBasedActionProxyFactory
URL: https://github.com/apache/struts/pull/195
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/core/src/main/java/org/apache/struts2/factory/PrefixBasedActionProxyFactory.java
 
b/core/src/main/java/org/apache/struts2/factory/PrefixBasedActionProxyFactory.java
index c522d1a6d..cf196a9b2 100644
--- 
a/core/src/main/java/org/apache/struts2/factory/PrefixBasedActionProxyFactory.java
+++ 
b/core/src/main/java/org/apache/struts2/factory/PrefixBasedActionProxyFactory.java
@@ -22,13 +22,17 @@
 import com.opensymphony.xwork2.ActionProxyFactory;
 import com.opensymphony.xwork2.DefaultActionProxyFactory;
 import com.opensymphony.xwork2.inject.Container;
+import com.opensymphony.xwork2.inject.Initializable;
 import com.opensymphony.xwork2.inject.Inject;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.struts2.StrutsConstants;
 
+import java.util.Arrays;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * <!-- START SNIPPET: description -->
@@ -55,28 +59,22 @@
  * </pre>
  * <!-- END SNIPPET: description -->
  */
-public class PrefixBasedActionProxyFactory extends DefaultActionProxyFactory {
+public class PrefixBasedActionProxyFactory extends StrutsActionProxyFactory {
 
     private static final Logger LOG = 
LogManager.getLogger(PrefixBasedActionProxyFactory.class);
 
     private Map<String, ActionProxyFactory> actionProxyFactories = new 
HashMap<>();
-    private ActionProxyFactory defaultFactory;
 
     @Inject
     public void setContainer(Container container) {
         this.container = container;
     }
 
-    @Inject(StrutsConstants.STRUTS_ACTIONPROXYFACTORY)
-    public void setActionProxyFactory(ActionProxyFactory factory) {
-        this.defaultFactory = factory;
-    }
-
     @Inject(StrutsConstants.PREFIX_BASED_MAPPER_CONFIGURATION)
     public void setPrefixBasedActionProxyFactories(String list) {
         if (list != null) {
-            String[] factories = list.split(",");
-            for (String factory : factories) {
+            Set<String> prefixes = new 
HashSet<>(Arrays.asList(list.split(",")));
+            for (String factory : prefixes) {
                 String[] thisFactory = factory.split(":");
                 if (thisFactory.length == 2) {
                     String factoryPrefix = thisFactory[0].trim();
@@ -106,8 +104,7 @@ public ActionProxy createActionProxy(String namespace, 
String actionName, String
                 LOG.debug("No ActionProxyFactory defined for [{}]", key);
             }
         }
-        LOG.debug("Cannot find any matching ActionProxyFactory, falling back 
to [{}]", defaultFactory);
-        return defaultFactory.createActionProxy(namespace, actionName, 
methodName, extraContext, executeResult, cleanupContext);
+        LOG.debug("Cannot find any matching ActionProxyFactory, falling back 
to [{}]", super.getClass().getName());
+        return super.createActionProxy(namespace, actionName, methodName, 
extraContext, executeResult, cleanupContext);
     }
-
 }
diff --git 
a/core/src/test/java/org/apache/struts2/factory/PrefixBasedActionProxyFactoryTest.java
 
b/core/src/test/java/org/apache/struts2/factory/PrefixBasedActionProxyFactoryTest.java
new file mode 100644
index 000000000..27e9d019c
--- /dev/null
+++ 
b/core/src/test/java/org/apache/struts2/factory/PrefixBasedActionProxyFactoryTest.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.struts2.factory;
+
+import com.opensymphony.xwork2.ActionProxy;
+import com.opensymphony.xwork2.ActionProxyFactory;
+import com.opensymphony.xwork2.DefaultActionProxyFactory;
+import com.opensymphony.xwork2.config.ConfigurationException;
+import com.opensymphony.xwork2.config.ConfigurationProvider;
+import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
+import com.opensymphony.xwork2.inject.ContainerBuilder;
+import com.opensymphony.xwork2.inject.Context;
+import com.opensymphony.xwork2.inject.Factory;
+import com.opensymphony.xwork2.inject.Scope;
+import com.opensymphony.xwork2.mock.MockActionProxy;
+import com.opensymphony.xwork2.test.StubConfigurationProvider;
+import com.opensymphony.xwork2.util.location.LocatableProperties;
+import org.apache.struts2.StrutsInternalTestCase;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class PrefixBasedActionProxyFactoryTest extends StrutsInternalTestCase {
+
+    private PrefixBasedActionProxyFactory factory;
+
+    public void testDifferentPrefixes() throws Exception {
+        
factory.setPrefixBasedActionProxyFactories("/ns1:prefix1,/ns2:prefix2");
+
+        ActionProxy proxy1 = factory.createActionProxy("/ns1", "", "", 
Collections.<String, Object>emptyMap(), false, true);
+        assertTrue(proxy1 instanceof Prefix1ActionProxy);
+
+        ActionProxy proxy2 = factory.createActionProxy("/ns2", "", "", 
Collections.<String, Object>emptyMap(), false, true);
+        assertTrue(proxy2 instanceof Prefix2ActionProxy);
+    }
+
+    public void testFallbackToDefault() throws Exception {
+        factory.setPrefixBasedActionProxyFactories("/ns1:prefix1");
+
+        ActionProxy proxy1 = factory.createActionProxy("/ns1", "", "", 
Collections.<String, Object>emptyMap(), false, true);
+        assertTrue(proxy1 instanceof Prefix1ActionProxy);
+
+        ActionProxy proxy2 = factory.createActionProxy("", "Foo", "", 
Collections.<String, Object>emptyMap(), false, true);
+        assertTrue(proxy2 instanceof StrutsActionProxy);
+    }
+
+    public void testEmptyPrefix() throws Exception {
+        factory.setPrefixBasedActionProxyFactories(":prefix1");
+
+        ActionProxy proxy1 = factory.createActionProxy("/ns1", "", "", 
Collections.<String, Object>emptyMap(), false, true);
+        assertTrue(proxy1 instanceof Prefix1ActionProxy);
+
+        ActionProxy proxy2 = factory.createActionProxy("/ns2", "", "", 
Collections.<String, Object>emptyMap(), false, true);
+        assertTrue(proxy2 instanceof Prefix1ActionProxy);
+    }
+
+    @Override
+    public void setUp() throws Exception {
+        ConfigurationProvider[] providers = new ConfigurationProvider[]{
+                new XmlConfigurationProvider("xwork-sample.xml"),
+                new StubConfigurationProvider() {
+                    @Override
+                    public void register(ContainerBuilder builder, 
LocatableProperties props) throws ConfigurationException {
+                        builder.factory(ActionProxyFactory.class, "prefix1", 
new Factory() {
+                            public Object create(Context context) throws 
Exception {
+                                return new Prefix1Factory();
+                            }
+
+                        }, Scope.SINGLETON);
+                    }
+                },
+                new StubConfigurationProvider() {
+                    @Override
+                    public void register(ContainerBuilder builder, 
LocatableProperties props) throws ConfigurationException {
+                        builder.factory(ActionProxyFactory.class, "prefix2", 
new Factory() {
+                            public Object create(Context context) throws 
Exception {
+                                return new Prefix2Factory();
+                            }
+
+                        }, Scope.SINGLETON);
+                    }
+                }
+        };
+
+        loadConfigurationProviders(providers);
+
+        factory = new PrefixBasedActionProxyFactory();
+        factory.setContainer(container);
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+        factory = null;
+    }
+
+    public static class Prefix1Factory extends DefaultActionProxyFactory {
+        public ActionProxy createActionProxy(String namespace, String 
actionName, String methodName, Map<String, Object> extraContext, boolean 
executeResult, boolean cleanupContext) {
+            return new Prefix1ActionProxy();
+        }
+
+    }
+
+    public static class Prefix1ActionProxy extends MockActionProxy {
+    }
+
+    public static class Prefix2Factory extends DefaultActionProxyFactory {
+        public ActionProxy createActionProxy(String namespace, String 
actionName, String methodName, Map<String, Object> extraContext, boolean 
executeResult, boolean cleanupContext) {
+            return new Prefix2ActionProxy();
+        }
+    }
+
+    public static class Prefix2ActionProxy extends MockActionProxy {
+    }
+
+}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 672b126da..644bf0d21 100644
--- a/pom.xml
+++ b/pom.xml
@@ -386,7 +386,7 @@
                 <artifactId>apache-rat-plugin</artifactId>
                 <executions>
                     <execution>
-                        <phase>verify</phase>
+                        <phase>prepare-package</phase>
                         <goals>
                             <goal>check</goal>
                         </goals>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Dependency Mapping Exception When Using PrefixBasedActionProxyFactory
> ---------------------------------------------------------------------
>
>                 Key: WW-4903
>                 URL: https://issues.apache.org/jira/browse/WW-4903
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Plugin - REST
>            Reporter: aditya shrivastava
>            Assignee: Lukasz Lenart
>             Fix For: 2.5.15
>
>         Attachments: error_screen_shot.png
>
>
> I am using struts-rest plugin with REST & NON REST flow I am using STRUTS 
> 2.3.34 version.
> To achieve this I am using following configuration.
> {code:java}
> <constant name="struts.mapper.class" 
> value="org.apache.struts2.dispatcher.mapper.PrefixBasedActionMapper"/>
> <constant name="struts.mapper.prefixMapping" 
> value="/sm:rest,/pd:rest,:struts"/>
> <constant name="struts.actionProxyFactory" value="prefix"/>
> {code}
> When I start my tomcat & hit on url 
> https://localhost:8080/myapp
> I always get the exception 
> {code:java}
> HTTP Status 500 – Internal Server Error
> Type Exception Report
> Message java.lang.RuntimeException: 
> com.opensymphony.xwork2.inject.DependencyException: 
> com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No 
> mapping found for dependency 
> [type=com.opensymphony.xwork2.ActionProxyFactory, 
> name='struts.actionProxyFactory'] in public void 
> org.apache.struts2.impl.PrefixBasedActionProxyFactory.setActionProxyFactory(com.opensymphony.xwork2.ActionProxyFactory).
> Description The server encountered an unexpected condition that prevented it 
> from fulfilling the request.
> Exception
> java.lang.RuntimeException: java.lang.RuntimeException: 
> com.opensymphony.xwork2.inject.DependencyException: 
> com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No 
> mapping found for dependency 
> [type=com.opensymphony.xwork2.ActionProxyFactory, 
> name='struts.actionProxyFactory'] in public void 
> org.apache.struts2.impl.PrefixBasedActionProxyFactory.setActionProxyFactory(com.opensymphony.xwork2.ActionProxyFactory).
>       
> com.opensymphony.xwork2.inject.ContainerBuilder$4.create(ContainerBuilder.java:132)
>       com.opensymphony.xwork2.inject.Scope$2$1.create(Scope.java:51)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:514)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:524)
>       
> com.opensymphony.xwork2.inject.ContainerImpl$9.call(ContainerImpl.java:555)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:584)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:553)
>       
> org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:565)
>       
> org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
>       
> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
>       
> com.elitecore.nvsmx.system.filter.PortalSecurityFilter.doFilter(PortalSecurityFilter.java:61)
> Root Cause
> java.lang.RuntimeException: 
> com.opensymphony.xwork2.inject.DependencyException: 
> com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No 
> mapping found for dependency 
> [type=com.opensymphony.xwork2.ActionProxyFactory, 
> name='struts.actionProxyFactory'] in public void 
> org.apache.struts2.impl.PrefixBasedActionProxyFactory.setActionProxyFactory(com.opensymphony.xwork2.ActionProxyFactory).
>       
> com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:502)
>       
> com.opensymphony.xwork2.inject.ContainerImpl$7.call(ContainerImpl.java:539)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:593)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:537)
>       
> com.opensymphony.xwork2.config.impl.LocatableFactory.create(LocatableFactory.java:32)
>       
> com.opensymphony.xwork2.inject.ContainerBuilder$4.create(ContainerBuilder.java:130)
>       com.opensymphony.xwork2.inject.Scope$2$1.create(Scope.java:51)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:514)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:524)
>       
> com.opensymphony.xwork2.inject.ContainerImpl$9.call(ContainerImpl.java:555)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:584)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:553)
>       
> org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:565)
>       
> org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
>       
> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
>       
> com.elitecore.nvsmx.system.filter.PortalSecurityFilter.doFilter(PortalSecurityFilter.java:61)
> com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No 
> mapping found for dependency 
> [type=com.opensymphony.xwork2.ActionProxyFactory, 
> name='struts.actionProxyFactory'] in public void 
> org.apache.struts2.impl.PrefixBasedActionProxyFactory.setActionProxyFactory(com.opensymphony.xwork2.ActionProxyFactory).
>       
> com.opensymphony.xwork2.inject.ContainerImpl.createParameterInjector(ContainerImpl.java:239)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.getParametersInjectors(ContainerImpl.java:229)
>       
> com.opensymphony.xwork2.inject.ContainerImpl$MethodInjector.<init>(ContainerImpl.java:293)
>       
> com.opensymphony.xwork2.inject.ContainerImpl$3.create(ContainerImpl.java:117)
>       
> com.opensymphony.xwork2.inject.ContainerImpl$3.create(ContainerImpl.java:114)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMembers(ContainerImpl.java:141)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMethods(ContainerImpl.java:113)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.addInjectors(ContainerImpl.java:90)
>       
> com.opensymphony.xwork2.inject.ContainerImpl$1.create(ContainerImpl.java:71)
>       
> com.opensymphony.xwork2.inject.ContainerImpl$1.create(ContainerImpl.java:67)
>       
> com.opensymphony.xwork2.inject.util.ReferenceCache$CallableCreate.call(ReferenceCache.java:150)
>       java.util.concurrent.FutureTask.run(FutureTask.java:266)
>       
> com.opensymphony.xwork2.inject.util.ReferenceCache.internalCreate(ReferenceCache.java:76)
>       
> com.opensymphony.xwork2.inject.util.ReferenceCache.get(ReferenceCache.java:116)
>       
> com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector.<init>(ContainerImpl.java:356)
>       
> com.opensymphony.xwork2.inject.ContainerImpl$5.create(ContainerImpl.java:311)
>       
> com.opensymphony.xwork2.inject.ContainerImpl$5.create(ContainerImpl.java:307)
>       
> com.opensymphony.xwork2.inject.util.ReferenceCache$CallableCreate.call(ReferenceCache.java:150)
>       java.util.concurrent.FutureTask.run(FutureTask.java:266)
>       
> com.opensymphony.xwork2.inject.util.ReferenceCache.internalCreate(ReferenceCache.java:76)
>       
> com.opensymphony.xwork2.inject.util.ReferenceCache.get(ReferenceCache.java:116)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.getConstructor(ContainerImpl.java:607)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:498)
>       
> com.opensymphony.xwork2.inject.ContainerImpl$7.call(ContainerImpl.java:539)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:593)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:537)
>       
> com.opensymphony.xwork2.config.impl.LocatableFactory.create(LocatableFactory.java:32)
>       
> com.opensymphony.xwork2.inject.ContainerBuilder$4.create(ContainerBuilder.java:130)
>       com.opensymphony.xwork2.inject.Scope$2$1.create(Scope.java:51)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:514)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:524)
>       
> com.opensymphony.xwork2.inject.ContainerImpl$9.call(ContainerImpl.java:555)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:584)
>       
> com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:553)
>       
> org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:565)
>       
> org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
>       
> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
>       
> com.elitecore.nvsmx.system.filter.PortalSecurityFilter.doFilter(PortalSecurityFilter.java:61)
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to