Ok, I found a solution, albeit a bit detailed. What you can do is move everything to the actor.
Set up your Actor in your global object, but save the ActorRef somewhere that you can access.
ActorRef myActor = Akka.system().actorOf(new Props(MyActor.class));
In your Actor, make a WS call.
public void onReceive(Object message) { WSRequestHolder request = WS.url("http://example.com"); Response response = request.get().get(); SomeResult result = doFurtherProcessing(response); getContext().sender().tell(result);
And in your controller, just wrap the call to your actor in async ()
public static Result method() { String message = "hello"; return async( Akka.asPromise(ask(myActor, message, 1000)).map(new Function<Object, Result>() { public Result apply(Object result) throws Throwable { return ok(result); } }) ); }
Link: http://www.playframework.org/documentation/2.0.3/JavaAkka
source share