Created
January 5, 2015 10:09
-
-
Save leewin12/8b6518a17d301e7ae5d1 to your computer and use it in GitHub Desktop.
Groovy AsyncHttpClient
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
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1') | |
import groovyx.net.http.AsyncHTTPBuilder | |
import groovyx.net.http.URIBuilder | |
import static groovyx.net.http.Method.POST | |
import static groovyx.net.http.ContentType.TEXT | |
import groovy.json.JsonSlurper | |
def http = new AsyncHTTPBuilder( poolSize:100 ) | |
def slurper = new JsonSlurper() | |
def reader = new File(args[0]) | |
reader.eachLine { line, lineNumber -> | |
def uri = new URIBuilder(line); | |
def response = http.post(uri:uri) { req,TEXT -> | |
} | |
http.handler.success = { resp, text -> | |
println "num:${lineNumber} DONE:${uri.path}:${resp.statusLine.statusCode}:${text}" | |
} | |
http.handler.failure = { resp,text -> | |
println "num:${lineNumber} ERROR:${resp.statusLine.statusCode}:${text}" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// No handler style