stomp - How to send message to the particular user using Spring Web Sockets? -
i unable send message particular user using spring web sockets here code. here when used send message getting org.springframework.messaging.simp.annotation.support.missingsessionuserexception: no "user" header in message
please tell me how avoid this. in advance.
controller.java
@messagemapping("/sendmessage") public void getmessage(string message,principal principal){ this.template.convertandsendtouser(principal.getname(),"/topic/messages",message); } index.jsp
function connect() { var socket = new sockjs('/springwebsocket/chat'); stompclient = stomp.over(socket); stompclient.connect({}, function(frame) { setconnected(true); console.log('connected: ' + frame); stompclient.subscribe('/user/queue/messages', function(messageoutput) { alert("respose"); }); }); } function sendmessage() { var = document.getelementbyid('from').value; var text = document.getelementbyid('text').value; stompclient.send("/app/sendmessage", {}, json.stringify({ 'from' : from, 'text' : text, })); } spring-servlet.xml:
<context:component-scan base-package="com.test"/> <mvc:annotation-driven></mvc:annotation-driven> <bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix" value="/web-inf/views/"> </property> <property name="suffix" value=".jsp"> </property> </bean> <websocket:message-broker application-destination-prefix="/app" > <websocket:stomp-endpoint path="/chat"> <websocket:sockjs/> </websocket:stomp-endpoint> <websocket:simple-broker prefix="/topic, /queue"/> </websocket:message-broker>
instead of this.template.convertandsendtouser(principal.getname(),"/topic/messages",message); use following this.template.convertandsendtouser(principal.getname(),"/queue/messages",message);
Comments
Post a Comment