Search in sources :

Example 1 with ApplicationScopeBean

use of com.ngtesting.platform.bean.ApplicationScopeBean in project ngtesting-platform by aaronchen2k.

the class WebSocketHandshakeInterceptor method beforeHandshake.

@Override
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
    ApplicationScopeBean scopeBean = SpringContextHolder.getBean(ApplicationScopeBean.class);
    if (request instanceof ServletServerHttpRequest) {
        ServletServerHttpRequest servletRequest = (ServletServerHttpRequest) request;
        HttpSession httpSession = servletRequest.getServletRequest().getSession(true);
        String test = (String) httpSession.getAttribute("TEST");
        UserVo user = null;
        if (httpSession.getAttribute(Constant.HTTP_SESSION_USER_KEY) != null) {
            user = (UserVo) httpSession.getAttribute(Constant.HTTP_SESSION_USER_KEY);
        }
        if (user != null) {
            attributes.put(WsConstant.WS_USER_KEY, user.getId().toString());
            attributes.put("somthing", "somthing");
            return true;
        }
    }
    return false;
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) UserVo(com.ngtesting.platform.vo.UserVo) HttpSession(javax.servlet.http.HttpSession) ApplicationScopeBean(com.ngtesting.platform.bean.ApplicationScopeBean)

Aggregations

ApplicationScopeBean (com.ngtesting.platform.bean.ApplicationScopeBean)1 UserVo (com.ngtesting.platform.vo.UserVo)1 HttpSession (javax.servlet.http.HttpSession)1 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)1