java - MissingSessionUser Exeption in Sockjs with Spring -
java - MissingSessionUser Exeption in Sockjs with Spring -
i trying create chat application websocket. able send message of connected client, , trying send message single user.
script:
var socket = new sockjs("server endpoint");
subscribe
stompclient.subscribe('/topic/chat', rendermessage);
connection
stompclient.connect("guest", "guest", connectcallback, errorcallback);
where send
stompclient.send("/app/addmessage", {}, jsonstr);
and in spring config
<websocket:message-broker application-destination-prefix="/app"> <websocket:stomp-endpoint path="/ws"> <websocket:sockjs /> </websocket:stomp-endpoint> <websocket:simple-broker prefix="/topic" /> <websocket:client-inbound-channel> <websocket:interceptors> <bean class="com.websocket.interceptor.connectioninterceptor" /> </websocket:interceptors> </websocket:client-inbound-channel> </websocket:message-broker>
method trying send single user
@messagemapping("/addmessage") public void addchatmessage(chatmessage chatmessage, simpmessageheaderaccessor headeraccessor,principal principal) throws exception { chatmessagelist.add(chatmessage); //trying output user returns null system.out.println(headeraccessor.getuser()); //returns null system.out.println(principal.getname()); //not sending current user template.convertandsendtouser("user", "/topic/chat", chatmessagelist); }
and in browser tried open console , can see header undefined
connected server undefined >>> subscribe id:sub-0 destination:/topic/chat
stack trace
oct 13, 2014 9:53:36 org.springframework.messaging.simp.annotation.support.simpannotationmethodmessagehandler processhandlermethodexception severe: unhandled exception org.springframework.messaging.simp.annotation.support.missingsessionuserexception: no "user" header in message @ org.springframework.messaging.simp.annotation.support.principalmethodargumentresolver.resolveargument(principalmethodargumentresolver.java:43) @ org.springframework.messaging.handler.invocation.handlermethodargumentresolvercomposite.resolveargument(handlermethodargumentresolvercomposite.java:81) @ org.springframework.messaging.handler.invocation.invocablehandlermethod.getmethodargumentvalues(invocablehandlermethod.java:128) @ org.springframework.messaging.handler.invocation.invocablehandlermethod.invoke(invocablehandlermethod.java:97) @ org.springframework.messaging.handler.invocation.abstractmethodmessagehandler.handlematch(abstractmethodmessagehandler.java:451) @ org.springframework.messaging.simp.annotation.support.simpannotationmethodmessagehandler.handlematch(simpannotationmethodmessagehandler.java:363) @ org.springframework.messaging.simp.annotation.support.simpannotationmethodmessagehandler.handlematch(simpannotationmethodmessagehandler.java:80) @ org.springframework.messaging.handler.invocation.abstractmethodmessagehandler.handlemessageinternal(abstractmethodmessagehandler.java:409) @ org.springframework.messaging.handler.invocation.abstractmethodmessagehandler.handlemessage(abstractmethodmessagehandler.java:345) @ org.springframework.messaging.support.executorsubscribablechannel$1.run(executorsubscribablechannel.java:70) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ java.lang.thread.run(thread.java:744)
how can send single user? how can headers in simpmessageheaderaccessor? , how headers work?
when subscribe need utilize "/user/"
prefix create recognized spring userdestinationmessagehandler
. code :
stompclient.subscribe('user/topic/chat', rendermessage);
see spring websocket user destinations.
java spring header stomp spring-websocket
Comments
Post a Comment