You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2016/10/31 19:38:44 UTC

[3/5] wicket git commit: WICKET-6260 let WebRequest detect Ajax request

WICKET-6260 let WebRequest detect Ajax request

WebRequest#isAjax() no longer touches the request body, thus it can safely be asked


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/12b4bfe2
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/12b4bfe2
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/12b4bfe2

Branch: refs/heads/wicket-7.x
Commit: 12b4bfe2a6a7f0ea354376beef18eb9ea20f97d6
Parents: afe1e33
Author: Sven Meier <sv...@apache.org>
Authored: Wed Oct 26 10:19:18 2016 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon Oct 31 20:32:31 2016 +0100

----------------------------------------------------------------------
 .../wicket/protocol/http/WebApplication.java    | 23 ++++----
 .../protocol/http/WebApplicationTest.java       | 58 ++++++++++++++++++++
 2 files changed, 69 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/12b4bfe2/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
index c97d11f..5ed6fb0 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
@@ -560,12 +560,21 @@ public abstract class WebApplication extends Application
 	 */
 	WebRequest createWebRequest(HttpServletRequest servletRequest, final String filterPath)
 	{
+		if (hasFilterFactoryManager())
+		{
+			for (AbstractRequestWrapperFactory factory : getFilterFactoryManager())
+			{
+				servletRequest = factory.getWrapper(servletRequest);
+			}
+		}
+
+		WebRequest webRequest = newWebRequest(servletRequest, filterPath);
+
 		if (servletRequest.getCharacterEncoding() == null)
 		{
 			try
 			{
-				String wicketAjaxHeader = servletRequest.getHeader(WebRequest.HEADER_AJAX);
-				if (Strings.isTrue(wicketAjaxHeader))
+				if (webRequest.isAjax())
 				{
 					// WICKET-3908, WICKET-1816: Forms submitted with Ajax are always UTF-8 encoded
 					servletRequest.setCharacterEncoding(CharEncoding.UTF_8);
@@ -582,16 +591,6 @@ public abstract class WebApplication extends Application
 			}
 		}
 
-		if (hasFilterFactoryManager())
-		{
-			for (AbstractRequestWrapperFactory factory : getFilterFactoryManager())
-			{
-				servletRequest = factory.getWrapper(servletRequest);
-			}
-		}
-
-		WebRequest webRequest = newWebRequest(servletRequest, filterPath);
-
 		return webRequest;
 	}
 

http://git-wip-us.apache.org/repos/asf/wicket/blob/12b4bfe2/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebApplicationTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebApplicationTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebApplicationTest.java
index 0b51703..ba6b175 100644
--- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebApplicationTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebApplicationTest.java
@@ -17,9 +17,15 @@
 package org.apache.wicket.protocol.http;
 
 import java.nio.charset.Charset;
+import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.Locale;
+import java.util.Map;
 
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.wicket.mock.MockRequestParameters;
+import org.apache.wicket.protocol.http.mock.MockHttpServletRequest;
 import org.apache.wicket.request.IRequestHandler;
 import org.apache.wicket.request.IRequestMapper;
 import org.apache.wicket.request.Request;
@@ -42,6 +48,58 @@ public class WebApplicationTest extends WicketTestCase
 	private static final String MOUNT_PATH_4 = "mount/path/4";
 
 	/**
+	 * WICKET-6260
+	 */
+	@Test
+	public void testBodyNotReadBeforeApplicationSetsCharacterEncoding() throws Exception {
+		WebApplication application = tester.getApplication();
+
+		HttpServletRequest request = new MockHttpServletRequest(application, null, null) {
+			@Override
+			public Map<String, String[]> getParameterMap()
+			{
+				fail("body should not be read before character encoding is set");
+				return null;
+			}
+
+			@Override
+			public String getParameter(String name)
+			{
+				fail("body should not be read before character encoding is set");
+				return null;
+			}
+
+			@Override
+			public Enumeration<String> getParameterNames()
+			{
+				fail("body should not be read before character encoding is set");
+				return null;
+			}
+
+			@Override
+			public String[] getParameterValues(String name)
+			{
+				fail("body should not be read before character encoding is set");
+				return null;
+			}
+
+			@Override
+			public MockRequestParameters getPostParameters()
+			{
+				fail("body should not be read before character encoding is set");
+				return null;
+			}
+		};
+
+		// character encoding not set yet
+		request.setCharacterEncoding(null);
+
+		application.createWebRequest(request , "/");
+
+		assertEquals("UTF-8", request.getCharacterEncoding());
+	}
+
+	/**
 	 * Test basic unmounting from a compound mapper.
 	 */
 	@Test