Deployment and testing
Seems like we're ready to deploy and test the Web service. In this section, we package our Web service for deployment, deploy it, and test it using Representational State Transfer (REST) and the client you've built.
Creating a deployment package of your Web service
Before you can run the stand-alone server and test the Web service, you need to package your code in a WAR file for deployment:
- Select the WSDL file in the Navigator view
- Click SOA > Generate Deploy Package
That creates a deployable WAR file at WebContent/ScientificCalculator.war in your project.
Now you're good to move on and run the stand-alone Web server.
Running the stand-alone Web server
The development framework comes with a stand-alone Web server, which allows you to perform testing of your Web service within the Eclipse framework.
Note that the STP plug-in has created a couple preconfigured run configurations. To run the server:
- Double-click the Java interface in the Navigator view
- Click Run > Run
- Select Java Application > ScientificCalculatorServer_server_com.ibm.dw.scicalc, as shown in Figure 7
- Click Run
Figure 7. Running the server
The server should then run and let you know it's ready.
Figure 8. Server ready
Now point your browser to http://localhost:8080/ScientificCalculator/services/ScientificCalculatorService?wsdl and you should see the WSDL. Next, we test the Web service in a browser using REST.
With a browser pointed to the WSDL of the Web service, you can now test operations on it. Point your browser to http://localhost:8080/ScientificCalculator/services/ScientificCalculatorService/square?square0=4.5.
Notice that we're calling the square operation with 4.5 as the parameter. You'll get a file of type soap+xml, that will show 20.25 as the result, as shown in the SOAP message that gets returned below.
Listing 15. SOAP message response
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<ns2:return xmlns:ns2="http://scicalc.dw.ibm.com/"
xmlns="http://www.w3.org/2005/08/addressing/wsdl">
20.25
</ns2:return>
</soap:Body>
</soap:Envelope>
|
You can see the answer is 20.25. Feel free to test out the other operations using REST. Next, we do a more regressive test using your client.
Testing by running the client code
Now that you know your service is up and functional with a REST test, you can perform a more rigorous and all-encompassing test using your client. To run the client:
- Double click the Java interface in the Navigator view
- Click Run > Run
- Select Java Application > ScientificCalculatorClient_client_com.ibm.dw.scicalc
- Select the Arguments tab
- Replace the "Program arguments" pane with http://localhost:8080/ScientificCalculator/services/ScientificCalculatorService?wsdl, as shown in Figure 9
- Click Run
Figure 9. Configuring the client
After clicking Run, the client will run and execute each operation in the console, as shown below.
Figure 10. Results of executing the client
You can see the server output of the client's execution by switching to its console, as shown below.
Figure 11. Server output
There you are! You have a completely functional Web service. Next, we do a final test by deploying the Web service on Apache Tomcat.
Deploying and testing on Apache Tomcat
Before you begin setting up Tomcat inside of Eclipse, you first need to copy some jars over to Tomcat's shared/lib directory by doing the following: Copy all jars except cxf-integration-jbi-*.jar (note the asterisk being a wildcard), or cxf-integration-jbi-2.0-incubator-RC-SNAPSHOT.jar for this tutorial, from CXF-Runtime-install-directory/lib to Tomcat-install-directory/shared/lib.
OK -- you're ready to move on and deploy the package on Tomcat using the Eclipse DTP. You'll begin by creating a new connector (the first four steps are also for if you want to optional start the Tomcat server within Eclipse):
- Click File > New > Other
- Open the Server folder and select Server
- Select, under the Apache folder, Tomcat v5.5 Server
- Click Finish
- Now click File > New > Other
- Open the Connection Profiles folder and select Connection Profile
- Select Tomcat Connection Profile
- Click Next
- Enter a name, Tomcat 5.5, and click Next
- Browse for the directory you installed Tomcat to (C:\apps\tomcat-5.5.20 for this tutorial)
- Click Finish
To deploy on Tomcat, start the Tomcat server by running startup.bat (Windows®) or startup.sh (Linux®). Once Tomcat is running, deploy your Web service by:
- Selecting the WAR file in the Navigator view
- Right-clicking it and selecting Deploy, as shown below
Figure 12. Server output
- Click the connection profile you made, Tomcat 5.5, and click OK
- If you've deployed before, you'll get a warning message, as shown in Figure 13. Click OK
Figure 13. Possible ignorable warning message
Now run the client as before, and you should get exactly the same output shown in Figure 10. Tomcat's standard output should also display what's shown in Figure 11.
We have built and tested a Web service successfully using the Eclipse STP plug-in.

