MissingMethodException在基于教程的代码中,昨天工作



我对GroovyHttpBuilder库有奇怪的问题。首先要注意的是,我对Groovy很新鲜。

我的代码基于教程。它只是从HTTP服务器加载文件列表。代码昨天工作,今天(工作区构建后)没有。

问题是:

Caught: groovy.lang.MissingMethodException: No signature of method: groovyx.net.http.HTTPBuilder.request() is applicable for argument types: (groovyx.net.http.Method, groovyx.net.http.ContentType, pl.linfo.groovy.samples.HttpTest$_main_closure1)
Possible solutions: request(groovyx.net.http.Method, groovy.lang.Closure)

代码为:

def http = new HTTPBuilder( 'http://nbp.pl/Kursy/xml/dir.txt' )
    http.request( GET, TEXT ) { 
        response.success = { resp, reader ->
            println "${resp.statusLine}"
            files = reader.text.split ('rn')
        }
        response.'404' = {
            println "Not found!"
            return
        }
    };

运行环境是 Eclipse 3.6

我想问题是时髦的编译

问题,重新编译后的时髦代码片段不再匹配闭包。但是,作为Groovy的新手,我很难找出发生了什么,所以请帮助。

这一定是Eclipse Groovy插件的问题。使用时髦的解释器运行时,您发布的代码对我来说效果很好。

$ cat hbuildertest.groovy 
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.1' )
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
def http = new HTTPBuilder( 'http://nbp.pl/Kursy/xml/dir.txt' )
    http.request( GET, TEXT ) { 
        response.success = { resp, reader ->
            println "${resp.statusLine}"
            files = reader.text.split ('rn')
        }
        response.'404' = {
            println "Not found!"
            return
        }
    };

$ groovy hbuildertest.groovy 
May 19, 2011 12:59:08 AM groovyx.net.http.ParserRegistry getCharset
WARNING: Could not find charset in response
HTTP/1.1 200 OK
$ 

还有带签名的方法:

public Object request( Method m, Object contentType, Closure configClosure ) 
            throws ClientProtocolException, IOException 

至少从 0.3.0 版本的库开始存在于groovyx.net.http.HTTPBuilder类中。

相关内容

最新更新