Forum Discussion

MaxRybalkin91's avatar
3 years ago

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 = requestJson.phone as String
    def email = requestJson.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 == "testt@testt.com") {
        response = new Response(code: 1022, message: 'The email field must be in the format test@test.com')
    } 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?

1 Reply