我正在按照 jBoss 文档将 websocket 包含在使用 jBoss 7 构建的服务中。
我已经创建了接口及其实现以及所需的注释:
@ServerEndpoint("/websocket/helloworld")
public interface MyService {
@OnMessage
String sayHello(String name);
@OnOpen
void helloOnOpen(Session session);
@OnClose
void helloOnClose(CloseReason reason);
}
而且我还在父 pom 和控制器所在的 weblayer 中添加了所需的依赖项。
<dependency>
<groupId>org.jboss.spec.javax.websocket</groupId>
<artifactId>jboss-websocket-api_1.0_spec</artifactId>
<version>1.0.0.Final</version>
<scope>provided</scope>
</dependency>
Websocket 未正确处理,我无法连接到它。查看服务器访问日志,我可以看到我正在访问服务器
{"ident": "-","auth": "-","logdate": "[30/Aug/2023:18:20:36 +0200]","client": {"ip": "172.18.0.1","user_agent": "-"},"verb": "GET","http": {"protocol": "HTTP/1.1","request": {"path": "/genesys-chat/websocket/helloworld","clientVersion": "-","query-string": "-"},"response": {"status": "404","bytes": "68","time": "5"}}, "type":"standard", "logname":"jbossweb_access.log"}
如您所见,请求被处理为普通的 HTTP GET 请求。调试一下可以看到undertow使用的handle是HTTP的。
请求已完成,邮递员指向
ws://localhost:8080/genesys-chat/websocket/helloworld
我错过了什么吗?
对于初学者,您需要编写一个实现而不是接口,请查看已发布的快速入门列表