Forum Discussion

eduardocasino's avatar
eduardocasino
New Contributor
8 years ago
Solved

OnRequest script causes mock service to fail with 500 Internal Server Error

Hi, I'm creating a REST mock service which supports just a few methods and I want the service to return a 405 Method Not Allowed whenever an unsupported method is invoked. So, I've created mock actions for the supported ones and placed this piece of code into the "OnRequest Script" tab of the service:

 

if ( mockRequest.method != "GET" && mockRequest.method != "POST" )
{
	
	mockRequest.httpResponse.status = 405

	return new com.eviware.soapui.impl.wsdl.mock.WsdlMockResult( mockRequest )

}

Each time I call the service, I'm getting a "500 Internal Server Error", no matter which method I use. Commenting out the "return" line, I get no error (but, of course, no filtering is done)

 

Is there anything obvious that I'm missing? SoapUI version is 5.3.0 on Ubuntu 16.04, Java 9 VM.

 

Many thanks,

Eduardo

  • I'll answer myself, this is the correct code:

     

    if ( mockRequest.httpRequest.method != "GET" && mockRequest.httpRequest.method != "POST" )
    {
    	
    	mockRequest.httpResponse.status = 405
    
    	return new com.eviware.soapui.impl.rest.mock.RestMockResult( mockRequest )
    
    }

     

1 Reply

  • I'll answer myself, this is the correct code:

     

    if ( mockRequest.httpRequest.method != "GET" && mockRequest.httpRequest.method != "POST" )
    {
    	
    	mockRequest.httpResponse.status = 405
    
    	return new com.eviware.soapui.impl.rest.mock.RestMockResult( mockRequest )
    
    }