feat: add web proxy support
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
17d07d6cef
commit
219eb6b919
@ -8,13 +8,10 @@ import org.springframework.stereotype.Component;
|
|||||||
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import javax.annotation.PreDestroy;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class MiaoScriptSpring {
|
public class MiaoScriptSpring {
|
||||||
private ScriptEngine engine;
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public ScriptEngine buildScriptEngine(ApplicationContext applicationContext) {
|
public ScriptEngine buildScriptEngine(ApplicationContext applicationContext) {
|
||||||
@ -25,10 +22,4 @@ public class MiaoScriptSpring {
|
|||||||
public ServerEndpointExporter serverEndpointExporter() {
|
public ServerEndpointExporter serverEndpointExporter() {
|
||||||
return new 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.EndpointConfig;
|
||||||
import javax.websocket.Session;
|
import javax.websocket.Session;
|
||||||
|
|
||||||
public interface WebSocketServerProxy {
|
public interface WebSocketProxy {
|
||||||
void onOpen(Session session, EndpointConfig config);
|
void onOpen(Session session, EndpointConfig config);
|
||||||
|
|
||||||
void onMessage(Session session, String message);
|
void onMessage(Session session, String message);
|
@ -14,12 +14,12 @@ import javax.websocket.server.ServerEndpoint;
|
|||||||
@ServerEndpoint("/ws/")
|
@ServerEndpoint("/ws/")
|
||||||
public class WebSocketServer implements ApplicationContextAware {
|
public class WebSocketServer implements ApplicationContextAware {
|
||||||
private static ApplicationContext context;
|
private static ApplicationContext context;
|
||||||
private WebSocketServerProxy proxy;
|
private WebSocketProxy proxy;
|
||||||
|
|
||||||
private boolean checkProxy(Session session) {
|
private boolean checkProxy(Session session) {
|
||||||
try {
|
try {
|
||||||
if (this.proxy == null) {
|
if (this.proxy == null) {
|
||||||
this.proxy = context.getBean(WebSocketServerProxy.class);
|
this.proxy = context.getBean(WebSocketProxy.class);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
Loading…
Reference in New Issue
Block a user