Websocket endpoint returns 404

ⅰ亾dé卋堺 提交于 2021-02-05 09:37:19

问题


I am new to the Java EE 7 websocket principle.

I have a Java EE 7 server deployed on Wildfly 10.

I have configured a context path and an application path. I am able to reach the server by http://localhost:8080/context_path/app_path/something.

Now, I have declared a simple ServerEndpoint:

@Stateful
@ServerEndpoint("websockets/stream")
public class StreamServerEndpoint {

    private static final Logger LOG = Logger.getLogger(StreamServerEndpoint.class);

    @Inject
    ByteBufferStore byteBufferStore;

    @Inject
    private EventListener listener;

    @OnOpen
    public void open(Session session) {
        LOG.info("Session opened and registered");
        listener.register(session);
    }

    @OnMessage
    public void message(Session session, ByteBuffer buffer) {
        LOG.info("Message retrieved");
        session.getUserProperties().put("buffer", buffer);
        //byteBufferStore.retrieve().ifPresent(byteBuffer -> Common.sendBuffer(session, buffer));
    }

    @OnClose
    public void close(Session session) {
        listener.unregister(session);
    }
}

On the other side, I have an external Angular 2 project which should connect to the websocket, but I get error status codes: 404, 200, depending on the link.

I get 200 with this:

ws://localhost:8080 

I get 404 (no handshake possible) with this:

ws://localhost:8080/context_path/app_path/websockets/stream  

What can I do to reach the websocket? Apparently my URL isn't correct, or the way I programmed the server endpoint is totally wrong.


回答1:


It sounds like the websockets aren't on at all - depending on your version of WildFly, they may need to be enabled. Try adding

<enable-websockets>true</enable-websockets>

under the jboss-web node of your jboss-web.xml




回答2:


I found the solution.. My bad, the WebSocket was in the wrong module (ejb).. Moving the class to the web module solved it.



来源:https://stackoverflow.com/questions/45730527/websocket-endpoint-returns-404

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