Author: musachy Date: Sat Apr 18 17:09:01 2009 New Revision: 766357 URL: http://svn.apache.org/viewvc?rev=766357&view=rev Log: WW-3000 force StrutsPrepareAndExecuteFilter to always lookup action mapping, to prevent infinite recursion when the filter is applied to FORWARD
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ng/PrepareOperations.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/StrutsPrepareAndExecuteFilter.java struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/ng/StrutsPrepareAndExecuteFilterIntegrationTest.java Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ng/PrepareOperations.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ng/PrepareOperations.java?rev=766357&r1=766356&r2=766357&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ng/PrepareOperations.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ng/PrepareOperations.java Sat Apr 18 17:09:01 2009 @@ -134,13 +134,24 @@ } /** - * Finds and optionally creates an {...@link ActionMapping}. It first looks in the current request to see if one + * Finds and optionally creates an {...@link ActionMapping}. It first looks in the current request to see if one * has already been found, otherwise, it creates it and stores it in the request. No mapping will be created in the * case of static resource requests or unidentifiable requests for other servlets, for example. */ public ActionMapping findActionMapping(HttpServletRequest request, HttpServletResponse response) { + return findActionMapping(request, response, false); + } + + /** + * Finds and optionally creates an {...@link ActionMapping}. if forceLookup is false, it first looks in the current request to see if one + * has already been found, otherwise, it creates it and stores it in the request. No mapping will be created in the + * case of static resource requests or unidentifiable requests for other servlets, for example. + * @param forceLookup if true, the action mapping will be looked up from the ActionMapper instance, ignoring if there is one + * in the request or not + */ + public ActionMapping findActionMapping(HttpServletRequest request, HttpServletResponse response, boolean forceLookup) { ActionMapping mapping = (ActionMapping) request.getAttribute(STRUTS_ACTION_MAPPING_KEY); - if (mapping == null) { + if (mapping == null || forceLookup) { try { mapping = dispatcher.getContainer().getInstance(ActionMapper.class).getMapping(request, dispatcher.getConfigurationManager()); if (mapping != null) { Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/StrutsPrepareAndExecuteFilter.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/StrutsPrepareAndExecuteFilter.java?rev=766357&r1=766356&r2=766357&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/StrutsPrepareAndExecuteFilter.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/StrutsPrepareAndExecuteFilter.java Sat Apr 18 17:09:01 2009 @@ -66,7 +66,7 @@ prepare.assignDispatcherToThread(); prepare.setEncodingAndLocale(request, response); request = prepare.wrapRequest(request); - ActionMapping mapping = prepare.findActionMapping(request, response); + ActionMapping mapping = prepare.findActionMapping(request, response, true); if (mapping == null) { boolean handled = execute.executeStaticResourceRequest(request, response); if (!handled) { Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/ng/StrutsPrepareAndExecuteFilterIntegrationTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/ng/StrutsPrepareAndExecuteFilterIntegrationTest.java?rev=766357&r1=766356&r2=766357&view=diff ============================================================================== --- struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/ng/StrutsPrepareAndExecuteFilterIntegrationTest.java (original) +++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/ng/StrutsPrepareAndExecuteFilterIntegrationTest.java Sat Apr 18 17:09:01 2009 @@ -79,6 +79,40 @@ assertNull(Dispatcher.getInstance()); } + public void testActionMappingLookup() throws ServletException, IOException { + MockHttpServletRequest request = new MockHttpServletRequest(); + MockHttpServletResponse response = new MockHttpServletResponse(); + MockFilterConfig filterConfig = new MockFilterConfig(); + MockFilterChain filterChain = new MockFilterChain() { + @Override + public void doFilter(ServletRequest req, ServletResponse res) { + fail("Shouldn't get here"); + } + }; + + request.setRequestURI("/hello.action"); + StrutsPrepareAndExecuteFilter filter = new StrutsPrepareAndExecuteFilter(); + filter.init(filterConfig); + filter.doFilter(request, response, filterChain); + assertEquals(200, response.getStatus()); + assertNull(ActionContext.getContext()); + assertNull(Dispatcher.getInstance()); + + //simulate a FORWARD + MockFilterChain filterChain2 = new MockFilterChain() { + @Override + public void doFilter(ServletRequest req, ServletResponse res) { + req.setAttribute("__invoked", true); + } + }; + request.setRequestURI("hello.jsp"); + filter.doFilter(request, response, filterChain2); + assertEquals(200, response.getStatus()); + assertNull(ActionContext.getContext()); + assertNull(Dispatcher.getInstance()); + assertTrue((Boolean) request.getAttribute("__invoked")); + } + public void testStaticFallthrough() throws ServletException, IOException { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse();