Video in progress
How do you test a WebSocket endpoint by hand?
The quickest way is the wscat or websocat CLI tools and the Network → WS tab in the browser DevTools. Postman also supports WebSocket requests. For STOMP you have to write the frames by hand, or connect through stomp.js from a small HTML page.
📖 Answer
From the terminal:
npx wscat -c ws://localhost:8080/ws/echo
> salom
< echo: salom
If you need a token, pass it as a header:
npx wscat -c ws://localhost:8080/ws -H "Authorization: Bearer eyJ..."
In the browser, go to DevTools → Network → "WS" filter, select the connection and open the "Messages" tab. Every frame sent and received is listed with its time. For handshake problems, look at the status code in the "Headers" tab: if it isn't 101, the problem hasn't even reached WebSocket yet.
Testing STOMP by hand is awkward because every frame has to end with a null byte. I usually keep a 20-line test HTML page around: it connects with stomp.js, subscribes, and prints everything it receives on the screen.
For automated checks, you write an integration test with Spring's WebSocketStompClient.
Sign up to mark studied questions and save your progress.