码迷,mamicode.com
首页 > Web开发 > 详细

websocket failed: Error during WebSocket handshake: Unexpected response code: 200

时间:2016-11-27 07:53:14      阅读:724      评论:0      收藏:0      [点我收藏+]

标签:throw   row   ssi   public   boolean   handler   uri   异常   .com   

websocket+spring整合,不能访问,

技术分享

解读源码:

技术分享

原因:websocket_username=null,导致空异常

解决:给websocket session 添加用户名

//握手前,读取用户名,并赋值给websocket的session
    @Override
    public boolean beforeHandshake(ServerHttpRequest request,
            ServerHttpResponse response, WebSocketHandler handler,
            Map<String, Object> attr) throws Exception {        
         if (request instanceof ServletServerHttpRequest) {
                ServletServerHttpRequest servletRequest = (ServletServerHttpRequest) request;
                HttpSession session = servletRequest.getServletRequest().getSession(false);
                if (session != null) {
                    String userName = (String) session.getAttribute(Constants.SESSION_USERNAME);
                    if(userName == null){
                        userName = "WEBSOCKET_USERNAME_IS_NULL";
                    }
                    attr.put(Constants.WEBSOCKET_USERNAME,userName);
                }
            }
        return true;
    }

 

websocket failed: Error during WebSocket handshake: Unexpected response code: 200

标签:throw   row   ssi   public   boolean   handler   uri   异常   .com   

原文地址:http://www.cnblogs.com/caer/p/6105854.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!