You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2016/01/20 10:02:27 UTC
struts git commit: WW-4589 do not overwrite explicit method name
Repository: struts
Updated Branches:
refs/heads/master 3163d6c38 -> 1fb695a82
WW-4589 do not overwrite explicit method name
Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/1fb695a8
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/1fb695a8
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/1fb695a8
Branch: refs/heads/master
Commit: 1fb695a82b589cdd6e7b5bc2501dfec6b95c906e
Parents: 3163d6c
Author: petersr <ri...@braxtontech.com>
Authored: Tue Jan 19 14:02:57 2016 -0800
Committer: petersr <ri...@braxtontech.com>
Committed: Tue Jan 19 14:02:57 2016 -0800
----------------------------------------------------------------------
.../apache/struts2/rest/RestActionMapper.java | 3 +-
.../struts2/rest/RestActionMapperTest.java | 39 ++++++++++++++++++++
2 files changed, 41 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts/blob/1fb695a8/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java
----------------------------------------------------------------------
diff --git a/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java b/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java
index d25b725..632842f 100644
--- a/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java
+++ b/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java
@@ -224,7 +224,8 @@ public class RestActionMapper extends DefaultActionMapper {
// fun trickery to parse 'actionName/id/methodName' in the case of 'animals/dog/edit'
int prevSlashPos = fullName.lastIndexOf('/', lastSlashPos - 1);
- if (prevSlashPos > -1) {
+ //WW-4589 do not overwrite explicit method name
+ if (prevSlashPos > -1 && mapping.getMethod() == null) {
mapping.setMethod(fullName.substring(lastSlashPos + 1));
fullName = fullName.substring(0, lastSlashPos);
lastSlashPos = prevSlashPos;
http://git-wip-us.apache.org/repos/asf/struts/blob/1fb695a8/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java
----------------------------------------------------------------------
diff --git a/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java b/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java
index 9903265..f17a071 100644
--- a/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java
+++ b/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java
@@ -207,6 +207,45 @@ public class RestActionMapperTest extends TestCase {
assertEquals("fido", ((String[]) mapping.getParams().get("id"))[0]);
assertEquals("update", mapping.getMethod());
}
+
+ public void testMappingWithMethodAndId() throws Exception {
+ req.setRequestURI("/myapp/animals/dog/fido/test/some-id!create;jsessionid=29fefpv23do1g");
+ req.setServletPath("/animals/dog/fido/test/some-id");
+ req.setMethod("GET");
+ mapper.setAllowDynamicMethodCalls("true");
+ ActionMapping mapping = mapper.getMapping(req, configManager);
+
+ assertEquals("/animals", mapping.getNamespace());
+ assertEquals("dog/fido/test", mapping.getName());
+ assertEquals("some-id", ((String[]) mapping.getParams().get("id"))[0]);
+ assertEquals("create", mapping.getMethod());
+ }
+
+ public void testMappingForStaticFiles() throws Exception {
+ req.setRequestURI("/myApp/custom/menu/Yosemite/Vernal_Fall/Vernal_Fall_Image!iframe");
+ req.setServletPath("/custom/menu/Yosemite/Vernal_Fall/Vernal_Fall_Image");
+ req.setMethod("GET");
+ mapper.setAllowDynamicMethodCalls("true");
+ final ActionMapping mapping = mapper.getMapping(req, configManager);
+
+ assertEquals("", mapping.getNamespace());
+ assertEquals("custom/menu/Yosemite/Vernal_Fall", mapping.getName());
+ assertEquals("Vernal_Fall_Image", ((String[]) mapping.getParams().get("id"))[0]);
+ assertEquals("iframe", mapping.getMethod());
+ }
+
+ public void testMappingForStaticFilesWithJsessionId() throws Exception {
+ req.setRequestURI("/myApp/custom/menu/Yosemite/Vernal_Fall/Vernal_Fall_Image!iframe;jsessionid=29fefpv23do1g");
+ req.setServletPath("/custom/menu/Yosemite/Vernal_Fall/Vernal_Fall_Image");
+ req.setMethod("GET");
+ mapper.setAllowDynamicMethodCalls("true");
+ final ActionMapping mapping = mapper.getMapping(req, configManager);
+
+ assertEquals("", mapping.getNamespace());
+ assertEquals("custom/menu/Yosemite/Vernal_Fall", mapping.getName());
+ assertEquals("Vernal_Fall_Image", ((String[]) mapping.getParams().get("id"))[0]);
+ assertEquals("iframe", mapping.getMethod());
+ }
public void testParseNameAndNamespace() {
tryUri("/foo/23", "", "foo/23");