mirror of
https://github.com/apache/struts.git
synced 2026-08-07 15:46:57 +00:00
WW-5238 Uses proper order of mapping functions to support action: prefix
This commit is contained in:
@@ -20,26 +20,18 @@ package com.opensymphony.xwork2.config.entities;
|
||||
|
||||
import com.opensymphony.xwork2.util.location.Located;
|
||||
import com.opensymphony.xwork2.util.location.Location;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* Configuration for Package.
|
||||
*
|
||||
* <p>
|
||||
* In the xml configuration file this is defined as the <code>package</code> tag.
|
||||
* </p>
|
||||
*
|
||||
* @author Rainer Hermanns
|
||||
* @version $Revision$
|
||||
*/
|
||||
public class PackageConfig extends Located implements Comparable, Serializable, InterceptorLocator {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(PackageConfig.class);
|
||||
public class PackageConfig extends Located implements Comparable<PackageConfig>, Serializable, InterceptorLocator {
|
||||
|
||||
protected Map<String, ActionConfig> actionConfigs;
|
||||
protected Map<String, ResultConfig> globalResultConfigs;
|
||||
@@ -422,8 +414,7 @@ public class PackageConfig extends Located implements Comparable, Serializable,
|
||||
return "PackageConfig: [" + name + "] for namespace [" + namespace + "] with parents [" + parents + "]";
|
||||
}
|
||||
|
||||
public int compareTo(Object o) {
|
||||
PackageConfig other = (PackageConfig) o;
|
||||
public int compareTo(PackageConfig other) {
|
||||
String full = namespace + "!" + name;
|
||||
String otherFull = other.namespace + "!" + other.name;
|
||||
|
||||
@@ -443,7 +434,6 @@ public class PackageConfig extends Located implements Comparable, Serializable,
|
||||
public static class Builder implements InterceptorLocator {
|
||||
|
||||
protected PackageConfig target;
|
||||
private boolean strictDMI = true;
|
||||
|
||||
public Builder(String name) {
|
||||
target = new PackageConfig(name);
|
||||
|
||||
@@ -289,8 +289,8 @@ public class DefaultActionMapper implements ActionMapper {
|
||||
}
|
||||
|
||||
parseNameAndNamespace(uri, mapping, configManager);
|
||||
extractMethodName(mapping, configManager);
|
||||
handleSpecialParameters(request, mapping);
|
||||
extractMethodName(mapping, configManager);
|
||||
return parseActionName(mapping);
|
||||
}
|
||||
|
||||
|
||||
+51
-72
@@ -20,15 +20,15 @@ package org.apache.struts2.dispatcher.mapper;
|
||||
|
||||
import com.mockobjects.servlet.MockHttpServletRequest;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.Result;
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.ConfigurationManager;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.config.entities.PackageConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ResultConfig;
|
||||
import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.StrutsInternalTestCase;
|
||||
import org.apache.struts2.result.StrutsResultSupport;
|
||||
import org.apache.struts2.views.jsp.StrutsMockHttpServletRequest;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -38,7 +38,6 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* DefaultActionMapper test case.
|
||||
*
|
||||
*/
|
||||
public class DefaultActionMapperTest extends StrutsInternalTestCase {
|
||||
|
||||
@@ -46,6 +45,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
|
||||
private ConfigurationManager configManager;
|
||||
private Configuration config;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
req = new MockHttpServletRequest();
|
||||
@@ -79,6 +79,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
|
||||
assertNull(mapping.getMethod());
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testGetMappingWithMethod() {
|
||||
req.setupGetParameterMap(new HashMap());
|
||||
req.setupGetRequestURI("/my/namespace/actionName!add.action");
|
||||
@@ -157,7 +158,6 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void testGetMappingWithNamespaceSlash() {
|
||||
|
||||
req.setupGetRequestURI("/my-hh/abc.action");
|
||||
@@ -256,6 +256,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
|
||||
assertNull(mapping);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testGetUri() {
|
||||
req.setupGetParameterMap(new HashMap());
|
||||
req.setupGetRequestURI("/my/namespace/actionName.action");
|
||||
@@ -268,6 +269,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
|
||||
assertEquals("/my/namespace/actionName.action", mapper.getUriFromActionMapping(mapping));
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testGetUriWithSemicolonPresent() {
|
||||
req.setupGetParameterMap(new HashMap());
|
||||
req.setupGetRequestURI("/my/namespace/actionName.action;abc=123rty56");
|
||||
@@ -280,6 +282,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
|
||||
assertEquals("/my/namespace/actionName.action", mapper.getUriFromActionMapping(mapping));
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testGetUriWithMethod() {
|
||||
req.setupGetParameterMap(new HashMap());
|
||||
req.setupGetRequestURI("/my/namespace/actionName!add.action");
|
||||
@@ -294,7 +297,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
|
||||
}
|
||||
|
||||
public void testGetUriWithOriginalExtension() {
|
||||
ActionMapping mapping = new ActionMapping("actionName", "/ns", null, new HashMap<String, Object>());
|
||||
ActionMapping mapping = new ActionMapping("actionName", "/ns", null, new HashMap<>());
|
||||
|
||||
ActionMapping orig = new ActionMapping();
|
||||
orig.setExtension("foo");
|
||||
@@ -304,6 +307,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
|
||||
assertEquals("/ns/actionName.foo", mapper.getUriFromActionMapping(mapping));
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testGetMappingWithNoExtension() {
|
||||
req.setupGetParameterMap(new HashMap());
|
||||
req.setupGetRequestURI("/my/namespace/actionName");
|
||||
@@ -320,6 +324,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
|
||||
assertNull(mapping.getMethod());
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testGetMappingWithNoExtensionButUriHasExtension() {
|
||||
req.setupGetParameterMap(new HashMap());
|
||||
req.setupGetRequestURI("/my/namespace/actionName.html");
|
||||
@@ -524,88 +529,66 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
|
||||
assertEquals("myAction", actionMapping.getName());
|
||||
}
|
||||
|
||||
public void testRedirectPrefix() {
|
||||
public void testActionPrefix() {
|
||||
Map<String, Object> parameterMap = new HashMap<>();
|
||||
parameterMap.put("redirect:" + "http://www.google.com", "");
|
||||
parameterMap.put("action:" + "next", "");
|
||||
|
||||
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
|
||||
request.setupGetServletPath("/someServletPath.action");
|
||||
request.setupGetServletPath("/index.action");
|
||||
request.setParameterMap(parameterMap);
|
||||
|
||||
DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
|
||||
defaultActionMapper.setContainer(container);
|
||||
ActionMapping actionMapping = defaultActionMapper.getMapping(request, configManager);
|
||||
|
||||
Result result = actionMapping.getResult();
|
||||
assertNull(result);
|
||||
assertNotNull(actionMapping);
|
||||
assertEquals("/", actionMapping.getNamespace());
|
||||
assertEquals("index", actionMapping.getName());
|
||||
assertNull(actionMapping.getMethod());
|
||||
}
|
||||
|
||||
public void testUnsafeRedirectPrefix() {
|
||||
public void testActionPrefixWhenAllowed() {
|
||||
config = new DefaultConfiguration();
|
||||
PackageConfig pkg = new PackageConfig.Builder("test")
|
||||
.namespace("/test")
|
||||
.addActionConfig("execute", new ActionConfig.Builder("test", "index", "org.test.TestAction")
|
||||
.methodName("execute")
|
||||
.addAllowedMethod("execute")
|
||||
.build())
|
||||
.addActionConfig("next", new ActionConfig.Builder("test", "next", "org.test.TestAction")
|
||||
.methodName("next")
|
||||
.addAllowedMethod("next")
|
||||
.addResultConfig(new ResultConfig.Builder("next", "org.test.TestResult")
|
||||
.build())
|
||||
.build())
|
||||
.build();
|
||||
|
||||
config.addPackageConfig("test", pkg);
|
||||
|
||||
|
||||
configManager = new ConfigurationManager(Container.DEFAULT_NAME) {
|
||||
public Configuration getConfiguration() {
|
||||
return config;
|
||||
}
|
||||
};
|
||||
|
||||
Map<String, Object> parameterMap = new HashMap<>();
|
||||
parameterMap.put("redirect:" + "http://%{3*4}", "");
|
||||
parameterMap.put("action:" + "next", "");
|
||||
|
||||
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
|
||||
request.setupGetServletPath("/someServletPath.action");
|
||||
request.setupGetServletPath("/test/index.action");
|
||||
request.setParameterMap(parameterMap);
|
||||
|
||||
DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
|
||||
defaultActionMapper.setContainer(container);
|
||||
defaultActionMapper.setAllowActionPrefix("true");
|
||||
|
||||
ActionMapping actionMapping = defaultActionMapper.getMapping(request, configManager);
|
||||
|
||||
Result result = actionMapping.getResult();
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
public void testRedirectActionPrefix() {
|
||||
Map<String, Object> parameterMap = new HashMap<>();
|
||||
parameterMap.put("redirectAction:" + "myAction", "");
|
||||
|
||||
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
|
||||
request.setupGetServletPath("/someServletPath.action");
|
||||
request.setParameterMap(parameterMap);
|
||||
|
||||
DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
|
||||
defaultActionMapper.setContainer(container);
|
||||
ActionMapping actionMapping = defaultActionMapper.getMapping(request, configManager);
|
||||
|
||||
|
||||
StrutsResultSupport result = (StrutsResultSupport) actionMapping.getResult();
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
public void testUnsafeRedirectActionPrefix() {
|
||||
Map<String, Object> parameterMap = new HashMap<>();
|
||||
parameterMap.put("redirectAction:" + "%{3*4}", "");
|
||||
|
||||
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
|
||||
request.setupGetServletPath("/someServletPath.action");
|
||||
request.setParameterMap(parameterMap);
|
||||
|
||||
DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
|
||||
defaultActionMapper.setContainer(container);
|
||||
ActionMapping actionMapping = defaultActionMapper.getMapping(request, configManager);
|
||||
|
||||
|
||||
StrutsResultSupport result = (StrutsResultSupport) actionMapping.getResult();
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
public void testRedirectActionPrefixWithEmptyExtension() {
|
||||
Map<String, Object> parameterMap = new HashMap<>();
|
||||
parameterMap.put("redirectAction:" + "myAction", "");
|
||||
|
||||
StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
|
||||
request.setupGetServletPath("/someServletPath");
|
||||
request.setParameterMap(parameterMap);
|
||||
|
||||
DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
|
||||
defaultActionMapper.setContainer(container);
|
||||
defaultActionMapper.setExtensions(",,");
|
||||
ActionMapping actionMapping = defaultActionMapper.getMapping(request, configManager);
|
||||
|
||||
|
||||
StrutsResultSupport result = (StrutsResultSupport) actionMapping.getResult();
|
||||
assertNull(result);
|
||||
assertNotNull(actionMapping);
|
||||
assertEquals("/test", actionMapping.getNamespace());
|
||||
assertEquals("next", actionMapping.getName());
|
||||
assertEquals("next", actionMapping.getMethod());
|
||||
}
|
||||
|
||||
public void testCustomActionPrefix() {
|
||||
@@ -617,11 +600,7 @@ public class DefaultActionMapperTest extends StrutsInternalTestCase {
|
||||
request.setupGetServletPath("/someServletPath.action");
|
||||
|
||||
DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
|
||||
defaultActionMapper.addParameterAction("foo", new ParameterAction() {
|
||||
public void execute(String key, ActionMapping mapping) {
|
||||
mapping.setName("myAction");
|
||||
}
|
||||
});
|
||||
defaultActionMapper.addParameterAction("foo", (key, mapping) -> mapping.setName("myAction"));
|
||||
ActionMapping actionMapping = defaultActionMapper.getMapping(request, configManager);
|
||||
|
||||
assertEquals(actionMapping.getName(), "myAction");
|
||||
|
||||
Reference in New Issue
Block a user