Unable to communicate with Web Socket using Stomp in 3rd-party client

Viewed 20

I have created a WebSocket application using Spring Boot(from Spring tutorials).

Application settings:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/arduino");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/arduino-websocket").setAllowedOriginPatterns("*").withSockJS();
    }

    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurerAdapter() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**").allowedOrigins("*");
            }
        };
    }

}

Web socket controller:

@RestController

@MessageMapping("/arduino/api/v1")
@RequestMapping("/arduino/api/v1")
public class ArduinoControllerV1 {

    @Autowired
    private SimpMessagingTemplate template;

    @MessageMapping("/getArduinoResponse")
    @SendTo("/arduino/subscribers")
    public WebSocketResponseEntity getArduinoResponse(WebSocketResponseEntity message) throws Exception {
        return message;
    }


    @PostMapping("/sendCommand")
    public String sendCommand(@RequestBody CommandEntity commandEntity) throws Exception {
        this.template.convertAndSend("/arduino/subscribers", commandEntity.getCommand());
        return String.format("Sending to %s the command: %s ", commandEntity.getDeviceSerial(), commandEntity.getCommand());
    }
}

You can see the full project here

I have also created a JS Client that implements Sock to the server: http://192.168.1.50:8080/arduino-websocket and then subscribes to the channel /arduino/subscribers using Stomp.

After that, the client can send a message through /arduino/api/v1/getArduinoResponse to the server using the Stomp client.

You can see the implementation for the explanation above here.

Currently, I am able to communicate between a different client using that code, the problem is when I'm trying to connect to the socket from a 3rd-party client such as:

  1. PieSocket chrome extension
  2. Web Socket Testing chrome extension

Example response from PieSocket: enter image description here

How can I connect to the WebSocket from 3rd-party clients? What am I missing here?

Full-Disclosure:

Eventually, I want to communicate with Arduino to the server using this WebSocket and it's failing there so I did some step back to see what's missing and it's seems to be I can't log in from 3rd-party client

0 Answers
Related