Forum Discussion

ramprakash4's avatar
Occasional Contributor
6 years ago

Could not find matching constructor for: WsdlMockResult(RestMockRequest)

I have a SOAP UI project that is built to provide mock response JSON to a request JSON.


Attached are 2 files

1. Groovy script used in the MockService to interpret the request and construct a dynamic JSON response.

2. Error log from SOAP UI 


 I have been able to test the JSON responses being sent to

1. My Mock Requests from within SOAP UI

2. By invoking SOAPUI project War file deployed in my tomcat locally.


However what I have noticed is that when we now try to hit the same URLs via our application code (Java code), it is failing.


Upon checking the error logs we noticed that the following error was appearing

  • Mon Aug 27 14:33:01 AEST 2018:ERROR:com.eviware.soapui.impl.wsdl.mock.DispatchException: com.eviware.soapui.impl.wsdl.mock.DispatchException: Failed to dispatch using script; groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.eviware.soapui.impl.wsdl.mock.WsdlMockResult(
  • Mon Aug 27 14:33:01 AEST 2018:ERROR:got an exception while dispatching - returning a default 500 response


For some reason the responses are being received when

SOAPUI Mock Request --> SOAP UI Mock Service

SOAP UI Mock Request --> SOAP UI WAR deployed in Tomcat


It fails when the same Tomcat URL (http://localhost:8080/webservicemocks/dafStubs) 


SOAPUI Mock service URL (http://localhost:9080/dafStubs) 

is invoked via Java code. 


I have also attached my whole soap UI project XML here for reference.


Can someone point me in the right direction as to why I am seeing this error?






  • I implemented the 'Create User' request like this:

    import groovy.json.JsonSlurper
    import groovy.json.JsonOutput
    Map responseObject = [:]
    switch (mockRequest.path) {
    	case context.getMockService().path + '/admin/user':
    		if (mockRequest.method.toString() == 'POST') {
    			responseObject = createUser()
    		} else if (mockRequest.method.toString() == 'PUT') {
    			// etc
    		} else {
    			// etc
    	case context.getMockService().path + '/admin/user/delete':
    mockRequest.httpResponse.setHeader ('Content-Type', 'application/json')
    mockRequest.httpResponse.getWriter() << JsonOutput.toJson(responseObject)
    return new RestMockResult(mockRequest)
    // Responses
    public Map createUser() {
    	Map requestObject = new JsonSlurper().parseText(mockRequest.requestContent)
    	return [
    		status: [
    			code: "DA-200",
    			message: "Success",
    			logMessage: "Success",
    			logMessageAttributes: null
    		createUserResult: requestObject.operationDetails

5 Replies

  • JHunt's avatar
    Community Hero

    You should return a RestMockResult instead of a WsdlMockResult. You can't create a WsdlMockResult for a RestMockRequest.


    See if that is your problem. I'm not sure why it would work in the other cases you mentioned!

    • ramprakash4's avatar
      Occasional Contributor

      Thank you much for the reply. Do you have any examples that you can point me to - from a groovy script syntax P.O.V to use RestMockRequest and set JSON response



      • JHunt's avatar
        Community Hero

        Hi Ram,

        I got a chance to open your project, so I can see what's happening. Did you know that even when you are testing your MockService from SoapUI, it is generating errors? You can see it in the Error Log. Also, if you look at the Raw tab on a response, you can the status code is 500 (Internal Server Error).


        There are two problems: this is a REST MockService, but your script says

        new WsdlMockResult(mockresponse)

        which is for SOAP services. It should be changed to

        // import

        new RestMockResult(mockresponse)

        The second problem is where you wrote your scripts. The SCRIPT section for a Method should be used when you want to run a Groovy Script to select from an existing MockResponse. That type of script should just return a String which names the response.


        The type of scripting you are doing, where you write to the httpResponse and return a MockResult belongs in the OnRequest section of the MockService. This one script will be used for EVERY request type, so I would recommend splitting it up into multiple methods.


        See attached for an example of how you might start on your project.