1

私はタイムアウトを指定する方法についてこの投稿に従いました。

def http = new HTTPBuilder(restEndpointUrl);
http.getParams().setParameter("http.socket.timeout", new Integer(2000))

エラーが発生しました:

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()

おそらく間違ったクラスに設定していますが、私が間違っていることを直接知っている場合は、コメントをいただければ幸いです。私はGroovy/Grailsにかなり慣れていません。

ありがとう

4

2 に答える 2

1

基礎となるクライアントでタイマーを設定します...

http.getClient().getParams().setParameter("http.socket.timeout", new Integer(2000))
于 2013-07-18T18:03:36.673 に答える
0

これを試してください。Grails 2.3.9 で http-builder 0.7.1 プラグインを使用しています。

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
于 2016-03-12T23:17:32.377 に答える