Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing file resources in SoapUI Mock Service Deployed in tomcat

Problem in short : Accessing local file in SCRIPT Dispatcher with respect to project path i.e., def file = new File(groovyUtils.projectPath+"/${responseFileName}.xml"). This is working fine when the test is run from SoapUI as Mock Service. But giving nothing or empty for above statement (groovyUtils.projectPath) when the same test is run against Deployed(remote tomcat) Mock Service.

Note: Here the responseFileName is present in the same location(when running SoapUI tool), relative to the soapui project xml

More Details about the problem:

Wanted to deploy the above mock service in tomcat. So, created war using Deploy as war from SoapUI, this has created a .war file. If the .war is extratcted, it shows the following directory structure.

└───WEB-INF
    ├───actions
    ├───lib
    ├───listeners
    └───soapui

And the soapui project xml is present under WEB-INF/soapui directory.

Since, Script dispatcher is using groovyUtils.projectPath, and .war file does not have that responseFile, added the required responseFile under WEB-INF/soapui directory using 7zip utility. And deployed the updated .war file in tomcat which is successful.

When the test request is hit to the deployed mock service, it is showing empty response and the following stacktrace in tomcat's catalina.out :

17-Jan-2016 10:13:32.356 SEVERE [http-nio-8080-exec-6] com.eviware.soapui.mockaswar.MockAsWarServlet.service null
 com.eviware.soapui.impl.wsdl.mock.DispatchException: Failed to dispatch using script; java.io.FileNotFoundException: \responseFile.xml (The system cannot find the file specified)
        at com.eviware.soapui.impl.wsdl.mock.dispatch.ScriptMockOperationDispatcher.selectMockResponse(ScriptMockOperationDispatcher.java:91)
        at com.eviware.soapui.impl.wsdl.mock.WsdlMockOperation.dispatchRequest(WsdlMockOperation.java:199)
        at com.eviware.soapui.impl.wsdl.mock.WsdlMockDispatcher.dispatchPostRequest(WsdlMockDispatcher.java:218)
        at com.eviware.soapui.impl.wsdl.mock.WsdlMockDispatcher.dispatchRequest(WsdlMockDispatcher.java:113)
        at com.eviware.soapui.impl.wsdl.mock.WsdlMockRunner.dispatchRequest(WsdlMockRunner.java:142)
        at com.eviware.soapui.mockaswar.MockAsWarServlet$MockServletSoapUICore.dispatchRequest(MockAsWarServlet.java:247)
        at com.eviware.soapui.mockaswar.MockAsWarServlet.service(MockAsWarServlet.java:182)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1017)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
        at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1575)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1533)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
  • How to refer the resource files in the SCRIPT Dispatcher so that it works in both way:

    a. mock service with in SoapUI

    b. deployed mock service in Tomcat

By the way, I am not sure if there is anything wrong in the way it is done.

Using:

SoapUI Open Source Edition - 5.2.1

Apache Tomcat - 8.0.5

Update: what is already tried apart from mentioned above in the short description

Only the following variables(underlined) are available in Script Dispatcher enter image description here

And if you use context in Script Dispatcher, unfortunately none of the usual methods for servlet context working such as below

No signature of method: com.eviware.soapui.impl.wsdl.mock.WsdlMockRunContext.getResourceAsStream() is applicable

No signature of method: com.eviware.soapui.impl.wsdl.mock.WsdlMockRunContext.getRealPath() is applicable

Obiviously because, SoapUI's API for WsdlMockRunContext does not have such public methods available.

I believe that there must be a different way which I am not aware and looking to know from the community.

like image 208
Rao Avatar asked Jan 17 '16 05:01

Rao


1 Answers

The main issue being : groovyUtils.projectPath is working only for first use case, and getting nothing for second use case.

After lot of trial & errors and search on the net, found a hint in one of the samples and the following approach working to be able to access the local file resource both below use cases as mentioned in the question.

  • running as mock service from soapUI itself
  • deployed as war in remote tomcat

So changed the code (script of mock dispatcher)
from:

   def file = new File(groovyUtils.projectPath+"/${responseFileName}.xml")

to:

   def projectPath = new File(mockOperation.mockService.project.path).parent
   def file = new File(projectPath.+"/${responseFileName}.xml")

Note: file(resource) must be available in the same location where soapui project file is present on the disk i.e., after creatin .war file, update .war file and make sure the required file is placed under WEB-INF/soapui as that where soapui's project xml is available.

like image 192
Rao Avatar answered Nov 07 '22 18:11

Rao