探究springboot集成websocket,连接不上,使用netty-websocket却能连接上

原因:集成spring-security了。把websocket请求拦截了,且不输出日志(因为一般spring相关日志级别是warn。debug模式下日志太多了

然后可以修改undertow日志级别看日志

# 日志配置
logging:
  level:
    com.cas.wict: debug
    org.springframework: warn
    org.springframework.web: debug
    io.undertow: debug

关键日志输出

2024-07-11 10:15:43.292 [XNIO-1 task-1] DEBUG io.undertow.request.security
 - Attempting to authenticate /ws, authentication required: false
2024-07-11 10:15:43.293 [XNIO-1 task-1] DEBUG io.undertow.request.security
 - Authentication outcome was NOT_ATTEMPTED with method io.undertow.security.impl.CachedAuthenticatedSessionMechanism@7fedbc60 for /ws
2024-07-11 10:15:43.293 [XNIO-1 task-1] DEBUG io.undertow.request.security
 - Authentication result was ATTEMPTED for /ws

发现可能是security对ws请求路径进行了拦截(为什么会拦截,猜测虽然写的是ws,但是发起的时候还是http,由后台升级成websocket)

解决办法:放开验证,单独写过滤器验证ws的请求

为什么以前用netty-websocket可以连接,那是因为netty没走spring-security的过滤器链

相关推荐

  1. Springboot配置websocket,https使用 WebSocket 连接

    2024-07-15 19:34:02       31 阅读
  2. Netty Websocket SpringBoot Starter

    2024-07-15 19:34:02       23 阅读
  3. SpringBoot集成WebSocket

    2024-07-15 19:34:02       65 阅读
  4. springboot +vue 集成websocket

    2024-07-15 19:34:02       47 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-15 19:34:02       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-15 19:34:02       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-15 19:34:02       58 阅读
  4. Python语言-面向对象

    2024-07-15 19:34:02       69 阅读

热门阅读

  1. 两个事务update同一条数据会发生什么?

    2024-07-15 19:34:02       22 阅读
  2. 浏览器渲染流程

    2024-07-15 19:34:02       21 阅读
  3. Redis Cluster 工具

    2024-07-15 19:34:02       16 阅读
  4. leensa注册码

    2024-07-15 19:34:02       26 阅读