@@ -8,13 +8,10 @@ import org.springframework.stereotype.Component;
 | 
			
		||||
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import javax.annotation.PreDestroy;
 | 
			
		||||
 | 
			
		||||
@Slf4j
 | 
			
		||||
@Component
 | 
			
		||||
public class MiaoScriptSpring {
 | 
			
		||||
    private ScriptEngine engine;
 | 
			
		||||
 | 
			
		||||
    @Bean
 | 
			
		||||
    @SneakyThrows
 | 
			
		||||
    public ScriptEngine buildScriptEngine(ApplicationContext applicationContext) {
 | 
			
		||||
@@ -25,10 +22,4 @@ public class MiaoScriptSpring {
 | 
			
		||||
    public ServerEndpointExporter serverEndpointExporter() {
 | 
			
		||||
        return new ServerEndpointExporter();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PreDestroy
 | 
			
		||||
    public void disableEngine() {
 | 
			
		||||
        engine.disableEngine();
 | 
			
		||||
        engine = null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										8
									
								
								src/main/java/pw/yumc/MiaoScript/web/WebServerProxy.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/main/java/pw/yumc/MiaoScript/web/WebServerProxy.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
package pw.yumc.MiaoScript.web;
 | 
			
		||||
 | 
			
		||||
import javax.servlet.http.HttpServletRequest;
 | 
			
		||||
import javax.servlet.http.HttpServletResponse;
 | 
			
		||||
 | 
			
		||||
public interface WebServerProxy {
 | 
			
		||||
    Object process(HttpServletRequest req, HttpServletResponse resp);
 | 
			
		||||
}
 | 
			
		||||
@@ -4,7 +4,7 @@ import javax.websocket.CloseReason;
 | 
			
		||||
import javax.websocket.EndpointConfig;
 | 
			
		||||
import javax.websocket.Session;
 | 
			
		||||
 | 
			
		||||
public interface WebSocketServerProxy {
 | 
			
		||||
public interface WebSocketProxy {
 | 
			
		||||
    void onOpen(Session session, EndpointConfig config);
 | 
			
		||||
 | 
			
		||||
    void onMessage(Session session, String message);
 | 
			
		||||
@@ -14,12 +14,12 @@ import javax.websocket.server.ServerEndpoint;
 | 
			
		||||
@ServerEndpoint("/ws/")
 | 
			
		||||
public class WebSocketServer implements ApplicationContextAware {
 | 
			
		||||
    private static ApplicationContext context;
 | 
			
		||||
    private WebSocketServerProxy proxy;
 | 
			
		||||
    private WebSocketProxy proxy;
 | 
			
		||||
 | 
			
		||||
    private boolean checkProxy(Session session) {
 | 
			
		||||
        try {
 | 
			
		||||
            if (this.proxy == null) {
 | 
			
		||||
                this.proxy = context.getBean(WebSocketServerProxy.class);
 | 
			
		||||
                this.proxy = context.getBean(WebSocketProxy.class);
 | 
			
		||||
            }
 | 
			
		||||
            return true;
 | 
			
		||||
        } catch (Exception ex) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user