You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jd...@apache.org on 2011/04/09 16:41:37 UTC

svn commit: r1090600 - in /wicket/trunk: wicket-core/src/main/java/org/apache/wicket/request/handler/render/ wicket-core/src/test/java/org/apache/wicket/util/cookies/ wicket-request/src/main/java/org/apache/wicket/request/flow/

Author: jdonnerstag
Date: Sat Apr  9 14:41:37 2011
New Revision: 1090600

URL: http://svn.apache.org/viewvc?rev=1090600&view=rev
Log:
fixed Cannot set a cookie on bookmarkable page
Issue: WICKET-3576

Added:
    wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectStatefullTestPage.html
    wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectStatefullTestPage.java
    wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectStatelessTestPage.html
    wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectStatelessTestPage.java
    wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectTest.java
Modified:
    wicket/trunk/wicket-core/src/main/java/org/apache/wicket/request/handler/render/WebPageRenderer.java
    wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/CookieValuePersisterTestPage.java
    wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/flow/ResetResponseException.java

Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/request/handler/render/WebPageRenderer.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/request/handler/render/WebPageRenderer.java?rev=1090600&r1=1090599&r2=1090600&view=diff
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/request/handler/render/WebPageRenderer.java (original)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/request/handler/render/WebPageRenderer.java Sat Apr  9 14:41:37 2011
@@ -173,7 +173,7 @@ public class WebPageRenderer extends Pag
 	{
 		WebResponse response = (WebResponse)requestCycle.getResponse();
 		String relativeUrl = requestCycle.getUrlRenderer().renderUrl(url);
-		response.reset();
+		// response.reset();
 		response.sendRedirect(relativeUrl);
 	}
 

