You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jc...@apache.org on 2008/10/04 23:43:36 UTC

svn commit: r701716 - /wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java

Author: jcompagner
Date: Sat Oct  4 14:43:35 2008
New Revision: 701716

URL: http://svn.apache.org/viewvc?rev=701716&view=rev
Log:
fix for setting the char encoding at the right times WICKET-1816

Modified:
    wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java?rev=701716&r1=701715&r2=701716&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java Sat Oct  4 14:43:35 2008
@@ -258,7 +258,8 @@
 					else
 					{
 						httpServletResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
-						httpServletResponse.setDateHeader("Expires", System.currentTimeMillis() + Duration.hours(1).getMilliseconds());
+						httpServletResponse.setDateHeader("Expires", System.currentTimeMillis() +
+							Duration.hours(1).getMilliseconds());
 					}
 				}
 			}
@@ -322,42 +323,7 @@
 				Thread.currentThread().setContextClassLoader(newClassLoader);
 			}
 
-			// If the request does not provide information about the encoding of
-			// its body (which includes POST parameters), than assume the
-			// default encoding as defined by the wicket application. Bear in
-			// mind that the encoding of the request usually is equal to the
-			// previous response.
-			// However it is a known bug of IE that it does not provide this
-			// information. Please see the wiki for more details and why all
-			// other browser deliberately copied that bug.
-			if (servletRequest.getCharacterEncoding() == null)
-			{
-				try
-				{
-					// It this request is a wicket-ajax request, we need decode the
-					// request always by UTF-8, because the request data is encoded by
-					// encodeUrlComponent() JavaScript function, which always encode data
-					// by UTF-8.
-					String wicketAjaxHeader = servletRequest.getHeader("wicket-ajax");
-					if (wicketAjaxHeader != null && wicketAjaxHeader.equals("true"))
-					{
-						servletRequest.setCharacterEncoding("UTF-8");
-					}
-					else
-					{
-						// The encoding defined by the wicket settings is used to
-						// encode the responses. Thus, it is reasonable to assume
-						// the request has the same encoding. This is especially
-						// important for forms and form parameters.
-						servletRequest.setCharacterEncoding(webApplication.getRequestCycleSettings()
-							.getResponseRequestEncoding());
-					}
-				}
-				catch (UnsupportedEncodingException ex)
-				{
-					throw new WicketRuntimeException(ex.getMessage());
-				}
-			}
+			checkCharacterEncoding(servletRequest);
 
 			// Create a new webrequest
 			final WebRequest request = webApplication.newWebRequest(servletRequest);
@@ -467,6 +433,46 @@
 		return true;
 	}
 
+	private void checkCharacterEncoding(final HttpServletRequest servletRequest)
+	{
+		// If the request does not provide information about the encoding of
+		// its body (which includes POST parameters), than assume the
+		// default encoding as defined by the wicket application. Bear in
+		// mind that the encoding of the request usually is equal to the
+		// previous response.
+		// However it is a known bug of IE that it does not provide this
+		// information. Please see the wiki for more details and why all
+		// other browser deliberately copied that bug.
+		if (servletRequest.getCharacterEncoding() == null)
+		{
+			try
+			{
+				// It this request is a wicket-ajax request, we need decode the
+				// request always by UTF-8, because the request data is encoded by
+				// encodeUrlComponent() JavaScript function, which always encode data
+				// by UTF-8.
+				String wicketAjaxHeader = servletRequest.getHeader("wicket-ajax");
+				if (wicketAjaxHeader != null && wicketAjaxHeader.equals("true"))
+				{
+					servletRequest.setCharacterEncoding("UTF-8");
+				}
+				else
+				{
+					// The encoding defined by the wicket settings is used to
+					// encode the responses. Thus, it is reasonable to assume
+					// the request has the same encoding. This is especially
+					// important for forms and form parameters.
+					servletRequest.setCharacterEncoding(webApplication.getRequestCycleSettings()
+						.getResponseRequestEncoding());
+				}
+			}
+			catch (UnsupportedEncodingException ex)
+			{
+				throw new WicketRuntimeException(ex.getMessage());
+			}
+		}
+	}
+
 	/**
 	 * @return The filter config of this WicketFilter
 	 */
@@ -1011,6 +1017,8 @@
 				// If resource found and it is cacheable
 				if ((resource != null) && resource.isCacheable())
 				{
+					// first check the char encoding for getting the parameters
+					checkCharacterEncoding(servletRequest);
 
 					final WebRequest request = webApplication.newWebRequest(servletRequest);
 					// make the session available.