java - Stomp over socket using sockjs can't connect with Spring 4 WebSocket -
trying use spring 4 websocket stomp on socket using sockjs. , faced 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 http://localhost:8080/ws/info 404 (not found) sockjs-0.3.js:807 whoops! lost connection undefined stomp.js:130 what wrong?
i've found examples in google (tickerstocks or that, greeting applications (example of spring)) , of them give me same error. trying use websocket handshake (without sockjs) - same result).
addition information:
method public ajaxresponse hello(); placed in indexcontroller on root context "/". can provide full path: http://localhost:8080/ws. deploy tested tomcat7 , tomcat8.
i follow boris spider advice , started use java configuration (appconfig , webinit files) instead of xml configuration files. when finished migration - tried websockets - , works! thought main problem in xml configuration websocket.
Comments
Post a Comment