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 through a PUT request in SOAP UI.

Ram
  • 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.

  • JHunt's avatar
    JHunt
    Community Hero

    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"?

      • JHunt's avatar
        JHunt
        Community Hero

         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.