Skip to content

Commit 4b1d021

Browse files
yasin3061maibin
authored andcommitted
BAEL-252 A Java Client to consume a WebSockets API (eugenp#2048)
* BAEL-900 Guide to dynamic tests in Junit 5 * BAEL-900 Guide to Dynamic Tests in Junit 5 * Revert "BAEL-900 Guide to Dynamic Tests in Junit 5" This reverts commit d0d45c9. * BAEL-900 Guide to Dynamic Tests in Junit 5 * BAEL-900 Guide to dynamic tests in Junit 5 * removed unnecessary annotation * BAEL-900 unused imports removed * BAEL-900 simplified input generator code * BAEL-252 A Java Client to consume a WebSockets API
1 parent ed082d3 commit 4b1d021

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

‎spring-boot/src/main/java/org/baeldung/websocket/client/StompClient.java‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
11
package org.baeldung.websocket.client;
22

3-
import java.util.Collections;
4-
import java.util.List;
53
import java.util.Scanner;
64

75
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
86
import org.springframework.messaging.simp.stomp.StompSessionHandler;
7+
import org.springframework.web.socket.client.WebSocketClient;
98
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
109
import org.springframework.web.socket.messaging.WebSocketStompClient;
11-
import org.springframework.web.socket.sockjs.client.SockJsClient;
12-
import org.springframework.web.socket.sockjs.client.Transport;
13-
import org.springframework.web.socket.sockjs.client.WebSocketTransport;
1410

1511
/**
1612
* Stand alone WebSocketStompClient.
17-
* @author Kalyan
1813
*
1914
*/
2015
public class StompClient {
2116

2217
private static String URL = "ws://localhost:8080/spring-mvc-java/chat";
2318

2419
public static void main(String[] args) {
25-
Transport webSocketTransport = new WebSocketTransport(new StandardWebSocketClient());
26-
List<Transport> transports = Collections.singletonList(webSocketTransport);
27-
SockJsClient sockJsClient = new SockJsClient(transports);
28-
29-
WebSocketStompClient stompClient = new WebSocketStompClient(sockJsClient);
20+
WebSocketClient client = new StandardWebSocketClient();
21+
WebSocketStompClient stompClient = new WebSocketStompClient(client);
22+
3023
stompClient.setMessageConverter(new MappingJackson2MessageConverter());
31-
24+
3225
StompSessionHandler sessionHandler = new MyStompSessionHandler();
3326
stompClient.connect(URL, sessionHandler);
3427

0 commit comments

Comments
 (0)