1***@163.com
1***@163.com
  • 发布:2019-08-20 10:16
  • 更新:2020-05-12 10:23
  • 阅读:1911

5+app访问webSocket后台服务时,sessionId与登陆时不一致

分类:HTML5+

首先在PC端用手机模拟器是没有问题的。
然后第一次安装到手机上使用时,new WebSocket("ws://url");还报了302状态。因为后台是shiro框架,我直接把socket服务取消登陆拦截了。但是还是会在登陆验证时保存session对象。
@Override
protected boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletRequest request, ServletResponse response) throws Exception {
Pager pager = new Pager();
String username = (String) token.getPrincipal();
// 获取用户
User user = userService.getUserByUsername(username);
//将用户信息添加到session
Session session = subject.getSession();
session.setAttribute("user",user);
System.out.println(session.getId());
.........

然后问题又来了,在WebSocket服务类中获取到session后没有user对象,并且查看sessionId也不一致
@OnOpen
public void onOpen(Session session,EndpointConfig config) {
httpSession = (HttpSession) config.getUserProperties().get(HttpSession.class.getName());
//TODO:PDA访问时Attributes中没有user对象
User user = (User)httpSession.getAttribute("user");
this.session = session;
this.userId = user.getId();
System.out.println("有用户连接了:"+userId);
webSocketMap.put(user.getId(), this);
........

2019-08-20 10:16 负责人:无 分享
已邀请:
中国小伙

中国小伙

请问您这个问题解决了嘛! 我现在也遇到这个问题了

该问题目前已经被锁定, 无法添加新回复