Last active
December 18, 2015 18:29
-
-
Save Raymond26/5825878 to your computer and use it in GitHub Desktop.
Play Framework Java example of an asynchronous GET request to a web service.
This file contains 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 java.util.Calendar; | |
import java.util.TimeZone; | |
import org.apache.commons.codec.digest.DigestUtils; | |
import play.libs.F.Function; | |
import play.*; | |
import play.libs.WS; | |
import play.mvc.*; | |
public class Special extends Controller { | |
public static Result IP_Quova() { | |
String ip = request().getQueryString("ip"); | |
String apikey = "neustar apiKey"; | |
String secret = "neustar secret"; | |
long gmdateSeconds = (Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis()) / 1000; | |
String sig = DigestUtils.md5Hex(apikey + secret + gmdateSeconds); | |
return async( | |
WS.url("http://api.quova.com/v1/ipinfo/" + ip) | |
.setQueryParameter("apikey", apikey) | |
.setQueryParameter("sig", sig) | |
.get() | |
.map( | |
new Function<WS.Response, Result>() { | |
public Result apply(WS.Response response) { | |
return ok(response.getBody()).as("text/xml"); | |
} | |
} | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment