Grails - Receive return from my REST request

0

I have a grails code for a POST-type REST call where I pass the login parameters and it was to receive the token and an access route, it is correct, both by Postman that I receive these parameters correctly, and by the code also after all , does not fall into catch for error handling.

The answer I get from Posman goes something like this:

{
"access_token":"e...2",
"instance_url":"http:\/\/m...\/..c"
}

This is the one excerpt from my grails code:

def http = new HTTPBuilder(sf_login_domain)
    def postBody = [
        grant_type: 'password',
        client_id: consumer_key,
        client_secret: consumer_secret,
        username: auth_username,
        password: auth_password
    ]
    try {
        http.post( path : 'EfetuarLogin', body : postBody, requestContentType: URLENC) {
          resp, json ->
            log.debug "**  access_token: ${json.access_token}, instance_domain: ${json.instance_url}"
            access_token = json.access_token
            instance_domain = json.instance_url + "/"
        }
        retornoLogin = ['access_token':access_token, 'instance_domain':instance_domain]
    }
    catch(Exception e){
        log.error "** Error code: ${e}"
        log.error "** Post form: ${postBody}"
    }

But my debug line log.debug "** access_token: ${json.access_token}, instance_domain: ${json.instance_url}" , returns me the JSon parameter empty.

Can anyone point out to me what I'm doing wrong? If there is another way to do this call in grails, or am I getting the answer incorrectly?

UPDATE

I tried to debug by adding this line

log.debug "**  resp: ${resp}, json: ${json}"

But in my log it came out:

**  resp: groovyx.net.http.HttpResponseDecorator@20562d99, json: Object movedObject moved to here.

Does Agluem have any suggestions on how I can see the response of the variable resp and json ?

    
asked by anonymous 27.04.2018 / 15:53

0 answers