Commits

Anonymous committed 22b4c3e

- fixed the encoding problem, due to wrapping request before setting the encoding will caused it to be ignored as pointed out by Ana in the forum. Put in testcase to check for this sequence as well.

Issue number: WW-1335
Obtained from:
Submitted by:
Reviewed by:

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@2681573baa09-0c28-0410-bef9-dab3c582ae83

  • Participants
  • Parent commits 3bf23e6

Comments (0)

Files changed (4)

File src/java/com/opensymphony/webwork/dispatcher/DispatcherUtils.java

         }
 
         //check for configuration reloading
-        if ("true".equalsIgnoreCase(Configuration.getString(WebWorkConstants.WEBWORK_CONFIGURATION_XML_RELOAD))) {
+        if (Configuration.isSet(WebWorkConstants.WEBWORK_CONFIGURATION_XML_RELOAD) && 
+        		"true".equalsIgnoreCase(Configuration.getString(WebWorkConstants.WEBWORK_CONFIGURATION_XML_RELOAD))) {
             FileManager.setReloadingConfigs(true);
         }
 

File src/java/com/opensymphony/webwork/dispatcher/FilterDispatcher.java

  * com.opensymphony.webwork.lifecycle.LifecycleListener} in web.xml. See the IoC docs for more information. <p/>
  *
  * @author Patrick Lightbody
+ * @author tm_jee
  * @see com.opensymphony.webwork.lifecycle.LifecycleListener
  * @see ActionMapper
  * @see ActionContextCleanUp
         // prepare the request no matter what - this ensures that the proper character encoding
         // is used before invoking the mapper (see WW-9127)
         DispatcherUtils du = DispatcherUtils.getInstance();
+        du.prepare(request, response);
         try {
         	// Wrap request first, just in case it is multipart/form-data
         	// parameters might not be accessible through before encoding (ww-1278)
             LOG.error(message, e);
             throw new ServletException(message, e);
         }
-        du.prepare(request, response);
+        
 
         ActionMapper mapper = ActionMapperFactory.getMapper();
         ActionMapping mapping = mapper.getMapping(request);

File src/java/com/opensymphony/webwork/dispatcher/ServletDispatcher.java

         DispatcherUtils du = DispatcherUtils.getInstance();
         du.prepare(request, response);
 
+        try {
+            request = du.wrapRequest(request, getServletContext());
+        } catch (IOException e) {
+            String message = "Could not wrap servlet request with MultipartRequestWrapper!";
+            LOG.error(message, e);
+            throw new ServletException(message, e);
+        }
+        
         ActionMapping mapping = ActionMapperFactory.getMapper().getMapping(request);
         if (mapping == null) {
             try {
             return;
         }
 
-        try {
-            request = du.wrapRequest(request, getServletContext());
-        } catch (IOException e) {
-            String message = "Could not wrap servlet request with MultipartRequestWrapper!";
-            LOG.error(message, e);
-            throw new ServletException(message, e);
-        }
-
         du.serviceAction(request, response, getServletContext(), mapping);
     }
 }

File src/test/com/opensymphony/webwork/dispatcher/FilterDispatcherTest.java

  */
 package com.opensymphony.webwork.dispatcher;
 
+import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 
 import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 import org.springframework.mock.web.MockFilterConfig;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
 import org.springframework.mock.web.MockServletContext;
 
+import com.mockobjects.servlet.MockFilterChain;
 import com.opensymphony.webwork.WebWorkConstants;
+import com.opensymphony.webwork.WebWorkTestCase;
 import com.opensymphony.webwork.config.Configuration;
+import com.opensymphony.webwork.dispatcher.mapper.ActionMapper;
+import com.opensymphony.webwork.dispatcher.mapper.ActionMapperFactory;
+import com.opensymphony.webwork.dispatcher.mapper.ActionMapping;
 import com.opensymphony.webwork.util.ObjectFactoryDestroyable;
 import com.opensymphony.webwork.util.ObjectFactoryInitializable;
 import com.opensymphony.webwork.util.ObjectFactoryLifecycle;
+import com.opensymphony.xwork.ActionInvocation;
+import com.opensymphony.xwork.ActionProxy;
+import com.opensymphony.xwork.ActionProxyFactory;
+import com.opensymphony.xwork.DefaultActionProxyFactory;
 import com.opensymphony.xwork.ObjectFactory;
