ramprakash4
7 years agoOccasional Contributor
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 through a PUT request in SOAP UI.
Ram
Ram
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.