whycxzp
2022-04-06 eb9f1652809815a13b05018712fa9a6bb5d9648f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.whyc.config;
 
import org.apache.catalina.session.StandardSessionFacade;
import org.apache.shiro.web.servlet.ShiroHttpSession;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
 
import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpoint;
import javax.websocket.server.ServerEndpointConfig;
 
@Configuration
public class WebSocketConfig extends ServerEndpointConfig.Configurator {
 
    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        //HttpSession httpSession = (ShiroHttpSession) request.getHttpSession();
        HttpSession httpSession = (HttpSession)request.getHttpSession();
        sec.getUserProperties().put("httpSession",httpSession);
        super.modifyHandshake(sec, request, response);
    }
 
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }
 
}