cancel
Showing results for 
Search instead for 
Did you mean: 

Pass JSON in PUT Request - SOAPUI Pro for REST service

SOLVED
Occasional 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
4 REPLIES
Community Leader

Re: PUT Request in SOAPUI Pro for REST service

Hi ramprakash4,

You were asking about this thread originally, but I don't understand the original question, so could you edit your post above to ask it again in your own words?

Are you just trying to make a simple REST request using PUT method that has JSON in the body?

Or is there some either meaning when he says "Content/schema"?

Highlighted
Occasional Contributor

Re: PUT Request in SOAPUI Pro for REST service

Thanks mate. Updated description
Community Leader

Re: PUT Request in SOAPUI Pro for REST service

 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.

Occasional Contributor

Re: PUT Request in SOAPUI Pro for REST service

This is brilliant. Worked like a charm. Thanks a lot. You saved me from wasting many hours. 

Watch a Video Interview
Top Kudoed Authors
Are You In?

Meet the Community Leaders!

SmartBear Connect is an excellent opportunity for training, in-person support, and networking.

GET YOUR TICKET WITH $100 OFF