| <!-- |
| /******************************************************************************* |
| * Copyright (c) 26.04.2007 WSO2 Inc. Others |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * WSO2 Inc - Initial version of the Tutorial |
| * 20070426 182718 sandakith@wso2.com Lahiru Sandakith, Initial Tutorial Implementation |
| * 20070513 186704 sandakith@wso2.com Lahiru Sandakith, Update the BU Tutorial to sync with the Axis2 1.2 |
| * 20070629 194962 sandakith@wso2.com Lahiru Sandakith, Update the BU Tutorial to sync with WTP 2.0 |
| *******************************************************************************/ |
| --> |
| <html> |
| <head> |
| <meta |
| http-equiv="Content-Type" |
| content="text/html; charset=UTF-8"> |
| <meta |
| http-equiv="Content-Type" |
| content="text/html; charset=iso-8859-1"> |
| <link |
| rel="stylesheet" |
| href="./default_style.css" |
| type="text/css"> |
| <link |
| rel="stylesheet" |
| href="stylesheets/wtp.css" |
| type="text/css"> |
| <title>Eclipse WTP Tutorials - Creating Bottom Up Web Service via Apache Axis2</title> |
| </head> |
| <body> |
| <table |
| width="100%" |
| cellspacing="5" |
| cellpadding="2" |
| border="0"> |
| <tbody> |
| <tr> |
| <td |
| width="60%" |
| align="left"><font |
| class="indextop" |
| size="5"><b>Eclipse WTP Tutorials - Creating Bottom Up Web Service via Apache Axis2</b></font></td> |
| <td width="40%"><img |
| width="207" |
| hspace="50" |
| height="129" |
| align="middle" |
| src="images/wtplogosmall.jpg" |
| alt=""></td> |
| </tr> |
| </tbody> |
| </table> |
| <table |
| width="100%" |
| cellspacing="5" |
| cellpadding="2" |
| border="0"> |
| <col width="16"> |
| <col width="*"> |
| <tbody> |
| <tr> |
| <td |
| valign="top" |
| align="right"> </td> |
| <td valign="top"><b><a href="mailto:sandakith@wso2.com">By Lahiru Sandakith</a></b> <br /> |
| <a href="http://www.wso2.org"> WSO2 Inc.</a><br /> |
| June 29, 2007<br /> |
| <br /> |
| </td> |
| </tr> |
| <tr> |
| <td |
| valign="top" |
| bgcolor="#0080c0" |
| align="left" |
| colspan="2"><b><font |
| face="Arial,Helvetica" |
| color="#ffffff">Introduction</font></b></td> |
| </tr> |
| <tr> |
| <td |
| valign="top" |
| align="right"> </td> |
| <td valign="top"> |
| <p><br /> |
| This tutorial is meant to demonstrate the use of the newly introduced <b>Axis2</b> Web Services tools in the |
| Web Tools Platform Project using the <b>WTP 2.0</b> drivers. Also this shows how to create a simple Web |
| service and Web service client from a JAVA class. The JAVA class in this scenario converts between the |
| Celsius and Farenheit temperature scales and its the same class that used in the Axis web services |
| tutorials.</p> |
| <br /> |
| </td> |
| </tr> |
| <tr> |
| <td |
| valign="top" |
| bgcolor="#0080c0" |
| align="left" |
| colspan="2"><b><font |
| face="Arial,Helvetica" |
| color="#ffffff">Set Up</font></b></td> |
| </tr> |
| <tr> |
| <td |
| valign="top" |
| align="right"> </td> |
| <td valign="top">Before creating the Web service, there are two prerequisites: |
| <ol> |
| <li><a href="http://www.eclipse.org/webtools/releases/2.0/">Download Eclipse WTP 2.0</a> and unzip |
| it.</li> |
| <li><a |
| href="http://www.eclipse.org/webtools/jst/components/ws/1.5/tutorials/InstallTomcat/InstallTomcat.html"> |
| Configure Apache Tomcat inside Eclipse WTP.</a></li> |
| </ol> |
| </td> |
| </tr> |
| <tr> |
| <td |
| valign="top" |
| bgcolor="#0080c0" |
| align="left" |
| colspan="2"><b><font |
| face="Arial,Helvetica" |
| color="#ffffff">Creating a bottom up JAVA bean Web service and Web service client using Axis2 WTP |
| Tools</font></b></td> |
| </tr> |
| <tr> |
| <td |
| valign="top" |
| align="right"> </td> |
| <td valign="top"> |
| <p>This tutorial need a Axis2 runtime. You can download the latest axis2 binary distribution from <a |
| href="http://ws.apache.org/axis2/download.cgi">here</a>. <br /> |
| <b>Note :</b> Currently Axis2 version 1.2 is the supported version for the Web Services Scenarios</p> |
| <ol> |
| <li>Download the latest Axis2 runtime from the above link and extract it.</li> |
| <li>Now we point Eclipse WTP to downloaded Axis2 Runtime. Open <b>Window -> Preferences |
| -> Web Services -> Axis2 Emitter</b> <br /> |
| <img |
| border="0" |
| src="images/1_n.png" |
| alt=""> <br /> |
| <p>Select the Axis2 Runtime tab and point to the correct Axis2 runtime location. Alternatively at |
| the Axis2 Preference tab, you can set the default setting that will come up on the Web Services Creation |
| wizards. For the moment we will accept the default settings.</p> |
| </li> |
| <li>Click OK. <br /> |
| <br /> |
| </li> |
| <li>Next we need to create a project with the support of Axis2 features. Open <b>File -> New |
| -> Other... -> Web -> Dynamic Web Project</b> <br /> |
| <img |
| border="0" |
| src="images/a1.png" |
| alt=""> <br /> |
| <p>Click next</p> |
| </li> |
| <li>Select the name <b>Axis2WSTest</b> as the Dynamic Web project name (you can specify any name |
| you prefer), and select the configured Tomcat runtime as the target runtime. <br /> |
| <img |
| border="0" |
| src="images/a2.png" |
| alt=""> <br /> |
| <p>Click next.</p> |
| </li> |
| <li>Select the Axis2 Web service facet <br /> |
| <img |
| border="0" |
| src="images/a3_n.png" |
| alt=""> <br /> |
| <p>Click Finish.</p> |
| </li> |
| <li>This will create a dynamic Web project in the workbench <br /> |
| <img |
| border="0" |
| src="images/b1.png" |
| alt=""> <br /> |
| <br /> |
| <br /> |
| </li> |
| <li>Import the <a href="code/Converter.java">wtp/Converter.java</a> class into Axis2WSTest/src (be |
| sure to preserve the package). <br /> |
| <img |
| border="0" |
| src="images/b2.png" |
| alt=""> <br /> |
| <p>Build the Project, if its not auto build.</p> |
| </li> |
| <li>Select Converter.java, open File -> New -> Other... -> Web Services -> Web Service |
| <br /> |
| <img |
| border="0" |
| src="images/c1.png" |
| alt=""> |
| <br /> |
| <p>Click next.</p> |
| </li><li>The Web service wizard would be brought up with Web service type set to <b>Bottom up Java |
| bean Web Service</b> with the service implementation automatically filled in. Move the service scale to <b>Start |
| service</b>. |
| <br /> |
| <img |
| border="0" |
| src="images/c2_a.png" |
| alt=""> |
| <br /> |
| </li><li>Click on the <b>Web Service runtime</b> link to select the Axis2 runtime. |
| <br /> |
| <img |
| border="0" |
| src="images/c2_b.png" |
| alt=""> |
| <br /> |
| <p>Click OK.</p> |
| </li><li>Ensure that the correct server and service project are selected as displayed below. |
| <br /> |
| <img |
| border="0" |
| src="images/c2.png" |
| alt=""> |
| <br /> |
| <p>Click next.</p> |
| </li><li>This page is the service.xml selection page. if you have a custom services.xml, you can include |
| that by clicking the <b>Browse</b> button. For the moment, just leave it at the default. |
| <br /> |
| <img |
| border="0" |
| src="images/c3_n.png" |
| alt=""> |
| <br /> |
| <p>Click next.</p> |
| </li><li>This page is the Start Server page. It will be displayed if the server has not been started. |
| Click on the <b>Start Server</b> button. This will start the server runtime. |
| <br /> |
| <img |
| border="0" |
| src="images/c4.png" |
| alt=""> |
| <br /> |
| <p>Click next.</p> |
| </li><li>This page is the Web services publication page, accept the defaults. |
| <br /> |
| <img |
| border="0" |
| src="images/c5.png" |
| alt=""> |
| <br /> |
| <p>Click Finish.</p> |
| <br /> |
| <br /> |
| </li><li>Now, select the <b>Axis2WSTest</b> dynamic Web project, right-click and select Run -> Run As |
| -> Run on Server to bring up the Axis2 servlet. |
| <br /> |
| <img |
| border="0" |
| src="images/d1.png" |
| alt=""> |
| <br /> |
| <p>Click Next.</p> |
| </li><li>Make sure you have the <b>Axis2WSTest</b> dynamic Web project on the right-hand side under the |
| Configured project. |
| <br /> |
| <img |
| border="0" |
| src="images/d2.png" |
| alt=""> |
| <br /> |
| <p>Click Finish.</p> |
| </li><li>This will deploy the Axis2 server webapp on the configured servlet container and will display |
| the Axis2 home page. Note that the servlet container will start up according to the Server configuration |
| files on your workspace. |
| <br /> |
| <img |
| border="0" |
| src="images/d5.png" |
| alt=""> |
| <br /> |
| <br /> |
| <br /> |
| </li><li>Click on the <b>Services</b> link to view the available services. The newly created converter |
| Web service will be shown there. |
| <br /> |
| <img |
| border="0" |
| src="images/e1.png" |
| alt=""> |
| <br /> |
| <br /> |
| <br /> |
| </li><li>Click on the <b>Converter Service</b> link to display the ?wsdl URL of the newly created Web |
| service. Copy the URL. |
| <br /> |
| <img |
| border="0" |
| src="images/e2.png" |
| alt=""> |
| <br /> |
| <br /> |
| <br /> |
| </li><li>Now we'll generate the client for the newly created service by referring the ?wsdl generated by |
| the Axis2 Server. Open File -> New -> Other... -> Web Services -> Web ServiceClient |
| <br /> |
| <img |
| border="0" |
| src="images/f1.png" |
| alt=""> |
| <br /> |
| <br /> |
| <br /> |
| </li><li>Paste the URL that was copied earlier into the service definition field. |
| <br /> |
| <img |
| border="0" |
| src="images/f2.png" |
| alt=""> |
| <br /> |
| </li><li>Click on the <b>Client project</b> hyperlink and enter <b>Axis2WSTestClient</b> as the name of |
| the client project. Click OK. |
| <br /> |
| <img |
| border="0" |
| src="images/f2a.png" |
| alt=""> |
| <br /> |
| <br /> |
| </li><li>Back on the Web Services Client wizard, make sure the Web service runtime is set to Axis2 and |
| the server is set correctly. Click Next. |
| <br /> |
| <img |
| border="0" |
| src="images/f3.png" |
| alt=""> |
| <br /> |
| <br /> |
| <br /> |
| </li><li>Next page is the Client Configuration Page. Accept the defaults and click Finish. |
| <br /> |
| <img |
| border="0" |
| src="images/f3_n.png" |
| alt=""> |
| <br /> |
| <br /> |
| <br /> |
| </li><li>The Clients stubs will be generated to your Dynamic Web project <b>Axis2WSTestClient</b>. |
| <br /> |
| <img |
| border="0" |
| src="images/t1.png" |
| alt=""> |
| <br /> |
| <br /> |
| <br /> |
| </li><li>Now we are going to write Java main program to invoke the client stub. Import the <a |
| href="code/ConverterClient.java">ConverterClient.java</a> file to the workspace into the wtp package |
| in the src folder of <b>Axis2WSTestClient</b>. |
| <br /> |
| <img |
| border="0" |
| src="images/t2.png" |
| alt=""> |
| <br /> |
| <br /> |
| <br /> |
| </li><li>Then select the ConverterClient file, right-click and select Run As -> Java Application. |
| Here's what you get on the server console: |
| <br /> |
| <img |
| border="0" |
| src="images/t3.png" |
| alt=""> |
| <br /> |
| <br /> |
| <br /> |
| </li><li>Another way to test and invoke the service is to select <b>Generate test case to test the |
| service</b> check box on the Axis2 Client Web Service Configuration Page when going through the Web Service |
| Client wizard. |
| <br /> |
| <img |
| border="0" |
| src="images/tc_1.png" |
| alt=""> |
| <br /> |
| <br /> |
| </li><li>If that option is selected, the Axis2 emitter will generate JUnit testcases matching the WSDL |
| we provide to the client. These JUnit testcases will be generated to a newly added source directory to |
| the <b>Axis2WSTestClient</b> project called <b>test</b>. |
| <br /> |
| <img |
| border="0" |
| src="images/tc_2.png" |
| alt=""> |
| <br /> |
| <br /> |
| </li> |
| <li>Next thing we need to do is to insert the testcase with the valid inputs as the Web servivce |
| method arguments. In this case, let's test the ConverterConverterSOAP11Port_httpTest.java by provide |
| values for Celsius and Farenheit for the temperature conversion. As an example, replace the generated |
| TODO statement in each test method to fill in the data with values as: <pre> |
| testfarenheitToCelsius() -> farenheitToCelsius8.setFarenheit(212); |
| |
| testStartfarenheitToCelsius() -> farenheitToCelsius8.setFarenheit(212); |
| |
| testcelsiusToFarenheit() -> celsiusToFarenheit10.setCelsius(100); |
| |
| testStartcelsiusToFarenheit() -> celsiusToFarenheit10.setCelsius(100); |
| </pre> Here the testcases were generated to test both the synchronous and asynchronous clients. <br /> |
| </li> |
| <li>After that, select the testcase, right-click, select Run As -> JUnit Test. You will be able |
| to run the unit test successfully invoking the Web service. <br /> |
| <img |
| border="0" |
| src="images/tc_4.png" |
| alt=""> <br /> |
| <br /> |
| <br /> |
| </li> |
| </ol> |
| </td> |
| </tr> |
| <tr> |
| <td |
| valign="top" |
| bgcolor="#0080c0" |
| align="left" |
| colspan="2"><b><font |
| face="Arial,Helvetica" |
| color="#ffffff">Summary</font></b></td> |
| </tr> |
| <tr> |
| <td |
| valign="top" |
| align="right"> </td> |
| <td valign="top"> |
| <p>In this example, we show using the Web Services wizard followed by using the Web Service client |
| wizard. You could also choose to generate both service and client using the Web Services wizard: <br /> |
| <img |
| border="0" |
| src="images/bu_e2e.png" |
| alt=""><br /> |
| <br /> |
| </p> |
| <p>The Web Service wizard orchestrates the end-to-end generation, assembly, deployment, installation and |
| execution of the Web service and Web service client. Now that your Web service is running, there are a few |
| interesting things you can do with this WSDL file. Examples:</p> |
| <ul> |
| <li>You can choose Web Services -> Test with Web Services Explorer to test the service.</li> |
| <li>You can choose Web Services -> Publish WSDL file to publish the service to a public UDDI |
| registry.</li> |
| </ul> |
| </td> |
| </tr> |
| <tr> |
| <td |
| valign="top" |
| bgcolor="#0080c0" |
| align="left" |
| colspan="2"><b><font |
| face="Arial,Helvetica" |
| color="#ffffff">Resources</font></b></td> |
| </tr> |
| <tr> |
| <td |
| valign="top" |
| align="right"> </td> |
| <td valign="top"> |
| <p>You can also refer to the Axis Web services tutorials:</p> |
| <ul> |
| <li><a |
| href="http://www.eclipse.org/webtools/jst/components/ws/1.0/tutorials/WebServiceExplorer/WebServiceExplorer.html">Using |
| Web Service Explorer to test a Web service</a></li> |
| <li><a |
| href="http://www.eclipse.org/webtools/jst/components/ws/1.5/tutorials/BottomUpWebService/BottomUpWebService.html">Creating |
| Bottom Up Web Service via Axis</a></li> |
| <li><a |
| href="http://www.eclipse.org/webtools/jst/components/ws/1.5/tutorials/TopDownWebService/TopDownWebService.html">Creating |
| Top Down Web Service via Axis</a></li> |
| <li><a |
| href="http://www.eclipse.org/webtools/jst/components/ws/1.5/tutorials/WebServiceClient/WebServiceClient.html">Consuming |
| Web service using Web Service Client via Axis</a></li> |
| </ul> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </body> |
| </html> |