lxw
2023-05-25 f3c27fb78447449a950ba73c5e72ceda64ad8a12
src/main/java/com/whyc/config/WebSocketConfig.java
@@ -1,11 +1,29 @@
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 {
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();
        if(httpSession!=null) {
            sec.getUserProperties().put("httpSession", httpSession);
        }
        super.modifyHandshake(sec, request, response);
    }
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {