Forum Discussion

ramprakash4's avatar
ramprakash4
Occasional Contributor
6 years ago
Solved

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(com.eviware.soapui.impl.rest.mock.RestMockRequest)
  • 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) 

OR

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?

 

Thanks,

Ram

 

 

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

    import groovy.json.JsonSlurper
    import groovy.json.JsonOutput
    import com.eviware.soapui.impl.rest.mock.RestMockResult
    
    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
    		}
    	break
    	case context.getMockService().path + '/admin/user/delete':
    		//etc
    	break
    	default:
    	break
    }
    
    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
    JHunt
    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
      ramprakash4
      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

       

      Ram

      • JHunt's avatar
        JHunt
        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 com.eviware.soapui.impl.rest.mock.RestMockResult

        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.