Skip to content

Commit cc84533

Browse files
committed
Logging decorator for WebSocketStompClient handler
Closes gh-23793
1 parent 6faf61b commit cc84533

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -57,6 +57,7 @@
5757
import org.springframework.web.socket.WebSocketMessage;
5858
import org.springframework.web.socket.WebSocketSession;
5959
import org.springframework.web.socket.client.WebSocketClient;
60+
import org.springframework.web.socket.handler.LoggingWebSocketHandlerDecorator;
6061
import org.springframework.web.socket.sockjs.transport.SockJsSession;
6162
import org.springframework.web.util.UriComponentsBuilder;
6263

@@ -265,7 +266,9 @@ public ListenableFuture<StompSession> connect(URI url, @Nullable WebSocketHttpHe
265266
Assert.notNull(url, "'url' must not be null");
266267
ConnectionHandlingStompSession session = createSession(connectHeaders, sessionHandler);
267268
WebSocketTcpConnectionHandlerAdapter adapter = new WebSocketTcpConnectionHandlerAdapter(session);
268-
getWebSocketClient().doHandshake(adapter, handshakeHeaders, url).addCallback(adapter);
269+
getWebSocketClient()
270+
.doHandshake(new LoggingWebSocketHandlerDecorator(adapter), handshakeHeaders, url)
271+
.addCallback(adapter);
269272
return session.getSessionFuture();
270273
}
271274

spring-websocket/src/test/java/org/springframework/web/socket/messaging/WebSocketStompClientTests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.springframework.web.socket.WebSocketHandler;
4646
import org.springframework.web.socket.WebSocketSession;
4747
import org.springframework.web.socket.client.WebSocketClient;
48+
import org.springframework.web.socket.handler.WebSocketHandlerDecorator;
4849

4950
import static org.junit.Assert.*;
5051
import static org.mockito.Mockito.*;
@@ -317,9 +318,12 @@ private WebSocketHandler connect() {
317318

318319
@SuppressWarnings("unchecked")
319320
private TcpConnection<byte[]> getTcpConnection() throws Exception {
320-
WebSocketHandler webSocketHandler = connect();
321-
webSocketHandler.afterConnectionEstablished(this.webSocketSession);
322-
return (TcpConnection<byte[]>) webSocketHandler;
321+
WebSocketHandler handler = connect();
322+
handler.afterConnectionEstablished(this.webSocketSession);
323+
if (handler instanceof WebSocketHandlerDecorator) {
324+
handler = ((WebSocketHandlerDecorator) handler).getLastHandler();
325+
}
326+
return (TcpConnection<byte[]>) handler;
323327
}
324328

325329
private void testInactivityTaskScheduling(Runnable runnable, long delay, long sleepTime)

0 commit comments

Comments
 (0)