Created
February 27, 2013 14:59
-
-
Save schleichardt/5048509 to your computer and use it in GitHub Desktop.
answer for stackoverflow http://stackoverflow.com/questions/15093511/play-2-0-4-any-chance-to-set-followredirects-to-false-in-ws-response-in-java-co/15115233#15115233
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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