把原来的启动方式
UndertowServer.start(JfinalConfig.class);
换成
UndertowServer.create(new UndertowConfig(JfinalConfig.class)).addWebSocketEndpoint(TestWebSocket.class).start();
然后TestWebSocket里面加上@ServerEndpoint注解
再需要一个Handler拦截websocket请求
WebSocketHandler Handler { Pattern ; WebSocketHandler(String filterUrlRegx) { (StrKit.(filterUrlRegx)) IllegalArgumentException(); = Pattern.(filterUrlRegx); } handle(String s, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, [] booleans) { (.matcher(s).find()){ ; }{ .handle(s, httpServletRequest, httpServletResponse, booleans); } } }
最后在JfinalConfig里面加上
configHandler(Handlers me) { me.add(WebSocketHandler()); }
大功告成
UndertowServer.create(...).configWeb( builder -》 {
builder.addWebSocketEndpoint(...);
}).start();
方法名都没变,配置的方式稍微变了一下