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/03/20 12:52:22 UTC

[wicket] branch master updated: WICKET-6759 Add `shouldNotifyOnErrorEvent` filter function to `WebSocketSettings` (#416)

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


The following commit(s) were added to refs/heads/master by this push:
     new 6d453fa  WICKET-6759 Add `shouldNotifyOnErrorEvent` filter function to `WebSocketSettings` (#416)
6d453fa is described below

commit 6d453fa39978d921f15dfdba8f1a515b86feb0d0
Author: Thomas <th...@gmail.com>
AuthorDate: Fri Mar 20 13:52:13 2020 +0100

    WICKET-6759 Add `shouldNotifyOnErrorEvent` filter function to `WebSocketSettings` (#416)
---
 .../org/apache/wicket/protocol/ws/WebSocketSettings.java | 16 ++++++++++++++++
 .../protocol/ws/api/AbstractWebSocketProcessor.java      |  6 ++++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/WebSocketSettings.java b/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/WebSocketSettings.java
index d6967a6..b755c18 100644
--- a/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/WebSocketSettings.java
+++ b/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/WebSocketSettings.java
@@ -149,6 +149,22 @@ public class WebSocketSettings
 	}
 
 	/**
+	 * A function that decides whether to notify the page/resource on
+	 * web socket error event.
+	 * The page notification leads to deserialization of the page instance from
+	 * the page store and sometimes this is not wanted.
+	 */
+	private Function<Throwable, Boolean> notifyOnErrorEvent = (throwable) -> true;
+
+	public boolean shouldNotifyOnErrorEvent(Throwable throwable) {
+		return notifyOnErrorEvent == null || notifyOnErrorEvent.apply(throwable);
+	}
+
+	public void setNotifyOnErrorEvent(Function<Throwable, Boolean> notifyOnErrorEvent) {
+		this.notifyOnErrorEvent = notifyOnErrorEvent;
+	}
+
+	/**
 	 * Set the executor for processing websocket push messages broadcasted to all sessions.
 	 * Default executor does all the processing in the caller thread. Using a proper thread pool is adviced
 	 * for applications that send push events from ajax calls to avoid page level deadlocks.
diff --git a/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java b/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java
index 2505278..c533858 100644
--- a/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java
+++ b/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java
@@ -194,8 +194,10 @@ public abstract class AbstractWebSocketProcessor implements IWebSocketProcessor
 	@Override
 	public void onError(Throwable t)
 	{
-		IKey key = getRegistryKey();
-		broadcastMessage(new ErrorMessage(getApplication(), getSessionId(), key, t));
+		if (webSocketSettings.shouldNotifyOnErrorEvent(t)) {
+			IKey key = getRegistryKey();
+			broadcastMessage(new ErrorMessage(getApplication(), getSessionId(), key, t));
+		}
 	}
 
 	/**