+import com.opensymphony.xwork.mock.MockActionInvocation;
+import com.opensymphony.xwork.mock.MockActionProxy;
+import com.opensymphony.xwork.mock.MockConfiguration;
 
 import junit.framework.TestCase;
 
 	public void testObjectFactoryLifecycle() throws Exception {
 		Configuration.reset();
 		DispatcherUtils.setInstance(null);
+		try {
+			Map configMap = new HashMap();
+			configMap.put(WebWorkConstants.WEBWORK_OBJECTFACTORY, "com.opensymphony.webwork.dispatcher.FilterDispatcherTest$InnerInitailizableDestroyableObjectFactory");
+			configMap.put(WebWorkConstants.WEBWORK_CONFIGURATION_XML_RELOAD, "false");
+			Configuration.setConfiguration(new InnerConfiguration(configMap));
 		
-		Map configMap = new HashMap();
-		configMap.put(WebWorkConstants.WEBWORK_OBJECTFACTORY, "com.opensymphony.webwork.dispatcher.FilterDispatcherTest$InnerInitailizableDestroyableObjectFactory");
-		configMap.put(WebWorkConstants.WEBWORK_CONFIGURATION_XML_RELOAD, "false");
-		Configuration.setConfiguration(new InnerConfiguration(configMap));
-		
-		MockServletContext servletContext = new MockServletContext();
-		MockFilterConfig filterConfig = new MockFilterConfig(servletContext);
+			MockServletContext servletContext = new MockServletContext();
+			MockFilterConfig filterConfig = new MockFilterConfig(servletContext);
 	
 		
-		FilterDispatcher filterDispatcher = new FilterDispatcher();
-		filterDispatcher.init(filterConfig);
+			FilterDispatcher filterDispatcher = new FilterDispatcher();
+			filterDispatcher.init(filterConfig);
 		
-		assertTrue(ObjectFactory.getObjectFactory() instanceof InnerInitailizableDestroyableObjectFactory);
-		assertTrue(((InnerInitailizableDestroyableObjectFactory)ObjectFactory.getObjectFactory()).initializable);
+			assertTrue(ObjectFactory.getObjectFactory() instanceof InnerInitailizableDestroyableObjectFactory);
+			assertTrue(((InnerInitailizableDestroyableObjectFactory)ObjectFactory.getObjectFactory()).initializable);
 		
-		assertFalse(((InnerInitailizableDestroyableObjectFactory)ObjectFactory.getObjectFactory()).destroyable);
-		filterDispatcher.destroy();
-		assertTrue(((InnerInitailizableDestroyableObjectFactory)ObjectFactory.getObjectFactory()).destroyable);
+			assertFalse(((InnerInitailizableDestroyableObjectFactory)ObjectFactory.getObjectFactory()).destroyable);
+			filterDispatcher.destroy();
+			assertTrue(((InnerInitailizableDestroyableObjectFactory)ObjectFactory.getObjectFactory()).destroyable);
+		}
+		finally {
+			Configuration.reset();
+			DispatcherUtils.setInstance(null);
+		}
+	}
+	
+	public void testIfActionMapperIsNullDontServiceAction() throws Exception {
+		try {
+			MockServletContext servletContext = new MockServletContext();
+			MockFilterConfig filterConfig = new MockFilterConfig(servletContext);
+			MockHttpServletRequest req = new MockHttpServletRequest(
+					servletContext);
+			MockHttpServletResponse res = new MockHttpServletResponse();
+			MockFilterChain filterChain = new MockFilterChain();
+
+			ActionProxyFactory.setFactory(new InnerActionProxyFactory());
+
+			Map conf = new HashMap();
+			conf.put(WebWorkConstants.WEBWORK_MAPPER_CLASS, "com.opensymphony.webwork.dispatcher.FilterDispatcherTest$NullInnerActionMapper");
+			Configuration.setConfiguration(new InnerConfiguration(conf));
+
+			NoOpDispatcherUtil du = new NoOpDispatcherUtil(servletContext);
+			DispatcherUtils.setInstance(du);
+
+			FilterDispatcher filter = new FilterDispatcher();
+			filter.init(filterConfig);
+			filter.doFilter(req, res, filterChain);
+
+			assertFalse(du.serviceAction);
+
+		}
+		finally {
+			DispatcherUtils.setInstance(null);
+			Configuration.reset();
+			ActionProxyFactory.setFactory(new DefaultActionProxyFactory());
+		}
+	}
+	
+	public void testCharacterEncodingSetBeforeRequestWrappingAndActionService() throws Exception {
+		try {
+		MockServletContext servletContext = new MockServletContext();
+			MockFilterConfig filterConfig = new MockFilterConfig(servletContext);
+			MockHttpServletRequest req = new MockHttpServletRequest(
+					servletContext);
+			MockHttpServletResponse res = new MockHttpServletResponse();
+			MockFilterChain filterChain = new MockFilterChain();
+
+			ActionProxyFactory.setFactory(new InnerActionProxyFactory());
+
+			Map conf = new HashMap();
+			conf.put(WebWorkConstants.WEBWORK_I18N_ENCODING, "UTF-16_DUMMY");
+			conf.put(WebWorkConstants.WEBWORK_MAPPER_CLASS, "com.opensymphony.webwork.dispatcher.FilterDispatcherTest$InnerActionMapper");
+			Configuration.setConfiguration(new InnerConfiguration(conf));
+
+			InnerDispatcherUtil du = new InnerDispatcherUtil(servletContext);
+			DispatcherUtils.setInstance(du);
+
+			FilterDispatcher filter = new FilterDispatcher();
+			filter.init(filterConfig);
+			filter.doFilter(req, res, filterChain);
+
+			assertTrue(du.wrappedRequest);
+			assertTrue(du.serviceAction);
+		}
+		finally {
+			Configuration.reset();
+			DispatcherUtils.setInstance(null);
+			ActionProxyFactory.setFactory(new DefaultActionProxyFactory());
+		}
 	}
 	
 	
 		}
 	}
 	
