我正在使用SpringBoot尝试通过websocket连接到janus。我收到一个http请求,然后将命令发送给janus。
我在自己的机器上使用janus on docker,在执行第一个请求后,尝试升级连接(http>ws)时出现异常。
java.util.concurrent.executionexception:javax.websocket.deploymentexception:初始化到[ws://172.17.0.2:8188/janus]的websocket连接的http请求失败,原因是:javax.websocket.deploymentexception:初始化到[ws://172.17.0.2:8188/janus]的websocket连接的http请求失败
原因:java.io.eofexception:到websocket的http升级失败,但可能已收到部分数据:状态代码[0],http头[{}]
这是我的websocketconfiguration类:
@EnableWebSocket
@Configuration
public class WebSocketConfiguration implements WebSocketConfigurer {
private final MessageDelegator handler;
private final Logger logger = LoggerFactory.getLogger(this.getClass().getName());
@Autowired
public WebSocketConfiguration(MessageDelegator handler) {
this.handler = handler;
}
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
RequestUpgradeStrategy upgradeStrategy = new TomcatRequestUpgradeStrategy();
registry.addHandler(handler, "/player")
.setAllowedOrigins("*")
.addInterceptors(new HandshakeConfiguration())
.setHandshakeHandler(new DefaultHandshakeHandler(upgradeStrategy));
logger.info("WebSocket endpoint: :8666/player");
}
}
握手配置是一个拦截器:
public class HandshakeConfiguration implements HandshakeInterceptor {
private Logger logger = LoggerFactory.getLogger(this.getClass().getName());
@Override
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
logger.info(request.getHeaders().toString());
request.getHeaders().add("sec-websocket-Protocol", "janus-protocol");
logger.info(request.getHeaders().toString());
return true;
}
@Override
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) {
logger.info(response.getHeaders().toString());
}
}
握手前:
m、 f.w.j.e.w.c.握手配置:[主机:”localhost:8666,upgrade:“websocket”,connection:“upgrade”,sec websocket key:“ynzls1po5dl3awtf/jpd1g==”,sec websocket version:“13”,sec websocket extensions:“permessage deflate;客户端\u最大\u窗口\u位”,用户代理:“python/3.6 websockets/8.1”]
正在添加websocket子策略:
m、 f.w.j.e.w.c.握手配置:[主机:”localhost:8666,upgrade:“websocket”,connection:“upgrade”,sec websocket key:“ynzls1po5dl3awtf/jpd1g==”,sec websocket version:“13”,sec websocket extensions:“permessage deflate;客户端\u最大\u窗口\u位”,用户代理:“python/3.6 websockets/8.1”,sec websocket协议:“janus协议”]
握手后:m.f.w.j.e.w.c.握手配置:[]
暂无答案!
目前还没有任何答案,快来回答吧!