Question

On running this below groovy script in OnRequest script tab of a soapUI mock request I get the below error

mockRunner.returnFile(mockRequest.httpResponse, new File(projectDir,"xmlresponse.xml")) return new com.eviware.soapui.impl.wsdl.mock.WsdlMockResult(mockRequest)

    ERROR:An error occurred [groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.mock.WsdlMockRunner.returnFile() is applicable for argument types: (org.mortbay.jetty.Response, java.io.File) values: [HTTP/1.1 200 

, C:\UXX\XXXX\AAAAA\xmlresponse.xml]], see error log for details

Any help is appreciated. Thank you.

Edited:

I tried your suggestion but getting this error. You cannot create an instance from the abstract interface. Then I tried a different way , found out by searching web.

def response = mockRequest.httpResponse
File file = new File("C:/Users/xx/xx/xxx/xmlresponse.xml")
FileInputStream fin = new FileInputStream(file);
response.setStatus( HttpServletResponse.SC_OK )
long length = file.length();
response.setContentType("application/xml;charset=utf-8" );
Tools.readAndWrite( fin, length, response.getOutputStream() );
fin.close();
return new com.eviware.soapui.impl.wsdl.mock.WsdlMockResult(mockRequest) 

But the issue with this is I am getting the xml response in the Json and raw tab of response side. When I set content as xml like this response.setContentType("application/xml;charset=utf-8" ) in above code , it doesnt give anything in json and xml tab but gives the response with xml content in raw tab. How do I get xml content back in xml tab?

Was it helpful?

Solution 2

I was having the exact same issue with my mock REST request / response in Soap UI 5

The other answer is correct in theory, creating a response in a groovy script does in fact work. However, there was some issue with the Groovy OnRequest script. Here's the code segment I used to create a valid XML response (courtesy of DivxYoda from this question HERE):

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

def httpResponse = mockRequest.httpResponse
httpResponse.setContentType("application/xml;charset=utf-8")
httpResponse.writer << "<root><user>ABC</user></root>"
httpResponse.status = 200
return mockResult

Tested, and works great for me!

OTHER TIPS

The com.eviware.soapui.impl.wsdl.mock.WsdlMockRunner.returnFile() function accepts

javax.servlet.http.HttpServletResponse

and File

instead of javax.servlet.http.HttpServletResponse you are sending org.mortbay.jetty.Response. To send a javax.servlet.http.HttpServletResponse value you could do something like this..

import javax.servlet.http.HttpServletResponse;

def response = new HttpServletResponse();

response.setStatus(200)
response.setContentType("text/xml;charset=UTF-8");

Link: Values not passing from TextBox to Servlet File

and then pass the response variable to the returnFile() function.

Note: The code is untested!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top