When is a closure not a Closure (using HTTPBuilder)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

When is a closure not a Closure (using HTTPBuilder)

John Bito
I'm quite surprised by the ClassCastException I'm getting when HTTPBuilder tries to run the failure handler I've specified. The closure runs when I execute the code using the groovy command.  When I asked about this on the groovy-user list, the suggestion was a classpath issue. I'm not sure how to investigate/correct that in my Eclipse configuration

The exception is Caught: java.lang.ClassCastException: RequestHandler$_post_closure1 cannot be cast to groovy.lang.Closure

The code is
class RequestHandler {
    def urlFactory
    def result
   
    def post() {
        def http = new HTTPBuilder(urlFactory.toURL())
        http.handler.failure = { resp ->
            println "Unexpected failure: ${resp.statusLine}"
        }
        result = http.post(body: urlFactory.params)
    }
}