Question

I have strange problem with Groovy and HttpBuilder library. First to note, I'm fresh to Groovy.

I've based my code on tutorial. It simply loads the list of files from HTTP server. The code was working yesterday, today (after workspace build) not.

The problem is:

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)

The code is:

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
        }
    };

The running environment is Eclipse 3.6

I suppose the problem is groovy compilation issue, the groovy code fragment after recompile no longer matching Closure. However, as new to Groovy I have problem to find out what's going on so please help.

Was it helpful?

Solution

This has to be some problem with the Eclipse Groovy plugin. The code you posted works well for me when run using the groovy interpreter.

$ 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
$ 

Also the method with signature:

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

exists in groovyx.net.http.HTTPBuilder class since at least 0.3.0 version of the library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top