I am developing an app that appends all the values of the form to a FormData()
object e.g. "msgBody
" and sends it to the grails server-side where it is consumed by jax-rs
api. I have used something like:
GrailsWebRequest request = WebUtils.retrieveGrailsWebRequest()
def params = request.getParams()
if (!(params.msgBody.length() > 0)) {
log.error("Empty message body")
}
The problem I am having is with the integration testing of that api where I have written:
def headers = ['Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryZ7dAiucrA3eTbjzI', 'Accept': 'application/json']
def content='{"msgBody":"Hello World"}'
sendRequest("/api/v1/message", 'POST', headers, content.bytes)
I keep on getting the "500 Internal Server Error
" and error message:
"Caused by: java.lang.NullPointerException: Cannot invoke method length() on null object".
Why is this happening?