JAX-RS @ServerEndpoint Websocket用jersey部署

我已经用jax-rs制作了一个简单的websocket服务器,如文档所示。 https://docs.oracle.com/javaee/7/api/javax/websocket/server/ServerEndpoint.html它基本上不执行任何操作,如果有人连接,它将打印出“有人连接”。

 @ServerEndpoint("/myWebsocket");
 public class HelloServer {

     @Onmessage
     public void processGreeting(String message,Session session) {
         System.out.println("Greeting received:" + message);
     }

 }

我正在尝试在当前项目中使用它,该项目已经具有http端点,并且在我运行它时,它使用jersey部署它们。我有一个jerseyContext,具有“ / api” contextPath。我有一个ServletHolder,其中包含所有http端点(@ Path,@ Get等)的包。我的@ServerEndpoint类包括在内

ServletHolder holder = new ServletHolder(ServletContainer.class)
jerseyContext.addServlet(holder,"/*")

但是当我运行程序本身时,我可以调用http方法,但是如果我尝试连接到“ ws:// localhost:8888 / api / myWebsocket”,它将初始化我的类,然后尝试检查路线,但找不到它,但出现404错误。这来自Jersey的RoutingStage.java文件:

    private RoutingResult _apply(final RequestProcessingContext request,final Router router) {

        final Router.Continuation continuation = router.apply(request);

        for (Router child : continuation.next()) {
            RoutingResult result = _apply(continuation.requestContext(),child);

            if (result.endpoint != null) {
                // we're done
                return result;
            } // else continue
        }

        Endpoint endpoint = Routers.extractEndpoint(router);
        if (endpoint != null) {
            // inflector at terminal stage found
            return RoutingResult.from(continuation.requestContext(),endpoint);
        }

        // inflector at terminal stage not found
        return RoutingResult.from(continuation.requestContext());
    }

返回的路由结果为“ null”,因此我得到404。我该如何部署它,以便找到Websocket服务器?

感谢您的帮助。

BBQ20097758258 回答:JAX-RS @ServerEndpoint Websocket用jersey部署

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3046935.html

大家都在问