+	public static class InnerActionProxyFactory extends ActionProxyFactory {
+
+		public ActionInvocation createActionInvocation(ActionProxy actionProxy, Map extraContext) throws Exception {
+			return new MockActionInvocation();
+		}
+
+		public ActionInvocation createActionInvocation(ActionProxy actionProxy) throws Exception {
+			return new MockActionInvocation();
+		}
+
+		public ActionInvocation createActionInvocation(ActionProxy actionProxy, Map extraContext, boolean pushAction) throws Exception {
+			return new MockActionInvocation();
+		}
+
+		public ActionProxy createActionProxy(String namespace, String actionName, Map extraContext) throws Exception {
+			return new MockActionProxy();
+		}
+
+		public ActionProxy createActionProxy(String namespace, String actionName, Map extraContext, boolean executeResult, boolean cleanupContext) throws Exception {
+			return new MockActionProxy();
+		}
+		
+	}
+	
+	
+	public static class NullInnerActionMapper implements ActionMapper {
+		public ActionMapping getMapping(HttpServletRequest request) {
+			return null;
+		}
+
+		public String getUriFromActionMapping(ActionMapping mapping) {
+			return null;
+		}
+	}
+	
+	public static class InnerActionMapper implements ActionMapper {
+
+		public ActionMapping getMapping(HttpServletRequest request) {
+			return new ActionMapping();
+		}
+
+		public String getUriFromActionMapping(ActionMapping mapping) {
+			return null;
+		}
+	}
+	
+	public static class NoOpDispatcherUtil extends DispatcherUtils {
+		protected boolean wrappedRequest = false;
+		protected boolean serviceAction = false;
+		
+		protected NoOpDispatcherUtil(ServletContext servletContext) {
+			super(servletContext);
+		}
+		
+		public HttpServletRequest wrapRequest(HttpServletRequest request, ServletContext servletContext) throws IOException {
+			wrappedRequest = true;
+			return request;
+		}
+		
+		public void serviceAction(HttpServletRequest request, HttpServletResponse response, ServletContext context, ActionMapping mapping) throws ServletException {
+			serviceAction = true;
+		}
+	}
+	
+	public static class InnerDispatcherUtil extends DispatcherUtils {
+
+		protected boolean wrappedRequest = false;
+		protected boolean serviceAction = false;
+		
+		protected InnerDispatcherUtil(ServletContext servletContext) {
+			super(servletContext);
+		}
+		
+		public HttpServletRequest wrapRequest(HttpServletRequest request, ServletContext servletContext) throws IOException {
+			wrappedRequest = true;
+			String characterEncoding = request.getCharacterEncoding();
+			// if we set the chracter encoding AFTER we do a wrapp, we will get
+			// a failing test
+			assertEquals(characterEncoding, "UTF-16_DUMMY");
+			return request;
+		}
+		
+		public void serviceAction(HttpServletRequest request, HttpServletResponse response, ServletContext context, ActionMapping mapping) throws ServletException {
+			serviceAction = true;
+			String characterEncoding = request.getCharacterEncoding();
+			// if we set the chracter encoding AFTER we do an action service, we will get
+			// a failing test
+			assertEquals(characterEncoding, "UTF-16_DUMMY");
+		}
+	}
 	
 	public static class InnerDestroyableObjectFactory extends ObjectFactory implements ObjectFactoryDestroyable {
 		public boolean destroyed = false;