Last active
June 28, 2022 19:08
-
-
Save axeda/5189102 to your computer and use it in GitHub Desktop.
Connection Timeouts with HttpBuilder
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 groovyx.net.http.HTTPBuilder | |
import static groovyx.net.http.ContentType.* | |
import static groovyx.net.http.Method.* | |
int TENSECONDS = 10*1000; | |
int THIRTYSECONDS = 30*1000; | |
HTTPBuilder builder = new HTTPBuilder('http://www.axeda.com') | |
//HTTPBuilder has no direct methods to add timeouts. We have to add them to the HttpParams of the underlying HttpClient | |
builder.getClient().getParams().setParameter("http.connection.timeout", new Integer(TENSECONDS)) | |
builder.getClient().getParams().setParameter("http.socket.timeout", new Integer(THIRTYSECONDS)) | |
try | |
{ | |
//Simply get the contents of http://www.axeda.com and log it to the Custom Object Log | |
builder.request(GET, TEXT){ | |
response.success = { resp, res -> | |
res.readLines().each { | |
logger.info it | |
} | |
} | |
} | |
} | |
finally | |
{ | |
//Make sure to always shut down the HTTPBuilder when you’re done with it | |
builder.shutdown() | |
} | |
return true |
Nice, Thanks.
HttpParams getParams();
- @deprecated (4.3) use
- {@link org.apache.http.client.config.RequestConfig}.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great, thanks!.