cancel
Showing results for 
Search instead for 
Did you mean: 

[SoapUI 5.2.1] mockRequest is NULL in REST MockService

SOLVED
New Contributor

Re: [SoapUI 5.2.1] mockRequest is NULL in REST MockService

What solution did u find for this problem?

Member

Re: [SoapUI 5.2.1] mockRequest is NULL in REST MockService

What solution did you get for this problem?

 

thanks

Jay

New Member

Re: [SoapUI 5.2.1] mockRequest is NULL in REST MockService

I had the same error in a GET mockservice and I have fixed doing the following work around:

 

def requestBody = ""

if (mockRequest != null) {

  requestBody = mockRequest.getRequestContent()

}
log.info "Request body: " + requestBody

New Contributor

Re: [SoapUI 5.2.1] mockRequest is NULL in REST MockService

Using @rupert_anderson 's code, the green 'play' button pops up the 'mockRequest is Null' warning, because the mock request object is not def'd up.

 

The mockRequest object is defined when a 'real' test executes the MockService endpoint.

 

To test code while writing it I put the following TestCode code and click 'play' until I am done.

Then I send a Test Step to call the MockService endpoint:

 

def mockRequestrequestContent = "" 
if (mockRequest != null)
mockRequestrequestContent = mockRequest.requestContent
else
mockRequestrequestContent = "<testRequestXmlOrJson/>"
log.info(mockRequestrequestContent)

//begin script

Note: The current version of SoapUI 5.50 doesn't have a log window at the bottom, trying to gather information to reply to your solution was challenging. I am new here, so might have missed a config setting somewhere :-)

Visitor

Re: [SoapUI 5.2.1] mockRequest is NULL in REST MockService

Hello.

I'm getting probably the same issue in POST requests. I'm trying to read JSON request body in the dispatch script of my RESTfull mock in SOAPui.

 

// log the request body
log.info(mockRequest.getRequestContent())

 

// Parse the JSON request.
def requestBody = new groovy.json.JsonSlurper().parseText(mockRequest.getRequestContent())

 

// Set up MSISDN value from the request message.
requestContext.msisdn = requestBody.phone_number
requestContext.uuid = requestBody.MC_UUID

return "Response_OK"

 

 

After mock restart it works just once. When I repeat the request with same (or different) values it stops on Null value in getRequestContent.

 

I'm using SOAP UI 5.5.0 for mock and Postman 7.16 for client.

 

Sending the request

 

POST http://localhost:8181/v1/identity

{
"MC_UUID":"550e8400-e29b-41d4-a716-446655440000",
"phone_number":"31657100013"

}

 

with headers

Content-Type:application/json

Accept:application/json

User-Agent:PostmanRuntime/7.16.3

Content-Length:89

Connection:keep-alive

Host:localhost:8181

Cache-Control:no-cache

Accept-Encoding:gzip, deflate

 

In the script log of the SOAP ui mock I can see

Mon Sep 09 18:14:40 CEST 2019:INFO:{"MC_UUID":"550e8400-e29b-41d4-a716-446655440000","phone_number":"31657100013"}

 

Mon Sep 09 18:14:46 CEST 2019:INFO:

 

So 1st time the request passed with correct body, 2nd time the same POST is delivered with empty body.

I need always to restart the mock to make the 1st test working.

Very strange behaviour.

Thanks in advance for any hints & advices.

Jozef

New Here?
Join us and watch the welcome video:
Join the exciting event
SeptemberHubBub
Top Kudoed Authors
Join the September Hub-bub to show off, learn and win