Ask a Question

Getting null on mockRequest.getRequestContent() in one of REST services


Getting null on mockRequest.getRequestContent() in one of REST services

Hello! I have several mock services in my SOAP project. I use the last version of SOAP UI (5.7.0)
One of the services contanis two methods with same path:


I have the same groovy script in both actions:

import groovy.json.JsonOutput
import groovy.json.JsonSlurper

class Response {
    Integer code
    String message
    String accountId

try {
    def requestBody = mockRequest.getRequestContent()
    def requestJson = new JsonSlurper().parseText(requestBody)
    def phone = as String
    def email = as String
    def response
    if (phone == null || phone.trim() == "") {
        response = new Response(code: 1011, message: 'Field phone is required')
    } else if (phone == "+79777777777") {
        response = new Response(code: 1021, message: 'The phone field must be in the format +79991112233')
    } else if (email == "") {
        response = new Response(code: 1022, message: 'The email field must be in the format')
    } else {
        response = new Response(code: 0, message: 'Success', accountId: UUID.randomUUID().toString())
    requestContext.response = JsonOutput.toJson(response).toString()
    return "response"
} catch (Exception ex) {
    requestContext.response = JsonOutput.toJson(new Response(code: 500, message: ex.message)).toString()
    return "response"

 My problem is that I'm getting error only in PUT method:


Another interesting fact that if I move my 'PUT' action from 'kaspersky' service to 'invest' or another, I won't get this error:



Creating another action with another path (not 'kaspersky') doesn't help. What can be a problem?

Champion Level 3

Hi @MaxRybalkin91 ,

this seems to be an old bug of PUT operation in REST mocks.


It was already discussed here: .


And the thread suggests a workaround (not nice, but working):

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


Best regards,

Showing results for 
Search instead for 
Did you mean: