feat: 提交项目代码

This commit is contained in:
super_liu
2021-05-31 14:56:05 +08:00
parent d50bb875cb
commit 3ed9ca235a
234 changed files with 27792 additions and 0 deletions
@@ -0,0 +1,28 @@
package com.adc.da.websocket.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;
import javax.websocket.server.ServerEndpointConfig.Configurator;
import java.util.Enumeration;
public class GetHttpSessionConfigurator extends Configurator {
private static final Logger logger = LoggerFactory.getLogger(GetHttpSessionConfigurator.class);
@Override
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
HttpSession httpSession=(HttpSession) request.getHttpSession();
Enumeration<String> attributeNames = httpSession.getAttributeNames();
logger.info("---------------------------GetHttpSessionConfigurator--------------------------------");
while (attributeNames.hasMoreElements()){
String s = attributeNames.nextElement();
logger.info("建立session时的属性为:"+s+" 参数为:"+httpSession.getAttribute(s));
}
logger.info("---------------------------GetHttpSessionConfigurator--------------------------------");
sec.getUserProperties().put(HttpSession.class.getName(),httpSession);
}
}
@@ -0,0 +1,25 @@
package com.adc.da.websocket.config;
import com.adc.da.websocket.handler.SpringWebSocketHandler;
import com.adc.da.websocket.interceptor.SpringWebSocketHandlerInterceptor;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.handler.TextWebSocketHandler;
/*@Configuration
@EnableWebSocket*/
public class SpringWebSocketConfig extends WebMvcConfigurerAdapter implements WebSocketConfigurer {
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry.addHandler(webSocketHandler(),"/websocket/socketServer").addInterceptors(new SpringWebSocketHandlerInterceptor()).setAllowedOrigins("*");
registry.addHandler(webSocketHandler(), "/sockjs/socketServer").addInterceptors(new SpringWebSocketHandlerInterceptor()).setAllowedOrigins("*").withSockJS();
}
// @Bean
public TextWebSocketHandler webSocketHandler(){
return new SpringWebSocketHandler();
}
}
@@ -0,0 +1,15 @@
package com.adc.da.websocket.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
@Configuration
public class WebSocketConfig {
@Bean
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
}