Created
June 4, 2015 04:15
-
-
Save carwinz/0f8acf76aa1f3c5dfd14 to your computer and use it in GitHub Desktop.
Http lookups with timeouts
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
| 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