Skip to content

Instantly share code, notes, and snippets.

@schleichardt
Created February 27, 2013 14:59
Show Gist options
  • Save schleichardt/5048509 to your computer and use it in GitHub Desktop.
Save schleichardt/5048509 to your computer and use it in GitHub Desktop.
package controllers;
import play.api.libs.ws.Response;
import play.api.libs.ws.WS$;
import play.libs.F;
import play.libs.WS;
import play.mvc.*;
public class Application extends Controller {
public static Result index() {
final String url = "http://localhost:80";
final F.Promise<WS.Response> responsePromise = wsHead(url);
return async(responsePromise.map(new F.Function<WS.Response, Result>() {
@Override
public Result apply(WS.Response response) throws Throwable {
return ok("got status: " + response.getStatus());
}
}));
}
private static F.Promise<WS.Response> wsHead(String url) {
return new F.Promise(WS$.MODULE$.url(url).head()).map(new F.Function<Response, WS.Response>() {
@Override
public WS.Response apply(Response o) throws Throwable {
return new WS.Response(o.getAHCResponse());
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment