0

I am following the jBoss documentation to include a websocket in a service built with jBoss 7.

I have created and interface and its implementation with the required annotations:

@ServerEndpoint("/websocket/helloworld")
public interface MyService {

    @OnMessage
    String sayHello(String name);

    @OnOpen
    void helloOnOpen(Session session);

    @OnClose
    void helloOnClose(CloseReason reason);

}

and also I have added the required dependency in the parent pom and the weblayer where the controller is.

<dependency>
   <groupId>org.jboss.spec.javax.websocket</groupId>
   <artifactId>jboss-websocket-api_1.0_spec</artifactId>
   <version>1.0.0.Final</version>
   <scope>provided</scope>
</dependency>

The websocket is not handled correclty, and I am not able to be connected to it. Reviewing the server access log I can see that I am reaching the server

{"ident": "-","auth": "-","logdate": "[30/Aug/2023:18:20:36 +0200]","client": {"ip": "172.18.0.1","user_agent": "-"},"verb": "GET","http": {"protocol": "HTTP/1.1","request": {"path": "/genesys-chat/websocket/helloworld","clientVersion": "-","query-string": "-"},"response": {"status": "404","bytes": "68","time": "5"}}, "type":"standard", "logname":"jbossweb_access.log"}

As you can see the request is handled a normal HTTP GET request. Debugging I can see that the handled used by undertow is the HTTP one.

enter image description here

The request done is with postman pointing to ws://localhost:8080/genesys-chat/websocket/helloworld

Do I miss something?

4
  • I am also evaluating if I missed to add the handler for websocket inside the standalone.xml with CLI with no success Commented Aug 31, 2023 at 15:44
  • 1
    How are you making the websocket call? Also that dependency should be marked with <scope>provided</scope> as the server already provides the API. Commented Aug 31, 2023 at 18:36
  • Hi @JamesR.Perkins, yes, the scope provided was set into the dependency management. I have updated the question. I am sending the ws connection with Postman, will all required headers (set automatically by postman) Commented Sep 1, 2023 at 7:29
  • I don't use Postman, but can it do websocket calls? I don't have postman to try. However, WildFly works with websockets. Have a look at github.com/wildfly/quickstart/tree/main/websocket-hello. Commented Sep 1, 2023 at 16:26

1 Answer 1

0

For starters you need to write an implementation not an interface, please look at the list of published quick starts

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks!!! Changing the annotations to the implementation, the websocket is connected, is there any way that I can set in wildfly how to map the interface to the implementation? I would like to have the contract in another repository. How can I do it ?
I have created a new question for this stackoverflow.com/questions/77051459/…
Not sure why you would be interested in having the contract separate, it doesn't define the payload at all, just the method name in the implementation for certain events. Why on earth they made it this way rather than just making it a traditional interface I have no idea!
Well, you miss the definition of the path or any other param that could be added in the request if needed. The objetive os due that the client must not now the details of the implementation, only the contract exposed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.