Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

groovy.lang.MissingMethodException when calling withHttp() from a service #21

Open
ghost opened this issue Sep 11, 2015 · 1 comment
Open

Comments

@ghost
Copy link

ghost commented Sep 11, 2015

Service class:

class GeoCoderService {
    def getLatLong(String address) {
        def result = null
        withHttp(uri: "http://maps.googleapis.com") {
            def html = get(path : '/maps/api/geocode/json', query : [address:address])
            if ( html.results != null && html.results.size() > 0 ) {
                def partial = html.results[0]
                if ( partial.geometry != null && partial.geometry.location != null) {
                    def lat = partial.geometry.location.lat
                    def lng = partial.geometry.location.lng
                    result = [lat:Double.valueOf(lat.toString()), lng:Double.valueOf(lng.toString())]
                }
            }
        }
        return result
    }
}

Controller class:

class GeneralController {

    def geoCoderService

    def index = {
        render (view: "index")
    }

    def test = {
        def point = geoCoderService.getLatLong('1600 Amphitheatre Pkwy, Mountain View, CA 94043')
        render "latitude = ${point.lat}"
        render "longitude = ${point.lng}"
    }
}

Exception:

Caused by: groovy.lang.MissingMethodException: No signature of method: package.GeoCoderService.withHttp() is applicable for argument types: (java.util.LinkedHashMap, package.GeoCoderService$_getLatLong_closure1) values: [[uri:http://maps.googleapis.com], package.GeoCoderService$_getLatLong_closure1@5ad666a2]
        at package.GeoCoderService.getLatLong(GeoCoderService.groovy:6) ~[main/:na]
        at package.GeneralController$_closure2.doCall(GeneralController.groovy:12) ~[main/:na]
        ... 3 common frames omitted
@ghost ghost changed the title groovy.lang.MissingMethodException when calling withHttp from a service groovy.lang.MissingMethodException when calling withHttp() from a service Sep 11, 2015
@sudhanshusirohia
Copy link

Add above lines at top
import groovyx.net.http.HTTPBuilder

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant