Skip to main content



      Home
Home » Eclipse Projects » Jakarta WebSocket » Problem with @ClientEndpoint
Problem with @ClientEndpoint [message #1851036] Fri, 25 March 2022 06:32 Go to next message
Eclipse UserFriend
Hi. I want to get the instance who called connectToServer in the client endpoint.

I can achieve it by the programmatic way.
public class BilibiliLiveClientEndpoint extends Endpoint {

public BilibiliLiveClientEndpoint(BilibiliLive bilibiliLive) {
    this.bilibiliLive = bilibiliLive;

session = ContainerProvider.getWebSocketContainer().connectToServer(new BilibiliLiveClientEndpoint(this), ClientEndpointConfig.Builder.create().build(), new URI(URL));


But I can't find a way to achieve it by the annotation way.
@ClientEndpoint
public class BilibiliLiveClientEndpointAnnotated {

@OnOpen
public void onOpen(Session session) {
    try {
        BilibiliLive bilibiliLive = BilibiliLiveJakarta.sessionBilibiliLiveJakartaMap.get(session);

session = ContainerProvider.getWebSocketContainer().connectToServer(BilibiliLiveClientEndpointAnnotated.class, new URI(URL));
sessionBilibiliLiveJakartaMap.put(session, this);

It seems that the only way to index the instance who called connectToServer is by session. But the session is not returned if the onOpen method is not completed. so the bilibiliLive instance is null.

Is there a way to achieve it by the annotation way? Thank you.
Re: Problem with @ClientEndpoint [message #1851083 is a reply to message #1851036] Sun, 27 March 2022 11:10 Go to previous message
Eclipse UserFriend
For the programmatic way, I can also use the EndpointConfig.getUserProperties().put() to add custom properties to transfer the instance inside. But there's no way for the annotation way.

[Updated on: Sun, 27 March 2022 11:11] by Moderator

Goto Forum:
  


Current Time: Tue May 20 16:34:23 EDT 2025

Powered by FUDForum. Page generated in 0.07058 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top