mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
WW-4903 Reverts to previous initialise mechanism
This commit is contained in:
@@ -59,12 +59,11 @@ import java.util.Set;
|
||||
* </pre>
|
||||
* <!-- END SNIPPET: description -->
|
||||
*/
|
||||
public class PrefixBasedActionProxyFactory extends StrutsActionProxyFactory implements Initializable {
|
||||
public class PrefixBasedActionProxyFactory extends StrutsActionProxyFactory {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(PrefixBasedActionProxyFactory.class);
|
||||
|
||||
private Map<String, ActionProxyFactory> actionProxyFactories = new HashMap<>();
|
||||
private Set<String> prefixes = new HashSet<>();
|
||||
|
||||
@Inject
|
||||
public void setContainer(Container container) {
|
||||
@@ -74,22 +73,18 @@ public class PrefixBasedActionProxyFactory extends StrutsActionProxyFactory impl
|
||||
@Inject(StrutsConstants.PREFIX_BASED_MAPPER_CONFIGURATION)
|
||||
public void setPrefixBasedActionProxyFactories(String list) {
|
||||
if (list != null) {
|
||||
prefixes = new HashSet<>(Arrays.asList(list.split(",")));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
for (String factory : prefixes) {
|
||||
String[] thisFactory = factory.split(":");
|
||||
if (thisFactory.length == 2) {
|
||||
String factoryPrefix = thisFactory[0].trim();
|
||||
String factoryName = thisFactory[1].trim();
|
||||
ActionProxyFactory obj = container.getInstance(ActionProxyFactory.class, factoryName);
|
||||
if (obj != null) {
|
||||
actionProxyFactories.put(factoryPrefix, obj);
|
||||
} else {
|
||||
LOG.warn("Invalid PrefixBasedActionProxyFactory config entry: [{}]", factory);
|
||||
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();
|
||||
String factoryName = thisFactory[1].trim();
|
||||
ActionProxyFactory obj = container.getInstance(ActionProxyFactory.class, factoryName);
|
||||
if (obj != null) {
|
||||
actionProxyFactories.put(factoryPrefix, obj);
|
||||
} else {
|
||||
LOG.warn("Invalid PrefixBasedActionProxyFactory config entry: [{}]", factory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-6
@@ -23,7 +23,7 @@ public class PrefixBasedActionProxyFactoryTest extends StrutsInternalTestCase {
|
||||
private PrefixBasedActionProxyFactory factory;
|
||||
|
||||
public void testDifferentPrefixes() throws Exception {
|
||||
initFactory("/ns1:prefix1,/ns2:prefix2");
|
||||
factory.setPrefixBasedActionProxyFactories("/ns1:prefix1,/ns2:prefix2");
|
||||
|
||||
ActionProxy proxy1 = factory.createActionProxy("/ns1", "", "", Collections.<String, Object>emptyMap(), false, true);
|
||||
assertTrue(proxy1 instanceof Prefix1ActionProxy);
|
||||
@@ -33,7 +33,7 @@ public class PrefixBasedActionProxyFactoryTest extends StrutsInternalTestCase {
|
||||
}
|
||||
|
||||
public void testFallbackToDefault() throws Exception {
|
||||
initFactory("/ns1:prefix1");
|
||||
factory.setPrefixBasedActionProxyFactories("/ns1:prefix1");
|
||||
|
||||
ActionProxy proxy1 = factory.createActionProxy("/ns1", "", "", Collections.<String, Object>emptyMap(), false, true);
|
||||
assertTrue(proxy1 instanceof Prefix1ActionProxy);
|
||||
@@ -43,7 +43,7 @@ public class PrefixBasedActionProxyFactoryTest extends StrutsInternalTestCase {
|
||||
}
|
||||
|
||||
public void testEmptyPrefix() throws Exception {
|
||||
initFactory(":prefix1");
|
||||
factory.setPrefixBasedActionProxyFactories(":prefix1");
|
||||
|
||||
ActionProxy proxy1 = factory.createActionProxy("/ns1", "", "", Collections.<String, Object>emptyMap(), false, true);
|
||||
assertTrue(proxy1 instanceof Prefix1ActionProxy);
|
||||
@@ -86,9 +86,10 @@ public class PrefixBasedActionProxyFactoryTest extends StrutsInternalTestCase {
|
||||
factory.setContainer(container);
|
||||
}
|
||||
|
||||
void initFactory(String prefixes) {
|
||||
factory.setPrefixBasedActionProxyFactories(prefixes);
|
||||
factory.init();
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
factory = null;
|
||||
}
|
||||
|
||||
public static class Prefix1Factory extends DefaultActionProxyFactory {
|
||||
|
||||
Reference in New Issue
Block a user