Forum Discussion

ramprakash4's avatar
ramprakash4
Occasional Contributor
7 years ago

Pass JSON in PUT Request - SOAPUI Pro for REST service

I am creating mock stubs using SoapUI to test our application code. One scenario is for the mock stubs to accept PUT request and read the JSON request coming through. I don't know how to pass JSON th...
  • JHunt's avatar
    JHunt
    7 years ago

     Oh, okay, I see what this is about... I didn't get that at all from the other question!

     

    This is a known bug actually. SoapUI doesn't seem to be able to get the body on PUT/DELETE messages. The same bug also makes it so that you can't see the body in the "raw" view of the sent request.

     

    You can fix for your MockServices by adding some code to the OnRequest script. I took inspiration from here.

     

    mockRequest.with { if (method.toString() == 'PUT' || method.toString() == 'DELETE') {
        BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8"));
        StringBuilder sb = new StringBuilder()
        while((s=br.readLine())!=null) { sb.append(s) }
        requestContent = sb.toString()
    }}

    Example project is attached.