Grizzly / Glassfish - Cant establish websockets handshake

安稳与你 提交于 2019-12-14 02:09:18

问题


I'm trying to get WebSockets working on top of Grizzly / Glassfish. I've cloned the sample WebSockets chat application, built it and deployed it to Glassfish 3.1.2. However, I cannot get WebSockets to connect. The WebSockets handshake is failing because I'm getting a 405 (Method Not Allowed) response. This makes sense because of what is in the Servlet:

public class WebSocketsServlet extends HttpServlet {

    private final ChatApplication app = new ChatApplication();

    @Override
    public void init(ServletConfig config) throws ServletException {
        WebSocketEngine.getEngine().register(app);
    }

    @Override
    public void destroy() {
        WebSocketEngine.getEngine().unregister(app);
    }
}

There is no doGet method specified, so I'm wondering if there is more configuration required somewhere, or if you need to implement the handshake logic in the servlet doGet method yourself?


回答1:


I was trying to use grizzly-websockets-chat-2.1.9.war on glassfish 3.1.2 and getting same error.

Followed the advice from this page http://www.java.net/forum/topic/glassfish/glassfish/websocket-connection-not-establishing-glasshfish-server-how-fix-it-0

which states to use the version found here (I would think the version would indicate it being older however the time stamps on the files are Jan 30 2012):

WAR

https://maven.java.net/service/local/artifact/maven/redirect?r=releases&g=com.sun.grizzly.samples&a=grizzly-websockets-chat&v=1.9.46&e=war

SOURCES

https://maven.java.net/service/local/artifact/maven/redirect?r=releases&g=com.sun.grizzly.samples&a=grizzly-websockets-chat&v=1.9.46&e=jar&c=sources

By using that war everything works.

For those that like using the glassfish web console. You can enable web-sockets by:

Configurations > server-config > Network Config > Protocols > http-listener-1, then HTTP tab > Scroll to bottom and check off Websockets Support.

Note Configurations > default-config > ... also has the same options

You might find this more continent that keeping a terminal around.




回答2:


It appears you haven't enabled websocket support (disabled by default).

Issue the following command and then restart the server:

asadmin set configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.websockets-support-enabled=true

You can replace http-listener-1 with whatever http-listener you wish to enable WS support for.



来源:https://stackoverflow.com/questions/9964716/grizzly-glassfish-cant-establish-websockets-handshake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!