0

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.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
cayz
  • 1
  • 2
  • Well, 404 is not found, not no handshake possible. Can you connect to the server with a different websocket client? – Evan Knowles Aug 17 '17 at 08:53
  • Unfortunately not, the requests from different websocket clients don't reach the server. – cayz Aug 17 '17 at 09:06
  • please refer to below URL for running example https://examples.javacodegeeks.com/core-java/real-time-applications-angularjs-java-part-3/ https://coderwall.com/p/uhqeqg/html5-websocket-with-angularjs – jeetendra Mandal Aug 17 '17 at 10:00

2 Answers2

0

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

Evan Knowles
  • 7,426
  • 2
  • 37
  • 71
0

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

cayz
  • 1
  • 2