Forum Discussion

allegro's avatar
allegro
New Contributor
11 years ago

SoapUI 5.0 requestContent is null for Rest Mock service

Hi guys,
I'm trying Rest Mock service. I need to take json or xml body from POST request which I send from Google Postman plugin, for example.

When I trying to get the message body by using mockRequest.requestContent in onRequest script (or in other places as well) I always get null value.

mockRequest.getHttpRequest() works well and returns HTTP header only.

Any thought, is mockRequest.requestContent supported for REST mock services?

Thanks in advance.
I'll be waiting for answers.

6 Replies

  • I have the exact same problem.

    I'm trying to build a dynamic REST mockservice that needs to return a different response based on the JSON body of the POST request.
    When I try to read the mockRequest.requestContent property it always returns null. The mockRequest object itself is not null, just the requestContent.

    I am not running the script via the small green triangle ("Run this script"), I have tried posting a real request via SoapUI/curl/Chrome and I can see the JSON data posted in SoapUI's http log, but in the script the requestContent is still null.

    Is this a bug or something I'm doing wrong?
    Thanks!
  • I faced the same issue
    also made a few observations

    Consider sending 2 requests one right after another to the same mocked endpoint.
    The following code successfully reads http response first time request is sent.
    It is showing request body and says that ..getReader().ready()==true
    For the second request ..getReader().ready()==false and request body is not shown.

    However if I send the second request with 40 seconds delay - both first and second requests appear in log.

    log.info mockRequest.getRequest().getReader().ready()
    try {
    while ((line = mockRequest.getRequest().getReader().readLine()) != null)
    log.info("line:"+line)
    ;
    } catch (Exception e) {
    log.error("exception:"+e)
    }


    In case someone have ideas of how investigate or workaround please post below.
  • lenenberg's avatar
    lenenberg
    Occasional Contributor
    I took nightly build 20140612-1506.
    It works fine for me.
    btw no access to reader anymore.
  • Thanks lenenberg for the hint on using the updated build. That seemed to work for POST requests.
    I then moved on to trying to do the same for a PUT request and found that it is still broken, and now even the "reader" approach is not available so I'm really up a creek. Very very frustrating.
  • QADev's avatar
    QADev
    New Contributor
    Hi,
    I have the same problem using Ready API 1.1.0 - ServiceV for a get request.
    Any solution?
    Thanks,
  • leonhardS's avatar
    leonhardS
    New Contributor
    QADev wrote:
    Hi,
    I have the same problem using Ready API 1.1.0 - ServiceV for a get request.
    Any solution?
    Thanks,



    Hi QADev,

    I also using Ready API 1.1.0 - ServiceV.
    The methode "mockRequest.requestContent" works fine in this version.

    I use it for the XmlHolder:

    def holder = new XmlHolder(mockRequest.requestContent)


    Which method do you use?