akiong akiong - 1 year ago 210
Groovy Question

how to call withHttp() with http builder helper plugin grails 3?

i am trying to upgrade my project from grails 2.1.1 to grails 3.0.9

in grails 3.0.9 : i install this plugin like this..

compile 'org.grails.plugins:http-builder-helper:1.0.2'

and i run it...

i get this error..

ERROR com.akiong.SmsService - No signature of method:
com.akiong.SmsService.withHttp() is applicable for argument types:
(java.util.LinkedHashMap, com.akiong.SmsService$_sendSms_clos ure2) values:
[[uri:https://abc.web.id], com.akiong.SmsService$_sendSms_closure2@48d98154]
groovy.lang.MissingMethodException: No signature of method:
com.akiong.SmsService.withHttp() is applicable for argument types:
(java.util.LinkedHashMap, com.akiong.SmsService$_sendSm s_closure2) values:
[[uri:https://abc.web.id], com.akiong.SmsService$_sendSms_closure2@48d98154]

this is my code com.akiong.SmsService.groovy

withHttp(uri: uri) {
client.getParams().setBooleanParameter("http.protocol.expect-continue", false)
get(path: '/abc.php', query: [u: smsMaskingUser, p: smsMaskingPassword, d: destinationNo, m: messages]){ resp, reader ->
loggResponse(resp, reader, refNo)

what must i do?

i tried both of this :

compile 'org.grails.plugins:http-builder-helper:1.0.0'


compile 'org.grails.plugins:grails-http-builder-helper:1.0.0'

both of this can be download...but i get the same error

Answer Source

i change my code from grails 2 -> 3 and not use http-builder-helper plugin on grails 3, but my app with grails 2 using http-builder-helper plugin.like this.

import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.TEXT

and this

http.request(GET,TEXT) { req ->
                uri.path = '/api.php' // overrides any path in the default URL
                uri.query = [ u: yourusername, p: yourpassword, d: something, m: messages ]
//              headers.'User-Agent' = 'Mozilla/5.0'

                response.success = { resp, reader ->
                    assert resp.status == 200
                    loggResponse(resp, reader, refNo)

                // called only for a 404 (not found) status code:
                response.'404' = { resp ->
                    println 'Not found'

hope this will help you

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download