| <?xml-stylesheet type="text/xsl" href="../../../../../wtp.xsl"?> |
| <html> |
| <head> |
| <meta name="root" content="../../../../../../" /> |
| <title>Running Web service scenarios using Ant</title> |
| </head> |
| <body> |
| <h1>Running Web service scenarios using Ant</h1> |
| <p> |
| <b>By Joan Haggarty</b> |
| <br /> |
| November 23, 2005 |
| <br /> |
| <br /> |
| </p> |
| |
| <h2>Introduction</h2> |
| <br></br> |
| <p> |
| This document is one of a series of tutorials to |
| demonstrate the use of the Web Services tools in the Web |
| Tools Platform Project with the <b>WTP 1.0 M9 drivers</b>. |
| </p> |
| <p> |
| This tutorial shows how to run Web services scenarios (top down web service, bottom up web service |
| and client generation) without the web service wizard by way of an Ant task. For M9, the |
| tasks are only supported on Windows but will be available on Linux in M10. |
| </p> |
| <p> |
| The Ant task can be invoked in one of two ways: |
| <ol> |
| <li>From the command line on Windows from the <b>wsant.bat</b> file. This method runs |
| Eclipse headless. Customization of the batch file to reflect your environment is necessary.</li> |
| <li>From within Eclipse, the Ant file <b>wsgen.xml</b> can be invoked directly as an |
| Ant build file.</li> |
| </ol> |
| The objective of this tutorial is to show how to configure the batch file, Ant file and properties |
| files in addition to invoking the Ant task. The scenario will use the top down service generation |
| scenario to invoke the task inside the Eclipse workbench and then inovke the task from the command |
| line to generate the client for the generated web service. |
| </p> |
| |
| <h2>Set up</h2> |
| |
| <br></br> |
| <p> Before creating the Web service, there are two |
| prerequisites: </p> |
| <ol> |
| <li> |
| <a href="InstallTomcat.html">Install Apache Tomcat</a> |
| </li> |
| <li> |
| <a href="CreateWebProject.html"> |
| Create a dynamic Web project</a> called |
| <b>testProject</b> |
| . |
| </li> |
| </ol> |
| |
| <h2>Service Generation - Using the Ant Task inside Eclipse</h2> |
| |
| <p> |
| First, import the Ant files into the Eclipse workbench. |
| |
| <ol> |
| <li>Within, WTP, create a simple project called <b>AntTest</b>.</li> |
| <li>Once you have created the simple project, use the main menu and |
| select: <b>File > New > Other > Web Services > Ant Files</b>. Click <b>Next</b>. |
| <br/> |
| <img border="0" |
| SRC="resources/antimport1.jpg" /> |
| <br/> |
| </li> |
| <li>Browse to the <b>AntTest</b> project. |
| <br/> |
| <img border="0" |
| SRC="resources/antimport2.jpg" /> |
| <br/> |
| </li> |
| <li>Click <b>Finish</b>.</li> |
| <li>Under the <b>Other Projects</b> in the <b>Project Explorer</b> view, three files have been imported into the |
| <b>AntTest</b> project folder: |
| <ul> |
| |
| <li><b>wsgen.xml </b>- the Ant file </li> |
| <li><b>axisservice.properties </b>- a sample Ant properties file for generating web services for the Axis runtime</li> |
| <li><b>axisclient.properties </b>- a sample Ant properties file for generating a web service client for the Axis runtime</li> |
| |
| </ul> |
| </li> |
| </ol> |
| |
| </p> |
| <p> |
| Next, import the sample WSDL file <a href="resources/AreaService.wsdl">AreaService.wsdl</a> file into |
| the WebContent folder of the dynamic web project <b>testProject</b>. |
| </p> |
| <p> |
| No matter where the task is invoked, required input needs to be provided to the Ant task by way |
| of properties and a reference to the properties file updated from the Ant file. |
| The properties file must specify the resource that will be used to generate the service. |
| In this example, we will point to the <b>AreaService.wsdl</b> file in the <b>testProject</b> |
| web project. The type of scenario needs to be specified as well. |
| In this case, the scenario will be <code>service</code>. |
| </p> |
| <ol> |
| <li>Go to the <b>AntTest</b> project under <b>Other Projects</b> in the <b>Project Explorer</b> view. |
| Open and edit the <b>wsgen.xml</b> Ant script so that <code>property file="axisservice.properties"</code>. |
| This indicates to the Ant task that you want to generate a service as opposed to a client. Remove any other property |
| file settings from the <b>wsgen.xml</b> file</li> |
| <li>Save the <b>wsgen.xml</b> file.</li> |
| <li>Edit the <b>axisservice.properties</b> file. Check that <code>scenarioType=service</code> |
| and set InitialSelection to a workspace relative path that points to the AreaService.wsdl: <code>InitialSelection=/testProject/WebContent/AreaService.wsdl</code>. You can delete all |
| of the other properties in the properties file. The Ant task will default the properties based on the dynamic |
| project settings and the scenarioType setting.</li> |
| <li>Save the <b>axisservice.properties</b> file. </li> |
| <li>Right click on the <b>wsgen.xml</b> file and select <b>Run As > Ant Build...</b></li> |
| <li>In the Ant dialog, click on the <b>JRE</b> tab and choose the radio button <b>Run in the same |
| JRE as the workspace</b>. Click <b>Apply</b> and then <b>Run</b> |
| <br/> |
| <img border="0" |
| SRC="resources/antdialog.jpg" /> |
| <br/> |
| |
| |
| </li> |
| <li>Once the generation is complete, you will get a <tt>Build Successful</tt> message in the console. |
| <b>AreaServiceSOAP.wsdl</b> should have been generated into the project's <b>WebContent\wsdl</b> folder |
| as well as the Java code in the <b>src</b> folder for the <b>testProject</b> web project in the <b>org.tempuri.AreaService</b> package - |
| |
| <ul> |
| <b> |
| <li>AreaService_PortType.java</li> |
| <li>AreaService_Service.java</li> |
| <li>AreaService_ServiceLocator.java</li> |
| <li>AreaServiceSOAPImpl.java</li> |
| <li>AreaServiceSOAPSkeleton.java</li> |
| <li>AreaServiceSOAPStub.java</li> |
| <li>Dimensions.java</li> |
| </b> |
| </ul> |
| You will also see deployment descriptors were generated in the <b>WebContent\WEB-INF</b> folder: |
| <ul> |
| <b> |
| <li>undeploy.wsdd</li> |
| <li>deploy.wsdd</li> |
| </b> |
| </ul> |
| </li> |
| </ol> |
| <b>Note:</b> to invoke a bottom up service generation, the only change required from the top down service generation shown |
| in this tutorial would be to specify a Java resource as the <b>InitialSelection</b> property setting in the |
| axisservice.properties file. The scenario is still "service". |
| <br/> |
| |
| <h2>Client Generation - Using the Ant Task at the Command Line</h2> |
| <p> |
| Typically, you would use |
| either the Eclipse or the command line mechanism to invoke the Ant task, not both. |
| However, for the purposes of showing how |
| the Ant tasks can be invoked, we'll switch out to the command line to demonstrate generating the client code. |
| The next task is to generate a client for the AreaService web service using the same project and the |
| WSDL file generated using the <tt>wsgen</tt> Ant task within Eclipse earlier. |
| </p> |
| <ol> |
| <li>Navigate to the plugins directory of your WTP installation. Change to the |
| <b>org.eclipse.wst.command.env_1.0.0</b> plugin directory and then go to the |
| <b>ant</b> folder. For example: <b>D:\wtp1110\eclipse\plugins\org.eclipse.wst.command.env_1.0.0\ant</b></li> |
| <li> The following files should exist there: |
| <ul> |
| <b> |
| <li>wsant.bat</li> |
| <li>wsgen.xml</li> |
| <li>axisservice.properties</li> |
| <li>axisclient.properties</li> |
| </b> |
| </ul> |
| </li> |
| <li>Make backup copies of the files if you wish.</li> |
| <li>Open the <b>wsgen.xml</b> Ant file and edit so that <code>property file="axisclient.properties"</code>. Remove any other property file references in the |
| file such as axisservice.properties.</li> |
| <li>Save the <b>wsgen.xml </b></li> |
| <li>Edit the <b>axisclient.properties</b> file. Check that <code>scenarioType=client</code> and set the InitialSelection |
| property to a workspace relative path pointing to the AreaServiceSOAP.wsdl that was generated in the previous section of this tutorial. |
| <code>InitialSelection=/testProject/WebContent/wsdl/AreaServiceSOAP.wsdl</code>.</li> |
| <li>Save the <b>axisclient.properties file</b>. </li> |
| <li>Next, edit the <b>wsant.bat</b> file. Set the local environment variables to reflect your system configuration |
| inluding the location of your JRE, the Eclipse <b>startup.jar</b> and the workspace containing the |
| web project and <b>AreaServiceSOAP.wsdl</b> file. |
| </li> |
| <li>Save the <b>wsant.bat</b> file. </li> |
| <li>Run <b>wsant.bat</b> by typing wsant at the command line.</li> |
| <li>When the generation is complete, look at the <b>wsgen.txt</b> file for output. </li> |
| <li>At the command line or back in WTP, navigate to the testProject src folder to find the client <b>AreaServiceProxy.java</b> code that was generated.</li> |
| </ol> |
| |
| </body> |
| </html> |