Sartakov Dmytro
Sartakov Dmytro

Reputation: 93

Grails HTTBuilder request Error

I make a request from Android to Grails controller. Request change the data in the database, but the Grails server returns an error:

2015-11-28 19:23:31,973 [http-bio-8080-exec-5] ERROR errors.GrailsExceptionResolver  - MissingPropertyException occurred when processing request: [POST] /ServerReg/saveReg/regSave
No such property: success for class: org.apache.catalina.connector.ResponseFacade. Stacktrace follows:
Message: No such property: success for class: org.apache.catalina.connector.ResponseFacade

my Grails controller:

def saveRegLink = new HTTPBuilder("http://db.likepay.me:80/rest/checkReg/registration/?fields=id");
saveRegLink.request(POST, JSON) { req ->
    headers.'X-DreamFactory-Session-Token' = session_id
    headers.'X-DreamFactory-Application-Name' = serviceName
    body = [
        telNum: telNum,
        IMEI: IMEI,
        DeviceName: DeviceName,
        SIM_SN: SIM_SN
    ]
}
response.success = {resp, json ->
    println resp.status
    render json
    return json
}
response.failure = { resp ->
    println 'request failed'
    assert resp.status >= 400
}

I shall be grateful for the help.

Upvotes: 0

Views: 367

Answers (1)

tylerwal
tylerwal

Reputation: 1870

You have the response.success/response.failure scoped outside of the closure that is passed to the request method.

It should be something like this:

def saveRegLink = new HTTPBuilder("http://db.likepay.me:80/rest/checkReg/registration/?fields=id");
saveRegLink.request(POST, JSON) { req ->
    headers.'X-DreamFactory-Session-Token' = session_id
    headers.'X-DreamFactory-Application-Name' = serviceName
    body = [
        telNum: telNum,
        IMEI: IMEI,
        DeviceName: DeviceName,
        SIM_SN: SIM_SN
    ]

    response.success = {resp, json ->
        println resp.status
        render json
        return json
    }
    response.failure = { resp ->
        println 'request failed'
        assert resp.status >= 400
    }   
}

Upvotes: 1

Related Questions