5

I want to create a spring boot app with a web socket client that connects to a web socket server.

As an example, I used the Getting Started guide you can find in Spring Boot.

https://spring.io/guides/gs/messaging-stomp-websocket/

In this example, you create a web socket server using spring boot and you connect to it using JavaScript.

I want to run that server and connect to it using another spring boot application that creates a WebSocketClient object.

This is the WebSocketClientConfiguration class that I created in the Spring Boot client App

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketClientConfig {

    @Bean
    public WebSocketClient webSocketClient() {
        final WebSocketClient client = new StandardWebSocketClient();

        final WebSocketStompClient stompClient = new WebSocketStompClient(client);
        stompClient.setMessageConverter(new MappingJackson2MessageConverter());

        final StompSessionHandler sessionHandler = new MyStompSessionHandler();
        stompClient.connect("ws://localhost:8080", sessionHandler);
        return client;
    }
}

But in my class MyStompSessionHandler, in handleTransportError method I can see that the exception is

javax.websocket.DeploymentException: The HTTP response from the server [200] did not permit the HTTP upgrade to WebSocket

Any idea what I am doing wrong?

1
  • do you have this sample WebSocket Client project? Commented May 11, 2021 at 22:18

1 Answer 1

8

I finally figured out. The reason it was failing it is because you need to put this in the URL

ws://localhost:8080/gs-guide-websocket

Like this URI.create("ws://localhost:8080/gs-guide-websocket")

Sign up to request clarification or add additional context in comments.

1 Comment

Uri is accepted with different signature of .connect() that also accepts WebSocketHttpHeaders in 2nd argument. Could you share the code snippet working for you ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.