0

I am trying to use groovy's HTTPBuilder. I'm getting:

groovy.lang.MissingMethodException: No signature of method: groovyx.net.http.HTTPBuilder.get() is applicable for argument types: (groovyx.net.http.Method, groovyx.net.http.ContentType, com.company.sample.mypackage.myClient$_foo_closure1) values: [GET, application/json, com.company.sample.mypackage.myClient$_foo_closure1@7ee6e5bc] Possible solutions: grep(), get(java.util.Map), get(java.util.Map, groovy.lang.Closure), wait(), getUri(), any()

I think I'm using something almost exactly like the example on HTTPBuilder's documentation. I'm wondering if my problem is environmental with how I have my project set up in Intellij? It's the first time I've set up a maven project in intellij on my own so I'm suspicious.

package com.company.sample.mypackage
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.JSON


public class myClient {

    public static void main(String[] args) {
        foo();
    }

    public static void foo() {

        def http = new HTTPBuilder( 'http://foo.com' )
        http.get(GET, JSON) { <---EXCEPTION HAPPENS HERE
            uri.path = '/api/myapi'

            response.success = { resp, json ->
                println 'Successful'
            }
            response.failure = { resp ->
                println 'failure'
            }
        }

    }
}

Also note: I'm using java 1.7, groovy 2.4.3 and http-builder 0.6...in case that's part of the problem.

Opal
  • 81,889
  • 28
  • 189
  • 210
Damon
  • 305
  • 1
  • 5
  • 13

1 Answers1

1

You should invoke request not get

public static void foo() {

    def http = new HTTPBuilder( 'http://foo.com' )
    http.request(GET, JSON) { 
        uri.path = '/api/myapi'

        response.success = { resp, json ->
            println 'Successful'
        }
        response.failure = { resp ->
            println 'failure'
        }
    }
}
Opal
  • 81,889
  • 28
  • 189
  • 210
  • Yes it does. Apologies for the delayed response. I'm almost certain I answered my own question shortly after posting but I don't see my response here fo some reason. I'm not sure what happened. – Damon Jun 24 '15 at 19:32