WICKET-5371 IllegalArgumentException: Argument 'page' may not be null. - when 
sending event from asynchronous process

Log a warning and unregister all subscriptions for a page when it is no more in 
the page stores for any reason


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

Branch: refs/heads/wicket-6.x
Commit: 1d1b4782dbb9dbc41cec097031f338ad889c0f77
Parents: 78fc5b5
Author: Martin Tzvetanov Grigorov <[email protected]>
Authored: Thu Aug 14 15:21:18 2014 +0200
Committer: Martin Tzvetanov Grigorov <[email protected]>
Committed: Fri Aug 15 09:48:23 2014 +0200

----------------------------------------------------------------------
 .../atmosphere/AtmosphereRequestHandler.java      | 18 +++++++++++++++---
 .../org/apache/wicket/atmosphere/EventBus.java    | 16 ++++++++++++++++
 2 files changed, 31 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/1d1b4782/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereRequestHandler.java
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereRequestHandler.java
 
b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereRequestHandler.java
index 3ba143d..f19e7e0 100644
--- 
a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereRequestHandler.java
+++ 
b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereRequestHandler.java
@@ -20,6 +20,7 @@ import java.util.Iterator;
 
 import org.apache.wicket.Component;
 import org.apache.wicket.Page;
+import org.apache.wicket.Session;
 import org.apache.wicket.ajax.AjaxRequestTarget;
 import org.apache.wicket.behavior.Behavior;
 import org.apache.wicket.protocol.http.WebApplication;
@@ -71,9 +72,20 @@ public class AtmosphereRequestHandler implements 
IRequestHandler
        public void respond(IRequestCycle requestCycle)
        {
                WebApplication application = WebApplication.get();
-               Page page = 
(Page)application.getMapperContext().getPageInstance(pageKey.getPageId());
-               AjaxRequestTarget target = 
application.newAjaxRequestTarget(page);
-               executeHandlers(target, page);
+               Integer pageId = pageKey.getPageId();
+               Page page = (Page) 
Session.get().getPageManager().getPage(pageId);
+               if (page != null)
+               {
+                       AjaxRequestTarget target = 
application.newAjaxRequestTarget(page);
+                       executeHandlers(target, page);
+               }
+               else
+               {
+                       LOGGER.warn("Could not find a page with id '{}' for 
session with id '{}' in the page stores. It will be unregistered",
+                                       pageId, pageKey.getSessionId());
+                       EventBus.get(application).unregister(pageKey);
+
+               }
        }
 
        private void executeHandlers(AjaxRequestTarget target, Page page)

http://git-wip-us.apache.org/repos/asf/wicket/blob/1d1b4782/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventBus.java
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventBus.java
 
b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventBus.java
index 6b56d56..253473b 100644
--- 
a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventBus.java
+++ 
b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventBus.java
@@ -290,6 +290,22 @@ public class EventBus implements UnboundListener
        }
 
        /**
+        * Unregisters all {@link EventSubscription}s for the given pageKey.
+        *
+        * @param pageKey
+        *          The key with the page id and session id
+        */
+       public synchronized void unregister(PageKey pageKey)
+       {
+               if (log.isDebugEnabled())
+               {
+                       log.debug("unregistering all subscriptions for page {} 
for session {}",
+                                       pageKey.getPageId(), 
pageKey.getSessionId());
+               }
+               subscriptions.removeAll(pageKey);
+       }
+
+       /**
         * Unregisters all {@link EventSubscription}s for the given component, 
including the
         * subscriptions for its behaviors.
         *

Reply via email to