The Unified and Autonomous Development Platform
Fix the issue that NPE might be thrown when login
Robin Shende7d4fe3abb2
diff --git a/commons.wicket/src/main/java/com/gitplex/commons/wicket/WicketUtils.java b/commons.wicket/src/main/java/com/gitplex/commons/wicket/WicketUtils.javaindex 31e44e588c..979428a707 100644--- a/commons.wicket/src/main/java/com/gitplex/commons/wicket/WicketUtils.java+++ b/commons.wicket/src/main/java/com/gitplex/commons/wicket/WicketUtils.java@@ -8,6 +8,7 @@ import org.apache.wicket.behavior.AttributeAppender;import org.apache.wicket.behavior.Behavior;import org.apache.wicket.core.request.handler.IPageRequestHandler;import org.apache.wicket.markup.html.WebMarkupContainer;+import org.apache.wicket.protocol.ws.api.registry.PageIdKey;import org.apache.wicket.request.Url;import org.apache.wicket.request.cycle.RequestCycle;@@ -34,10 +35,13 @@ public class WicketUtils {@Nullablepublic static PageKey getPageKey() {Page page = getPage();- if (page != null)- return new PageKey(page);- else- return null;+ if (page != null) {+ String sessionId = page.getSession().getId();+ if (sessionId != null) {+ return new PageKey(sessionId, new PageIdKey(page.getPageId()));+ }+ }+ return null;}public static void markLastVisibleChild(WebMarkupContainer container) {diff --git a/commons.wicket/src/main/java/com/gitplex/commons/wicket/websocket/DefaultWebSocketManager.java b/commons.wicket/src/main/java/com/gitplex/commons/wicket/websocket/DefaultWebSocketManager.javaindex 42a986a312..8cf844e5f6 100644--- a/commons.wicket/src/main/java/com/gitplex/commons/wicket/websocket/DefaultWebSocketManager.java+++ b/commons.wicket/src/main/java/com/gitplex/commons/wicket/websocket/DefaultWebSocketManager.java@@ -16,6 +16,7 @@ import javax.inject.Singleton;import org.apache.wicket.Application;import org.apache.wicket.protocol.ws.api.IWebSocketConnection;import org.apache.wicket.protocol.ws.api.registry.IWebSocketConnectionRegistry;+import org.apache.wicket.protocol.ws.api.registry.PageIdKey;import org.apache.wicket.protocol.ws.api.registry.SimpleWebSocketConnectionRegistry;import org.eclipse.jetty.websocket.api.WebSocketPolicy;import org.hibernate.resource.transaction.spi.TransactionStatus;@@ -48,13 +49,17 @@ public class DefaultWebSocketManager implements WebSocketManager {@Overridepublic void onRegionChange(CommonPage page) {- regions.put(new PageKey(page), page.getWebSocketRegions());+ String sessionId = page.getSession().getId();+ if (sessionId != null) {+ regions.put(new PageKey(sessionId, new PageIdKey(page.getPageId())), page.getWebSocketRegions());+ }}@Overridepublic void onDestroySession(String sessionId) {for (Iterator<Map.Entry<PageKey, Collection<WebSocketRegion>>> it = regions.entrySet().iterator(); it.hasNext();) {- if (it.next().getKey().getSessionId().equals(sessionId))+ PageKey pageKey = it.next().getKey();+ if (pageKey.getSessionId().equals(sessionId))it.remove();}}diff --git a/commons.wicket/src/main/java/com/gitplex/commons/wicket/websocket/PageKey.java b/commons.wicket/src/main/java/com/gitplex/commons/wicket/websocket/PageKey.javaindex 1fe2edac2f..c6f3f4c068 100644--- a/commons.wicket/src/main/java/com/gitplex/commons/wicket/websocket/PageKey.java+++ b/commons.wicket/src/main/java/com/gitplex/commons/wicket/websocket/PageKey.java@@ -2,7 +2,6 @@ package com.gitplex.commons.wicket.websocket;import org.apache.commons.lang3.builder.EqualsBuilder;import org.apache.commons.lang3.builder.HashCodeBuilder;-import org.apache.wicket.Page;import org.apache.wicket.protocol.ws.api.registry.IKey;import org.apache.wicket.protocol.ws.api.registry.PageIdKey;@@ -22,11 +21,6 @@ public class PageKey {this.pageId = new PageIdKey(pageId);}- public PageKey(Page page) {- this.sessionId = page.getSession().getId();- this.pageId = new PageIdKey(page.getPageId());- }-public String getSessionId() {return sessionId;}