0

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?

Dave Sag
  • 13,266
  • 14
  • 86
  • 134
rkshakya99
  • 439
  • 1
  • 5
  • 8

1 Answers1

0

I have found out that you don't need to set the Content-Type in the headers and you also have to set all the fields of the FormData() object even if they are null. I did so but still I am getting the same NullPointerException message.

rkshakya99
  • 439
  • 1
  • 5
  • 8