Sunday, 15 May 2011

glassfish 4 - PathParam from previous websocket call is submitted -



glassfish 4 - PathParam from previous websocket call is submitted -

i using javaee 7 , glassfish 4 project setup , utilize websockets. browser have used chrome 35.0.1916.153. endpoint should receive message through websockets , broadcast message other users within same group.

if open 2 browser tabs open websocket connections different groups [e.g. first 1, 2 (the order matters!)] works expected. when phone call broadcast method first tab (groupid=1) groupid path parameter has value 2. looks lastly onopen call's value.

in phone call session object looks this:

session = (org.glassfish.tyrus.core.sessionimpl) sessionimpl{ uri=/test/group/1, <-- id='0fcff8ae-7ff8-42e8-a9e9-03cbb1f62562', endpoint=endpointwrapper{ endpointclass=null, endpoint=org.glassfish.tyrus.core.annotatedendpoint@59d91963, uri='/test/group/2', <-- contextpath='/test' } }

the uri session , endpoint differ may result in unwanted behavior.

has noted yet?

my endpoint class looks this:

@serverendpoint(value = "/group/{groupid}", encoders = {messageencoder.class}, decoders = {messagedecoder.class}) public class groupendpoint { private map<string, set<session>> groups = groupsingleton.getgroups(); @onmessage public void broadcast(@pathparam("groupid") string groupid, message message, session session) throws ioexception, encodeexception { (session session : groups.get(groupid)) session.getbasicremote().sendobject(message); } @onopen public void onopen(@pathparam("groupid") string groupid, session session){ if(groups.containskey(property)){ // add together peer list of viewers groups.get(groupid).add(session); }else{ // if not start new list set<session> sessions = collections.synchronizedset(new hashset<session>()); sessions.add(session); groups.put(groupid, sessions); } } @onclose public void onclose(@pathparam("groupid") string groupid, session session) { groups.get(groupid).remove(session); if(groups.get(groupid).isempty()) groups.remove(groupid); } }

this known bug, tracked tyrus-203, fixed in tyrus 1.1

can please useone of promoted glassfish builds?

thanks, pavel

websocket glassfish-4 java-ee-7

No comments:

Post a Comment