diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java index b9f05e64bb..8e3a2016d7 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -109,8 +109,7 @@ public class DefaultStompSession implements ConnectionHandlingStompSession { private final Map receiptHandlers = new ConcurrentHashMap<>(4); - /* Whether the client is willfully closing the connection */ - private volatile boolean closing; + private volatile boolean clientSideClose; /** @@ -368,7 +367,7 @@ public class DefaultStompSession implements ConnectionHandlingStompSession { @Override public void disconnect(@Nullable StompHeaders headers) { - this.closing = true; + this.clientSideClose = true; try { StompHeaderAccessor accessor = createHeaderAccessor(StompCommand.DISCONNECT); if (headers != null) { @@ -519,7 +518,7 @@ public class DefaultStompSession implements ConnectionHandlingStompSession { if (logger.isDebugEnabled()) { logger.debug("Connection closed in session id=" + this.sessionId); } - if (!this.closing) { + if (!this.clientSideClose) { resetConnection(); handleFailure(new ConnectionLostException("Connection closed")); } @@ -729,11 +728,11 @@ public class DefaultStompSession implements ConnectionHandlingStompSession { @Override public void run() { - closing = true; - String error = "Server has gone quiet. Closing connection in session id=" + sessionId + "."; + String error = "Read inactivity. Closing connection in session id=" + sessionId + "."; if (logger.isDebugEnabled()) { logger.debug(error); } + clientSideClose = true; resetConnection(); handleFailure(new IllegalStateException(error)); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java index a6ebe75ec2..def88837c7 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -372,7 +372,7 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif private class WebSocketTcpConnectionHandlerAdapter implements BiConsumer, WebSocketHandler, TcpConnection { - private final TcpConnectionHandler connectionHandler; + private final TcpConnectionHandler stompSession; private final StompWebSocketMessageCodec codec = new StompWebSocketMessageCodec(getInboundMessageSizeLimit()); @@ -385,9 +385,9 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif private final List> inactivityTasks = new ArrayList<>(2); - public WebSocketTcpConnectionHandlerAdapter(TcpConnectionHandler connectionHandler) { - Assert.notNull(connectionHandler, "TcpConnectionHandler must not be null"); - this.connectionHandler = connectionHandler; + public WebSocketTcpConnectionHandlerAdapter(TcpConnectionHandler stompSession) { + Assert.notNull(stompSession, "TcpConnectionHandler must not be null"); + this.stompSession = stompSession; } // CompletableFuture callback implementation: handshake outcome @@ -395,7 +395,7 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif @Override public void accept(@Nullable WebSocketSession webSocketSession, @Nullable Throwable throwable) { if (throwable != null) { - this.connectionHandler.afterConnectFailure(throwable); + this.stompSession.afterConnectFailure(throwable); } } @@ -404,7 +404,7 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif @Override public void afterConnectionEstablished(WebSocketSession session) { this.session = session; - this.connectionHandler.afterConnected(this); + this.stompSession.afterConnected(this); } @Override @@ -415,23 +415,23 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif messages = this.codec.decode(webSocketMessage); } catch (Throwable ex) { - this.connectionHandler.handleFailure(ex); + this.stompSession.handleFailure(ex); return; } for (Message message : messages) { - this.connectionHandler.handleMessage(message); + this.stompSession.handleMessage(message); } } @Override - public void handleTransportError(WebSocketSession session, Throwable ex) throws Exception { - this.connectionHandler.handleFailure(ex); + public void handleTransportError(WebSocketSession session, Throwable ex) { + this.stompSession.handleFailure(ex); } @Override - public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception { + public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) { cancelInactivityTasks(); - this.connectionHandler.afterConnectionClosed(); + this.stompSession.afterConnectionClosed(); } private void cancelInactivityTasks() {