Modified: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/CookieValuePersisterTestPage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/CookieValuePersisterTestPage.java?rev=1090600&r1=1090599&r2=1090600&view=diff
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/CookieValuePersisterTestPage.java (original)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/CookieValuePersisterTestPage.java Sat Apr  9 14:41:37 2011
@@ -34,12 +34,9 @@ public class CookieValuePersisterTestPag
 
 	/**
 	 * Construct.
-	 * 
-	 * 
 	 */
 	public CookieValuePersisterTestPage()
 	{
-
 		// Create and add feedback panel to page
 		final FeedbackPanel feedback = new FeedbackPanel("feedback");
 		add(feedback);
@@ -48,7 +45,6 @@ public class CookieValuePersisterTestPag
 
 	/**
 	 * 
-	 * @author Juergen Donnerstag
 	 */
 	public final class TestForm extends Form<Void>
 	{
@@ -63,13 +59,9 @@ public class CookieValuePersisterTestPag
 		public TestForm(final String id)
 		{
 			super(id);
-
 			add(new TextField<String>("input", new Model<String>("test")));
 		}
 
-		/**
-		 * Dummy
-		 */
 		@Override
 		public final void onSubmit()
 		{

Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectStatefullTestPage.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectStatefullTestPage.html?rev=1090600&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectStatefullTestPage.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectStatefullTestPage.html Sat Apr  9 14:41:37 2011
@@ -0,0 +1,26 @@
+<!--
+    $Id: CookieValuePersisterTestPage.html 527232 2007-04-10 18:15:14Z jcompagner $
+    $Revision: 527232 $
+    $Date: 2007-04-10 20:15:14 +0200 (Di, 10 Apr 2007) $
+
+    ====================================================================
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<body>
+  <form wicket:id="form">
+    <input wicket:id="input" type="text" />
+    <input type="submit" value="set cookie" />
+  </form>
+</body>
+</html>

Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectStatefullTestPage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectStatefullTestPage.java?rev=1090600&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectStatefullTestPage.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectStatefullTestPage.java Sat Apr  9 14:41:37 2011
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.util.cookies;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+
+
+/**
+ * Statefull form page which sets a cookie and calls setResponsePage()
+ * 
+ * @author Bertrand Guay-Paquet
+ */
+public class SetCookieAndRedirectStatefullTestPage extends WebPage
+{
+	private static final long serialVersionUID = 1L;
+
+	/**	 */
+	public static final String cookieName = "CookieValuePersisterStatelessTestPage";
+
+	private IModel<String> inputModel;
+
+	/**
+	 * Construct.
+	 */
+	public SetCookieAndRedirectStatefullTestPage()
+	{
+		inputModel = new Model<String>();
+		Form<Void> form = new Form<Void>("form")
+		{
+			private static final long serialVersionUID = 1L;
+
+			@Override
+			protected void onSubmit()
+			{
+				CookieUtils utils = new CookieUtils();
+				utils.save(cookieName, inputModel.getObject());
+				setResponsePage(getApplication().getHomePage());
+			}
+		};
+		add(form);
+		form.add(new TextField<String>("input", inputModel));
+	}
+}
\ No newline at end of file

Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectStatelessTestPage.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectStatelessTestPage.html?rev=1090600&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectStatelessTestPage.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectStatelessTestPage.html Sat Apr  9 14:41:37 2011
@@ -0,0 +1,26 @@
+<!--
+    $Id: CookieValuePersisterTestPage.html 527232 2007-04-10 18:15:14Z jcompagner $
+    $Revision: 527232 $
+    $Date: 2007-04-10 20:15:14 +0200 (Di, 10 Apr 2007) $
+
+    ====================================================================
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<body>
+  <form wicket:id="form">
+    <input wicket:id="input" type="text" />
+    <input type="submit" value="set cookie" />
+  </form>
+</body>
+</html>

Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectStatelessTestPage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectStatelessTestPage.java?rev=1090600&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectStatelessTestPage.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectStatelessTestPage.java Sat Apr  9 14:41:37 2011
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.util.cookies;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.StatelessForm;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+
+
+/**
+ * Stateless form page which sets a cookie and calls setResponsePage()
+ * 
+ * @author Bertrand Guay-Paquet
+ */
+public class SetCookieAndRedirectStatelessTestPage extends WebPage
+{
+	private static final long serialVersionUID = 1L;
+
+	/**	 */
+	public static final String cookieName = "CookieValuePersisterStatelessTestPage";
+
+	private IModel<String> inputModel;
+
+	/**
+	 * Construct.
+	 */
+	public SetCookieAndRedirectStatelessTestPage()
+	{
+		inputModel = new Model<String>();
+		Form<Void> form = new StatelessForm<Void>("form")
+		{
+			private static final long serialVersionUID = 1L;
+
+			@Override
+			protected void onSubmit()
+			{
+				CookieUtils utils = new CookieUtils();
+				utils.save(cookieName, inputModel.getObject());
+				setResponsePage(getApplication().getHomePage());
+			}
+		};
+		add(form);
+		form.add(new TextField<String>("input", inputModel));
+	}
+}
\ No newline at end of file

Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectTest.java?rev=1090600&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectTest.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/cookies/SetCookieAndRedirectTest.java Sat Apr  9 14:41:37 2011
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.util.cookies;
+
+import java.util.List;
+
+import javax.servlet.http.Cookie;
+
+import org.apache.wicket.Page;
+import org.apache.wicket.WicketTestCase;
+import org.apache.wicket.util.tester.FormTester;
+
+/**
+ * Tests setting a cookie and calling setResponsePage() in the same request.
+ * 
+ * @author Bertrand Guay-Paquet
+ */
+public class SetCookieAndRedirectTest extends WicketTestCase
+{
+	private static final String cookieValue = "cookieValue";
+
+	/**
+	 * Validate proper cookie value set with statefull page
+	 */
+	public void testStatefullPage()
+	{
+		tester.startPage(SetCookieAndRedirectStatefullTestPage.class);
+		FormTester formTester = tester.newFormTester("form");
+		formTester.setValue("input", cookieValue);
+		formTester.submit();
+		Page page = tester.getLastRenderedPage();
+
+		List<Cookie> cookies = tester.getLastResponse().getCookies();
+		assertEquals(1, cookies.size());
+		assertEquals(cookieValue, cookies.get(0).getValue());
+	}
+
+	/**
+	 * Validate proper cookie value set with stateless page
+	 */
+	public void testStatelessPage()
+	{
+		tester.startPage(SetCookieAndRedirectStatelessTestPage.class);
+		FormTester formTester = tester.newFormTester("form");
+		formTester.setValue("input", cookieValue);
+		formTester.submit();
+		Page page = tester.getLastRenderedPage();
+
+		List<Cookie> cookies = tester.getLastResponse().getCookies();
+		assertEquals(1, cookies.size());
+		assertEquals(cookieValue, cookies.get(0).getValue());
+	}
+}

Modified: wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/flow/ResetResponseException.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/flow/ResetResponseException.java?rev=1090600&r1=1090599&r2=1090600&view=diff
==============================================================================
--- wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/flow/ResetResponseException.java (original)
+++ wicket/trunk/wicket-request/src/main/java/org/apache/wicket/request/flow/ResetResponseException.java Sat Apr  9 14:41:37 2011
@@ -28,13 +28,12 @@ import org.apache.wicket.request.Request
  */
 public abstract class ResetResponseException extends ReplaceHandlerException
 {
-	/**
-	 * 
-	 */
 	private static final long serialVersionUID = 1L;
 
 	/**
 	 * Construct.
+	 * 
+	 * @param handler
 	 */
 	protected ResetResponseException(final IRequestHandler handler)
 	{
@@ -45,6 +44,11 @@ public abstract class ResetResponseExcep
 	{
 		private final IRequestHandler delegate;
 
+		/**
+		 * Construct.
+		 * 
+		 * @param delegate
+		 */
 		public ResponseResettingDecorator(final IRequestHandler delegate)
 		{
 			this.delegate = delegate;