This is an automated email from the ASF dual-hosted git repository. mgrigorov pushed a commit to branch wicket-8.x in repository https://gitbox.apache.org/repos/asf/wicket.git
The following commit(s) were added to refs/heads/wicket-8.x by this push: new e772703 WICKET-6759 Add `shouldNotifyOnErrorEvent` filter function to `WebSocketSettings` (#416) e772703 is described below commit e772703a28b63de6c95cf12ed733ee9b9c079d30 Author: Thomas <thomas.he...@gmail.com> AuthorDate: Fri Mar 20 13:52:13 2020 +0100 WICKET-6759 Add `shouldNotifyOnErrorEvent` filter function to `WebSocketSettings` (#416) (cherry picked from commit 6d453fa39978d921f15dfdba8f1a515b86feb0d0) --- .../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 3a156e0..6d17caa 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 d8fdffb..7194cf5 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)); + } } /**