0

I am trying to subscribe to a particular channel in spring web sockets but while pointing to a URL using SockJs i getting the following error WebSocket connection to 'ws://localhost:8080/Spring/rest/user/chat/045/jmfz3b3j/websocket' failed: Error during WebSocket handshake: Unexpected response code: 200 Please help me to avoid this. Here is my client side code for subscription.

Index.jsp

var stompClient =null;
      function subscribe(){ 
var socket = new SockJS('/Spring/rest/user/chat');
stompClient = Stomp.over(socket);
stompClient.connect({}, function(frame) {
     console.log('Connected: ' + frame);
     stompClient.subscribe('/topic/messages', function(test) {
       alert("in call back function");});
 });
 }

1 Answers1

-1

@Kane This is my websocket configuration in spring-servlet.xml

<websocket:message-broker application-destination-prefix="/app" >
    <websocket:stomp-endpoint path="/chat" allowed-origins="*">
        <websocket:sockjs />
    </websocket:stomp-endpoint>
    <websocket:simple-broker prefix="/topic"/>
</websocket:message-broker>

And this is my controller code

@Controller
@RequestMapping("user")
public class OptnCptController{
    @MessageMapping("topic/messages")
    public String getMsg(String s)
    {
        return s;
    }
}