Accepting/Rejecting a WebSocket asynchronously

43 views
Skip to first unread message

Isaac Pereira

unread,
Nov 19, 2017, 2:58:59 PM11/19/17
to Play Framework
In my application, in play 2.6.x (java), I have a websocket endpoint, but I need to do some async db operation before accept/reject it. Like this:

public CompletionStage<WebSocket> subscribe(String username) {

 
return userRepo.getUserByUsername(username).thenApplyAsync(
    userOpt
-> {
     
...
             return WebSocket.Json.accept(
                 request -> ActorFlow.actorRef(...)
             
);
      ...
   
},
   
...
 
)


But I get this when starting the application:

play.sbt.PlayExceptions$CompilationException: Compilation error[Cannot use a method returning java.util.concurrent.CompletionStage[play.mvc.WebSocket] as a Handler for requests]

Am I getting it wrong? https://www.playframework.com/documentation/2.6.x/JavaWebSockets#accepting-a-websocket-asynchronously

How could I achieve that?

Best Regards

vahid islami

unread,
Jan 24, 2018, 10:28:23 AM1/24/18
to Play Framework
I have same problem! did you resolve that?
Reply all
Reply to author
Forward
0 new messages