Mock Service: mockRequest.requestContent is NULL (HTTP PUT)

Originally posted by andsoulnd on July 17, 2014

I am trying to get the content of HTTP PUT request (take text from request body) to compose dynamic response in REST Mock Service.
mockRequest.requestContent is always NULL if PUT method is used although request is sent with some text in request body and Content-Length is set with appropriate value in HTTP headers.
If HTTP action is changed to POST then mockRequest.requestContent is populated correctly.

Is it a bug or do I miss something?

Originally posted by MarcusJ on July 29, 2014

Hello,

Unfortunately, this is a bug. There is an internal defect of SOAP-2344 for this issue. This applies for the PUT and DELETE methods for a REST mock service.

Originally posted by andsoulnd on August 04, 2014

mrJames, Is there any estimate date when it will be fixed or the link to the bug in tracking system to check its status updates?

Originally posted by jpalmier on July 16, 2015

I have the same issue with SoapUI 5.1.2 and 5.2.0.

I need to read the content of a PUT message.

Is a workaround exist for this issue ?

Originally posted by apm on March 03, 2016

I have the same issue with SoapUI 5.2.1 when I try to read the content of a PUT message.

Has this bug been fixed in any SOAP UI release ? Or is there a workaround for this issue ?

Originally posted by viswam_i on October 10, 2016

Anyone got the solution for this? Even I am seeing the same issue

Originally posted by viswam_i on October 10, 2016

Can anyone please suggest in which version this issue is resolved?

Originally posted by kjdivya on August 24, 2017

Hi

i found one workaround for the problem. We are getting null output for mockRequest.getRequestContent() for PUT request

The workaround would be to use the following code

InputStream is = mockRequest.request.inputStream
BufferedReader br = new BufferedReader(new InputStreamReader(is, “UTF-8”));
StringBuilder sb = new StringBuilder()
while((s=br.readLine())!=null) {
sb.append(s)
}
String payLoad = sb.toString()
log.info payLoad

Originally posted by jasonhjia on June 28, 2018

The workaround works smoothly. However, if you need re-get the content down the road, you can’t since the stream cannot be consumed twice. Hope there’s a real solution from smartbear.

Originally posted by vikititor on November 11, 2019

NOT WORKS. I am using the ReadyAPI v 2.8.

I am unable to read request body.. So unable to return valid response to my Application under test = I am unable to test it = unable to use this tool for testing.

This topic is here sooo loooong.. And no solution? I am surprised. So nobody from SmartBear was working on it? It means, that we are paing for licenses, but no effect?

Please can somebody tell me, how to read POST body request ? because I must return some string value from it back to AUT..

Originally posted by NBorovykh on November 13, 2019

HI vikititor,

In the Dispatch script, a request content can be retrieved as follows:

mockRequest.getRequestContent()

In the latest ReadyAPI version it works for POST, PUT and the other supported HTTP methods.

Please check the screenshot:

Please double-check your configuration and if it still does not work for you as expected, submit a new support case: https://support.smartbear.com/message/?prod=ReadyAPI

Originally posted by vikititor on November 14, 2019

OK, OK.. on this place dispacher script this works…

But before I will send the response, I need create it.. How to transform readed value from this script to the response script?

Because I just tryed on response script, where this was really not working.

This is my needs.

* read request send to MOCK server, parse some values

* prepare response to AUT using this values

* solution must be thread save, because my AUT sends a lot of requests per seccond. I can not use properties..

Originally posted by AlexKaras on November 14, 2019

Hi,

Have you seen my reply here: https://community.smartbear.com/t5/Service-Virtualization-Virtual/how-MOCK-read-request-data-from-attachement/m-p/193441/highlight/true#M692 ?
Does it help?