Trying to use Spring 4 WebSocket with STOMP over socket using sockjs. And i faced a problem.
My configuration:
websocket.xml - part of spring context
<websocket:message-broker application-destination-prefix="/app">
<websocket:stomp-endpoint path="/ws">
<websocket:sockjs/>
</websocket:stomp-endpoint>
<websocket:simple-broker prefix="/topic"/>
</websocket:message-broker>
Controller code:
@MessageMapping("/ws")
@SendTo("/topic/ws")
public AjaxResponse hello() throws Exception {
AjaxResponse ajaxResponse = new AjaxResponse();
ajaxResponse.setSuccess(true);
ajaxResponse.addSuccessMessage("WEB SOCKET!!! HELL YEAH!");
return ajaxResponse;
}
Client side:
var socket = new SockJS("<c:url value='/ws'/>");
var stompClient = Stomp.over(socket);
stompClient.connect({}, function(frame) {
alert('Connected: ' + frame);
stompClient.send("/app/ws", {}, {});
stompClient.subscribe('/topic/ws', function(response){
alert(response.success);
});
});
Output:
Opening Web Socket... stomp.js:130
GET http://localhost:8080/ws/info 404 (Not Found) sockjs-0.3.js:807
Whoops! Lost connection to undefined stomp.js:130
What i do wrong?
I've found examples in google (TickerStocks or something like that, greeting applications (example of Spring)) and all of them give me the same error. I trying use WebSocket with handshake (without sockjs) - same result).
ADDITION INFORMATION:
Method public AjaxResponse hello();
placed in IndexController on root context "/". So i can provide full path: http://localhost:8080/ws
.
To deploy tested tomcat7 and tomcat8.