Websocket端点返回404 [英] Websocket endpoint returns 404

查看:198
本文介绍了Websocket端点返回404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java EE 7 Websocket原理的新手.

我在Wildfly 10上部署了Java EE 7服务器.

我已经配置了上下文路径和应用程序路径.我可以通过http://localhost:8080/context_path/app_path/something到达服务器.

现在,我已经声明了一个简单的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);
    }
}

另一方面,我有一个外部Angular 2项目,该项目应该连接到websocket,但是我得到错误状态代码:404、200,具体取决于链接.

我得到200:

ws://localhost:8080 

我得到404(无法握手):

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

我该怎么做才能到达网络套接字?显然我的网址不正确,或者我对服务器端点进行编程的方式是完全错误的.

解决方案

我找到了解决方案..很糟糕,WebSocket位于错误的模块(ejb)中. >

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.

解决方案

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

这篇关于Websocket端点返回404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