diff --git a/core/src/main/java/org/apache/struts2/dispatcher/mapper/ActionMapper.java b/core/src/main/java/org/apache/struts2/dispatcher/mapper/ActionMapper.java index a4af0c973..bb42556ce 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/mapper/ActionMapper.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/mapper/ActionMapper.java @@ -21,10 +21,10 @@ package org.apache.struts2.dispatcher.mapper; -import javax.servlet.http.HttpServletRequest; - import com.opensymphony.xwork2.config.ConfigurationManager; +import javax.servlet.http.HttpServletRequest; + /** * * @@ -51,7 +51,7 @@ public interface ActionMapper { * * @param request The servlet request * @param configManager The current configuration manager - * @return The appropriate action mapping + * @return The appropriate action mapping or null if mapping cannot be determined */ ActionMapping getMapping(HttpServletRequest request, ConfigurationManager configManager); 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 f67834187..f0e44bd35 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 @@ -289,9 +289,10 @@ public class RestActionMapper extends DefaultActionMapper { } mapping.setName(fullName); + return mapping; } - - return mapping; + // if action name isn't specified, it can be a normal request, to static resource, return null to allow handle that case + return null; } private void handleDynamicMethodInvocation(ActionMapping mapping, String name) { 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 43114cd72..ffaa99ef6 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 @@ -57,6 +57,15 @@ public class RestActionMapperTest extends TestCase { }; } + public void testRootMapping() throws Exception { + req.setRequestURI("/myapp/"); + req.setServletPath("/"); + + ActionMapping mapping = mapper.getMapping(req, configManager); + + assertNull(mapping); + } + public void testGetMapping() throws Exception { req.setRequestURI("/myapp/animals/dog"); req.setServletPath("/animals/dog");