已提交上一个websocket调用中的PathParam
我正在使用JavaEE7和Glassfish 4作为我的项目设置,我想使用WebSocket。作为浏览器,我使用了Chrome 35.0.1916.153。我的端点应该通过WebSocket接收消息,并将此消息广播给同一组中的其他用户 如果我打开两个浏览器选项卡,打开与不同组的websocket连接[例如,首先是1,然后是2(顺序很重要!)],一切正常。但是当我通过第一个选项卡(groupId=1)调用广播方法时,groupId path参数的值为2。看起来这是最后一次onOpen调用的值 在此调用中,会话对象如下所示:已提交上一个websocket调用中的PathParam,websocket,glassfish-4,java-ee-7,Websocket,Glassfish 4,Java Ee 7,我正在使用JavaEE7和Glassfish 4作为我的项目设置,我想使用WebSocket。作为浏览器,我使用了Chrome 35.0.1916.153。我的端点应该通过WebSocket接收消息,并将此消息广播给同一组中的其他用户 如果我打开两个浏览器选项卡,打开与不同组的websocket连接[例如,首先是1,然后是2(顺序很重要!)],一切正常。但是当我通过第一个选项卡(groupId=1)调用广播方法时,groupId path参数的值为2。看起来这是最后一次onOpen调用的值 在此
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'
}
}
@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 {
for (Session session : groups.get(groupId))
session.getBasicRemote().sendObject(message);
}
@OnOpen
public void onOpen(@PathParam("groupId") String groupId,
Session session){
if(groups.containsKey(property)){
// then add peer to the list of viewers
groups.get(groupId).add(session);
}else{
// if not start a 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);
}
}
session=(org.glassfish.tyrus.core.SessionImpl)SessionImpl{
uri=/test/group/1,这是一个已知的bug,跟踪为,在Tyrus 1.1中修复
你能使用其中一个版本吗
谢谢,
帕维尔