Reputation: 6105
I followed this post on how to specify a timeout, doing:
def http = new HTTPBuilder(restEndpointUrl);
http.getParams().setParameter("http.socket.timeout", new Integer(2000))
and I got the error:
Class: groovy.lang.MissingMethodException
Message:No signature of method: groovyx.net.http.HTTPBuilder.getParams() is applicable for argument types: () values: [] Possible solutions: getParser(), getClass(), getHeaders(), getUri()
I'm probably setting it on the wrong class but if you directly know what I'm doing wrong your comments are much appreciated. I'm fairly new to Groovy/Grails.
Thanks
Upvotes: 1
Views: 3041
Reputation: 1641
Try this, I'm using http-builder 0.7.1 plugin with Grails 2.3.9:
import groovyx.net.http.HTTPBuilder
import org.apache.http.client.config.RequestConfig
import org.apache.http.config.SocketConfig
import org.apache.http.conn.ConnectTimeoutException
import org.apache.http.impl.client.HttpClients
def timeout = 10000
SocketConfig sc = SocketConfig.custom().setSoTimeout(timeout).build()
RequestConfig rc = RequestConfig.custom().setConnectTimeout(timeout).setSocketTimeout(timeout).build()
def hc = HttpClients.custom().setDefaultSocketConfig(sc).setDefaultRequestConfig(rc).build()
def http = new HTTPBuilder(restEndpointUrl)
http.client = hc
Upvotes: 0
Reputation: 11643
You set the timer on the underlying client ...
http.getClient().getParams().setParameter("http.socket.timeout", new Integer(2000))
Upvotes: 1