我在独立应用程序中的Grizzly上运行了一个Web服务。
Grizzly HTTP服务器按如下方式实例化:
this.httpServer = GrizzlyHttpServerFactory.createHttpServer(uri);
WebappContext applicationContext = new WebappContext("test", "/test");
ServletRegistration registration = applicationContext.addServlet("jersey", ServletContainer.class);
registration.addMapping("/*");
registration.setInitParameter(ServletProperties.JAXRS_APPLICATION_CLASS, MyApplicationService.class.getName());
applicationContext.deploy(httpServer);
WebSocketAddOn webSocketAddon = new WebSocketAddOn();
httpServer.getListeners().forEach(listener -> {
listener.registerAddOn(webSocketAddon);
});
WebSocketEngine.getEngine().register("/ws", "/notifications", myNotificationService);问题:我的通知服务不接受任何web套接字连接。
但如果我改变了:
// factory from org.glassfish.jersey.grizzly2.httpserver
this.httpServer = GrizzlyHttpServerFactory.createHttpServer(uri);出自:
// factory from org.glassfish.grizzly.http.server
this.httpServer = HttpServer.createSimpleServer(null, 8084);那么我的服务确实接受web套接字连接。
我不明白为什么。两者之间的区别是什么?
发布于 2017-09-10 03:49:57
必须是简单的。
替换
this.httpServer = GrizzlyHttpServerFactory.createHttpServer(uri);通过
this.httpServer = GrizzlyHttpServerFactory.createHttpServer(uri, false);解决了问题。
HTTP服务器在获得配置Web套接字附加组件的机会之前是自动启动的。
https://stackoverflow.com/questions/46130825
复制相似问题