Thursday, May 31

Deploying SOAPUI mock service as a web application

I recently worked on a heavily TDD (test driven development) SOA project in which we used SOAPUI extensively to unit test atomic pieces of work. It was a large team of developers with a constant need to test new and on-going development work against mock services.

I tried to use the tutorial here but kept running into errors first wth JBoss and then with Tomcat (I eventually used Tomcat because I liked the UI better).

I have therefore re-written the tutorial with the steps I took to get the whole system in place.

Follow these steps to install Apache Tomcat  and then create and deploy your mocks as war (Web application ARchive) files

1. Download  and install the latest java SDK from http://www.oracle.com/technetwork/java/javase/downloads/ for your system (for me it was 7u4).
Run the relevant (jdk-7u4-windows-x64) installer with the default options, which will install Java into "C:\Program Files\Java\jdk1.7.0_04\". Note: ideally use the full JDK (Java Development Kit), which contains the JRE (Java Run-Time Engine) and other useful tools for developers


2. Install Apache Tomcat from http://tomcat.apache.org/download-70.cgi (I downloaded the apache-tomcat-7.0.27.exe from the 32-bit/64-bit Windows Service Installer (pgp, md5)
 link ). I installed Tomcat to port 8090 on localhost. Make sure the Tomcat Manager is also installed




If you would rather try JBoss as the web server, a lovely tutorial on JBoss can be found here

3. Open SOAPUI (A trial can be downloaded from http://sourceforge.net/projects/soapui/files/). The following mock service instructions are modified from this nice tutorial

4. We will now create a new mock service which will eventually be deployed and exposed via Tomcat. The first thing you will need is the WSDL of the web service you want to mock. I’m going to use a publicly available temperature converting web service available here: http://www.webservicex.net/ConvertTemperature.asmx?WSDL

5. Create a new SOAPUI project (Right-click on 'Projects' in SOAPUI)


5. Fill in the dialog as shown below, and click OK


You will be prompted by SOAPUI (after it inspects the WSDL) to set options for the Mock Operations for the ConvertTemp interface. Leave the port on the default srtting as tick the 2 boxes as shown below and click OK



6. Specify a name for the MockService to hold that interface. (I used ConvertTemperatureSoapMockService) and click OK


Repeat this process for the other MockServices prompted by IIS (I used ConvertTemperatureSoap12MockService)

You should now have something similar to the structure shown below
 


7.  Right-click on the project you just created and select the 'Deploy As War' menu item

 


8. Fill in the dialog as shown in the image below. (C:\Projects\MyTestMockLibraryFolder is the location to which I am deploying the web applicaiton for the mock service). Tick the 'Check to enable WebUI' checkbox so that you can view the mock service using the WebUI. Click on OK

 


SOAPUI will prompt you to save the project file so you can re-open it later if you need to modify it. Select a save location and click on OK. Note: Not sure if this is a bug or simply misleading interface, but SOAPUI will NOT create the war file in the War Directory you specify using the settings above. It will create the actual web applicaiton. If you want SOAPUI to actually generate the war file in the location, you need to fill in the 'War File' box by specifying the full path including the directory as such: C:\Projects\MyTestMockLibraryFolder\MyTestMockLibrary.war)

SOAPUI then creates the web application. The soapui log should be something like the image below


10. Browse to the specified War Directory and you should see the web application components

11. Open the WEB-INF folder and note the web.xml file

12. Check that Tomcat is installed and running by browsing to the port you specified when installing it. (http://localhost:8090 for me). You should see the welcome to Tomcat page. If not, check services and make sure that the Apache Tomcat 7.0 Tomcat7 service is running. Click on the 'Manager App' button

10. On the App Manager page, scroll down to the 'Deploy' section


12. Using the 'Deploy directory or War file located on server' section, fill in the Context Path as the service name for the service url you added in SOAPUI earlier (see first image below)


The Deployment seciton in the App Manager should look like the image below


13. In the 'XML Configuration File URL' box, type in the web.xml path for the file you noted in step 11 above (i.e. /WEB-INF/web.xml)

14. Type or paste the War Directory path into the 'WAR or Directory URL' box. The section should now look like the image below


15. Click on Deploy. You should see an OK message at the top of the App Manager window. Your web application should now be deployed

 

16. Still on the App Manager page, find the new service and click on the link


17. You will probably get an error page stating that the resources are not available. In the browser adress bar, add a forward slash to the URL (http://127.0.0.1:8090/TestMockLibrary becomes http://127.0.0.1:8090/TestMockLibrary/) and hit the Enter button on your keypad. You should now see the Mock Service page in the WEBUI.

 

18. Click on one of the Mock Operations as shown to view the WSDL

 


19. You can now call this service from any application using the URL as long as Tomcat is running on the host machine