2011-05-17 116 views
2

我有奇怪的问题与GroovyHttpBuilder库。首先要注意的是,我对Groovy很新鲜。MissingMethodException在基于教程的代码和昨天工作

我已经在教程中使用了我的代码。它只是从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 ('\r\n') 
     } 
     response.'404' = { 
      println "Not found!" 
      return 
     } 
    }; 

运行环境是的Eclipse 3.6

我想这个问题是常规编制问题,Groovy代码重新编译后的片段不再匹配关闭。然而,作为Groovy的新手,我有问题想知道发生了什么,所以请帮忙。

回答

1

这对Eclipse Groovy插件来说有些问题。使用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 ('\r\n') 
     } 
     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 

存在于groovyx.net.http.HTTPBuilder类,因为至少0.3.0版本的库。

+0

正如我写的,代码为我运行,并在Eclipse中。但是,记事本驱动的开发肯定不适合我,我希望它在IDE中工作:( – 2011-05-19 10:34:29