diff --git a/app/src/main/java/io/xeres/app/configuration/WebSocketMessageBrokerConfiguration.java b/app/src/main/java/io/xeres/app/configuration/WebSocketMessageBrokerConfiguration.java index 8b4b43a2..ca4dfa2f 100644 --- a/app/src/main/java/io/xeres/app/configuration/WebSocketMessageBrokerConfiguration.java +++ b/app/src/main/java/io/xeres/app/configuration/WebSocketMessageBrokerConfiguration.java @@ -21,6 +21,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.event.EventListener; import org.springframework.messaging.simp.config.MessageBrokerRegistry; @@ -31,6 +32,7 @@ import org.springframework.web.socket.messaging.SessionDisconnectEvent; import org.springframework.web.socket.messaging.SessionSubscribeEvent; import org.springframework.web.socket.messaging.SessionUnsubscribeEvent; +import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean; import static io.xeres.common.message.MessagePath.APP_PREFIX; import static io.xeres.common.message.MessagePath.BROKER_PREFIX; @@ -46,6 +48,16 @@ public class WebSocketMessageBrokerConfiguration implements WebSocketMessageBrok { private static final Logger log = LoggerFactory.getLogger(WebSocketMessageBrokerConfiguration.class); + // See https://stackoverflow.com/questions/21730566/how-to-increase-output-buffer-for-spring-sockjs-websocket-server-implementation + @Bean + public ServletServerContainerFactoryBean createServletServerContainerFactoryBean() + { + var container = new ServletServerContainerFactoryBean(); + container.setMaxTextMessageBufferSize(MAXIMUM_MESSAGE_SIZE); + container.setMaxBinaryMessageBufferSize(MAXIMUM_MESSAGE_SIZE); + return container; + } + @Override public void registerStompEndpoints(StompEndpointRegistry registry) { diff --git a/ui/src/main/java/io/xeres/ui/client/message/MessageClient.java b/ui/src/main/java/io/xeres/ui/client/message/MessageClient.java index 797f50a4..59f0e8e8 100644 --- a/ui/src/main/java/io/xeres/ui/client/message/MessageClient.java +++ b/ui/src/main/java/io/xeres/ui/client/message/MessageClient.java @@ -195,16 +195,14 @@ private void performPendingSubscriptions(StompSession session) @EventListener public void onApplicationEvent(ContextClosedEvent ignored) // we don't use @PreDestroy because the tomcat context is closed before that { - // Only disconnects gracefully on the remote scenario because on the local - // one, the WebSocket will already be closed anyway. - if (future != null && RemoteUtils.isRemoteUiClient()) + if (future != null) { try { - subscriptions.forEach(StompSession.Subscription::unsubscribe); // if the connection is already closed (likely when running on the same host), we catch the MessageDeliveryException below + subscriptions.forEach(StompSession.Subscription::unsubscribe); // if the connection is already closed (likely when running on the same host), we catch the MessageDeliveryException below as well as IllegalStateException future.get().disconnect(); } - catch (MessageDeliveryException | ExecutionException ignoredException) + catch (MessageDeliveryException | IllegalStateException | ExecutionException ignoredException) { // Nothing we can do } diff --git a/ui/src/main/java/io/xeres/ui/client/message/SessionHandler.java b/ui/src/main/java/io/xeres/ui/client/message/SessionHandler.java index 87416631..66ec2ad9 100644 --- a/ui/src/main/java/io/xeres/ui/client/message/SessionHandler.java +++ b/ui/src/main/java/io/xeres/ui/client/message/SessionHandler.java @@ -19,7 +19,10 @@ package io.xeres.ui.client.message; +import io.xeres.ui.support.util.UiUtils; import jakarta.annotation.Nonnull; +import javafx.application.Platform; +import javafx.scene.control.Alert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.messaging.simp.stomp.*; @@ -58,7 +61,8 @@ public void handleTransportError(@Nonnull StompSession session, @Nonnull Throwab { if (exception instanceof ConnectionLostException) { - log.debug("Connection closed"); + log.debug("Connection closed: {}", exception.getMessage()); + Platform.runLater(() -> UiUtils.alert(Alert.AlertType.ERROR, "WebSocket connection lost. Chat messages won't work anymore. Relaunch to fix.")); } else {