Skip to content

Instantly share code, notes, and snippets.

@carwinz
Created June 4, 2015 04:15
Show Gist options
  • Save carwinz/0f8acf76aa1f3c5dfd14 to your computer and use it in GitHub Desktop.
Save carwinz/0f8acf76aa1f3c5dfd14 to your computer and use it in GitHub Desktop.
Http lookups with timeouts
import groovy.json.JsonSlurper
class HttpUtils {
static def getJsonFrom(url) {
new JsonSlurper().parseText(getTextFrom(url))
}
static def getTextFrom(url, timeout = 30000) {
URLConnection con = new URL(url).openConnection();
con.setConnectTimeout(timeout);
con.setReadTimeout(timeout);
con.getInputStream().text
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment