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 2020/10/20 20:10:13 UTC

[wicket] 01/02: WICKET-6845 stackoverflow while serializing a page containing a reference to session

This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/wicket.git

commit 8664176abcc6393c54b29d058c655d440500bc8d
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
AuthorDate: Tue Oct 20 23:07:30 2020 +0300

    WICKET-6845 stackoverflow while serializing a page containing a reference to session
    
    Make sure an HTTP session is created before committing the response.
    This is needed because org.apache.wicket.pageStore.RequestPageStore#detach() is called after committing the response and it is too late to create an HTTP session at that time.
---
 .../apache/wicket/pageStore/RequestPageStore.java  | 32 ++++++++++++++--------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/wicket-core/src/main/java/org/apache/wicket/pageStore/RequestPageStore.java b/wicket-core/src/main/java/org/apache/wicket/pageStore/RequestPageStore.java
index ddeab95..54dc9da 100644
--- a/wicket-core/src/main/java/org/apache/wicket/pageStore/RequestPageStore.java
+++ b/wicket-core/src/main/java/org/apache/wicket/pageStore/RequestPageStore.java
@@ -59,6 +59,11 @@ public class RequestPageStore extends DelegatingPageStore
 	@Override
 	public void addPage(IPageContext context, IManageablePage page)
 	{
+		// make sure an HTTP session is bound before committing the response
+		if (isPageStateless(page) == false)
+		{
+			context.getSessionId(true);
+		}
 		getRequestData(context).add(page);
 	}
 
@@ -92,18 +97,7 @@ public class RequestPageStore extends DelegatingPageStore
 		RequestData requestData = getRequestData(context);
 		for (IManageablePage page : requestData.pages())
 		{
-			boolean isPageStateless;
-			try
-			{
-				isPageStateless = page.isPageStateless();
-			}
-			catch (Exception x)
-			{
-				log.warn("An error occurred while checking whether a page is stateless. Assuming it is stateful.", x);
-				isPageStateless = false;
-			}
-
-			if (isPageStateless == false)
+			if (isPageStateless(page) == false)
 			{
 				getDelegate().addPage(context, page);
 			}
@@ -113,6 +107,20 @@ public class RequestPageStore extends DelegatingPageStore
 		getDelegate().detach(context);
 	}
 
+	private boolean isPageStateless(final IManageablePage page) {
+		boolean isPageStateless;
+		try
+		{
+			isPageStateless = page.isPageStateless();
+		}
+		catch (Exception x)
+		{
+			log.warn("An error occurred while checking whether a page is stateless. Assuming it is stateful.", x);
+			isPageStateless = false;
+		}
+		return isPageStateless;
+	}
+
 	private RequestData getRequestData(IPageContext context)
 	{
 		return context.getRequestData(KEY, RequestData::new);