feat: add web proxy support

Signed-off-by: MiaoWoo <admin@yumc.pw>
master
MiaoWoo 2020-05-30 10:21:17 +08:00
parent 17d07d6cef
commit 219eb6b919
4 changed files with 11 additions and 12 deletions

View File

@ -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;
}
}

View 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);
}

View File

@ -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);

View File

@ -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) {