Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Creating a bottom-up Axis2 Web service"

(Update the wiki to show Axis2 1.3 changes in tutorial)
 
(7 intermediate revisions by 2 users not shown)
Line 12: Line 12:
 
|-
 
|-
 
| valign="top" |
 
| valign="top" |
<br /> This tutorial is meant to demonstrate the use of the newly introduced ''' Axis2''' Web Services tools in the Web Tools Platform Project using the ''' WTP 2.0''' drivers. If you are using Axis2 1.4 or later version please use ''' WTP 3.0 RC2''' 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.<br />
+
<br /> This tutorial is meant to demonstrate the use of the newly introduced ''' Axis2''' Web Services tools in the Web Tools Platform Project using the ''' WTP 2.0''' drivers. If you are using Axis2 1.4 or later version please use ''' WTP 3.0''' 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.<br />
 
|-
 
|-
 
| colspan="2" bgcolor="#0080c0" align="left" valign="top" | ''' <font color="#ffffff" face="Arial,Helvetica">Set Up</font>'''
 
| colspan="2" bgcolor="#0080c0" align="left" valign="top" | ''' <font color="#ffffff" face="Arial,Helvetica">Set Up</font>'''
Line 24: Line 24:
 
|-
 
|-
 
| valign="top" |
 
| valign="top" |
This tutorial need a Axis2 runtime. You can download the latest axis2 binary distribution from [http://ws.apache.org/axis2/download.cgi here]. <br />'''Note :''' Currently Axis2 version 1.2 and 1.3 are the supported versions for the Web Services Scenarios
+
This tutorial need a Axis2 runtime. You can download the latest axis2 binary distribution from [http://ws.apache.org/axis2/download.cgi here]. <br />'''Note :''' Currently Axis2 version 1.2 and 1.3 are the supported versions for the Web Services Scenarios using WTP 2.0.  Axis2 version 1.4 is also supported for WTP 3.0.
 
# Download the latest Axis2 runtime from the above link and extract it.
 
# Download the latest Axis2 runtime from the above link and extract it.
# Now we point Eclipse WTP to downloaded Axis2 Runtime. Open '''Window -> Preferences -> Web Services -> Axis2 Emitter'''<br />[[Image:Ws_buAxis2SetAxis2Pref.jpg|alt]]<br />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.
+
# Now we point Eclipse WTP to downloaded Axis2 Runtime. Open '''Window -> Preferences -> Web Services -> Axis2 Preferences'''<br /><br />[[Image:Ws_buAxis2SetAxis2Pref.jpg|alt]]<br />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.
 
# Click OK. <br /><br />
 
# Click OK. <br /><br />
# Next we need to create a project with the support of Axis2 features. Open '''File -> New -> Other... -> Web -> Dynamic Web Project'''<br />[[Image:Ws_buAxis2CreateDWP.jpg|alt]]<br />Click next
+
# Next we need to create a project with the support of Axis2 features. Open '''File -> New -> Other... -> Web -> Dynamic Web Project'''<br /><br />[[Image:Ws_buAxis2CreateDWP.jpg|alt]]<br />Click next
# Select the name '''Axis2WSTest''' as the Dynamic Web project name (you can specify any name you prefer), and select the configured Tomcat runtime as the target runtime. <br />[[Image:Ws_buAxis2CreateDWPnext.jpg|alt]]<br />Click next.
+
# Select the name '''Axis2WSTest''' as the Dynamic Web project name (you can specify any name you prefer), and select the configured Tomcat runtime as the target runtime. <br /><br />[[Image:Ws_buAxis2CreateDWPnext.jpg|alt]]<br /><br />For WTP 3.0 or later<br />[[Image:Ws_buAxis2CreateDWPnext_wtp_2.0.png]]<br />If you are using WTP 2.0 click Next to setup axis2 project facet or if you are using WTP 3.0 or later click Modify button in the configuration to setup axis2 project facet.
# Select the Axis2 Web service facet <br />[[Image:Ws_buAxis2CreateDWPfacets.jpg|alt]]<br />Click Finish.
+
# For WTP 2.0 select the Axis2 Project Facet<br /><br />[[Image:Ws_buAxis2CreateDWPfacets.jpg]]<br />Click Finish. <br /> For WTP 3.0 or later select the Axis2 Project Facet<br />[[Image:Ws_buAxis2CreateDWPfacets_wtp_3.0.png]]<br />Click Ok and then click Finish.
# This will create a dynamic Web project in the workbench <br />[[Image:Ws_buAxis2DWPcreated.png|alt]]<br /><br /><br />
+
# This will create a dynamic Web project in the workbench <br /><br />[[Image:Ws_buAxis2DWPcreated.png|alt]]<br /><br /><br />
# Import the [http://www.eclipse.org/webtools/community/tutorials/BottomUpAxis2WebService/code/Converter.java  wtp/Converter.java] class into Axis2WSTest/src (be sure to preserve the package). <br />[[Image:Ws_buAxis2ClassImported.png|alt]]<br />Build the Project, if its not auto build.
+
# Import the [http://www.eclipse.org/webtools/community/tutorials/BottomUpAxis2WebService/code/Converter.java  wtp/Converter.java] class into Axis2WSTest/src (be sure to preserve the package). <br /><br />[[Image:Ws_buAxis2ClassImported.png|alt]]<br />Build the Project, if its not auto build.
# Select Converter.java, open File -> New -> Other... -> Web Services -> Web Service <br />[[Image:Ws_buAxis2newWebService.png|alt]]<br />Click next.
+
# Select Converter.java, open File -> New -> Other... -> Web Services -> Web Service <br /><br />[[Image:Ws_buAxis2newWebService.png|alt]]<br />Click next.
# The Web service wizard would be brought up with Web service type set to '''Bottom up Java bean Web Service''' with the service implementation automatically filled in. Move the service scale to '''Start service'''. <br />[[Image:Ws_buAxis2WebServiceWizard.png|alt]]<br />
+
# The Web service wizard would be brought up with Web service type set to '''Bottom up Java bean Web Service''' with the service implementation automatically filled in. Move the service scale to '''Start service'''. <br /><br />[[Image:Ws_buAxis2WebServiceWizard.png|alt]]<br />
# Click on the '''Web Service runtime''' link to select the Axis2 runtime. <br />[[Image:Ws_buAxis2setAxis2runtime.png|alt]]<br />Click OK.
+
# Click on the '''Web Service runtime''' link to select the Axis2 runtime. <br /><br />[[Image:Ws_buAxis2setAxis2runtime.png|alt]]<br />Click OK.
# Ensure that the correct server and service project are selected as displayed below. <br />[[Image:Ws_buAxis2WizardEnsure.png|alt]]<br />Click next.
+
# Ensure that the correct server and service project are selected as displayed below. <br /><br />[[Image:Ws_buAxis2WizardEnsure.png|alt]]<br />Click next.
# This page is the service.xml selection page. if you have a custom services.xml, you can include that by clicking the '''Browse''' button. For the moment, just leave it at the default. <br />[[Image:Ws_buAxis2WizardNext.png|alt]]<br />Click next.
+
# This page is the service.xml selection page. if you have a custom services.xml, you can include that by clicking the '''Browse''' button. For the moment, just leave it at the default. <br /><br />[[Image:Ws_buAxis2WizardNext.png|alt]]<br />Click next.
# This page is the Start Server page. It will be displayed if the server has not been started. Click on the '''Start Server''' button. This will start the server runtime. <br />[[Image:Ws_buAxis2startServer.png|alt]]<br />Click next.
+
# This page is the Start Server page. It will be displayed if the server has not been started. Click on the '''Start Server''' button. This will start the server runtime. <br /><br />[[Image:Ws_buAxis2startServer.png|alt]]<br />Click next.
# This page is the Web services publication page, accept the defaults. <br />[[Image:Ws_buAxis2WizardFinish.png|alt]]<br />Click Finish.<br /><br />
+
# This page is the Web services publication page, accept the defaults. <br /><br />[[Image:Ws_buAxis2WizardFinish.png|alt]]<br />Click Finish.<br /><br />
# Now, select the '''Axis2WSTest''' dynamic Web project, right-click and select Run -> Run As -> Run on Server to bring up the Axis2 servlet. <br />[[Image:Ws_buAxis2StartOnServer.png|alt]]<br />Click Next.
+
# Now, select the '''Axis2WSTest''' dynamic Web project, right-click and select Run -> Run As -> Run on Server to bring up the Axis2 servlet. <br /><br />[[Image:Ws_buAxis2StartOnServer.png|alt]]<br />Click Next.
# Make sure you have the '''Axis2WSTest''' dynamic Web project on the right-hand side under the Configured project. <br />[[Image:Ws_buAxis2RunOnServer.png|alt]]<br />Click Finish.
+
# Make sure you have the '''Axis2WSTest''' dynamic Web project on the right-hand side under the Configured project. <br /><br />[[Image:Ws_buAxis2RunOnServer.png|alt]]<br />Click Finish.
# 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 />[[Image:Ws_buAxis2ServletPage.png|alt]]<br /><br /><br />
+
# 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 /><br />[[Image:Ws_buAxis2ServletPage.png|alt]]<br /><br /><br />
# Click on the '''Services''' link to view the available services. The newly created converter Web service will be shown there. <br />[[Image:Ws_buAxis2ServiceServletPage.png|alt]]<br /><br /><br />
+
# Click on the '''Services''' link to view the available services. The newly created converter Web service will be shown there. <br /><br />[[Image:Ws_buAxis2ServiceServletPage.png|alt]]<br /><br /><br />
# Click on the '''Converter Service''' link to display the ?wsdl URL of the newly created Web service. Copy the URL. <br />[[Image:Ws_buAxis2WsdlServletPage.png|alt]]<br /><br /><br />
+
# Click on the '''Converter Service''' link to display the ?wsdl URL of the newly created Web service. Copy the URL. <br /><br />[[Image:Ws_buAxis2WsdlServletPage.png|alt]]<br /><br /><br />
# 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 />[[Image:Ws_buAxis2NewClientWizard.png|alt]]<br /><br /><br />
+
# 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 /><br />[[Image:Ws_buAxis2NewClientWizard.png|alt]]<br /><br /><br />
# Paste the URL that was copied earlier into the service definition field. <br />[[Image:Ws_buAxis2ClientWizardFirstPage.png|alt]]<br />
+
# Paste the URL that was copied earlier into the service definition field. <br /><br />[[Image:Ws_buAxis2ClientWizardFirstPage.png|alt]]<br />
# Click on the '''Client project''' hyperlink and enter ''' Axis2WSTestClient''' as the name of the client project. Click OK. <br />[[Image:Ws_buAxis2ClientWizardProjectSetting.png|alt]]<br /><br />
+
# Click on the '''Client project''' hyperlink and enter ''' Axis2WSTestClient''' as the name of the client project. Click OK. <br /><br />[[Image:Ws_buAxis2ClientWizardProjectSetting.png|alt]]<br /><br />
# 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 />[[Image:Ws_buAxis2ClientWizardFirstPage.png|alt]]<br /><br /><br />
+
# 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 /><br />[[Image:Ws_buAxis2ClientWizardFirstPage.png|alt]]<br /><br /><br />
# Next page is the Client Configuration Page. Accept the defaults and click Finish. <br />[[Image:Ws_buAxis2ClientWizardConfigPage.png|alt]]<br /><br /><br />
+
# Next page is the Client Configuration Page. Accept the defaults and click Finish. <br /><br />[[Image:Ws_buAxis2ClientWizardConfigPage.png|alt]]<br /><br /><br />
# The Clients stubs will be generated to your Dynamic Web project ''' Axis2WSTestClient'''.  Following screen shot depicts the source files created when prior versions of axis2 1.3 is used.<br />[[Image:Ws_buAxis2ClientJavaStub.png|alt]]<br />axis2 ver. 1.3 or later screenshot< br />[[Image:Ws_buAxis2ClientJavaStub_1.3.png|alt]]<br /><br /><br />
+
# The Clients stubs will be generated to your Dynamic Web project ''' Axis2WSTestClient'''.  Following screen shot depicts the source files created when prior versions of axis2 1.2 is used.<br /><br />[[Image:Ws_buAxis2ClientJavaStub.png|alt]]<br />axis2 ver. 1.3 or later screenshot<br />[[Image:Ws_buAxis2ClientJavaStub_1.3.png|alt]]<br /><br /><br />
# Now we are going to write Java main program to invoke the client stub. Import the [http://www.eclipse.org/webtools/community/tutorials/BottomUpAxis2WebService/code/ConverterClient.java  ConverterClient.java] file (if you are using axis2 version 1.3 or later use [http://www.eclipse.org/webtools/community/tutorials/BottomUpAxis2WebService/code/ConverterClient.java.zip  ConverterClient.java.zip]) to the workspace into the wtp package in the src folder of '''Axis2WSTestClient'''. <br />[[Image:Ws_buAxis2TestClientJava.png|alt]]<br />Click to view axis2 ver. 1.3 or later screenshot<br />[[Image:Ws_buAxis2TestClientJava_1.3.png|alt]]<br /><br /><br />
+
# Now we are going to write Java main program to invoke the client stub. Import the [http://www.eclipse.org/webtools/community/tutorials/BottomUpAxis2WebService/code/ConverterClient.java  ConverterClient.java] file (if you are using axis2 version 1.3 or later use [http://wiki.eclipse.org/images/7/77/ConverterClient.java.zip  ConverterClient.java.zip]) to the workspace into the wtp package in the src folder of '''Axis2WSTestClient'''. <br /><br />[[Image:Ws_buAxis2TestClientJava.png|alt]]<br />Axis2 ver. 1.3 or later screenshot<br />[[Image:Ws_buAxis2TestClientJava_1.3.png|alt]]<br /><br /><br />
# Then select the ConverterClient file, right-click and select Run As -> Java Application. Here's what you get on the server console: <br />[[Image:Ws_buAxis2RunTestClientJava.png|alt]]<br />Click to view axis2 ver. 1.3 or later screenshot<br />[[Image:Ws_buAxis2RunTestClientJava_1.3.png|alt]]<br /><br /><br />
+
# Then select the ConverterClient file, right-click and select Run As -> Java Application. Here's what you get on the server console: <br /><br />[[Image:Ws_buAxis2RunTestClientJava.png|alt]]<br />Axis2 ver. 1.3 or later screenshot<br />[[Image:Ws_buAxis2RunTestClientJava_1.3.png|alt]]<br /><br /><br />
# Another way to test and invoke the service is to select '''Generate test case to test the service''' check box on the Axis2 Client Web Service Configuration Page when going through the Web Service Client wizard. <br />[[Image:Ws_buAxis2ChooseUnitTest.png|alt]]<br /><br />
+
# Another way to test and invoke the service is to select '''Generate test case to test the service''' check box on the Axis2 Client Web Service Configuration Page when going through the Web Service Client wizard. <br /><br />[[Image:Ws_buAxis2ChooseUnitTest.png|alt]]<br /><br />
# 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 ''' Axis2WSTestClient''' project called '''test'''. <br />[[Image:Ws_buAxis2UnitTestFile.png|alt]] <br />Axis2 ver. 1.3 or later screenshot<br />[[Image:Ws_buAxis2UnitTestFile_1.3.jpg|alt]]<br /><br />
+
# 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 ''' Axis2WSTestClient''' project called '''test'''. <br /><br />[[Image:Ws_buAxis2UnitTestFile.png|alt]] <br />Axis2 ver. 1.3 or later screenshot<br />[[Image:Ws_buAxis2UnitTestFile_1.3.jpg|alt]]<br /><br />
# 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 (or ConverterTest.java for axis2 ver. 1.3 or later) 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:  
+
# 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 (or ConverterTest.java for axis2 ver. 1.3 or later) 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:<source lang=java>testfarenheitToCelsius() -> farenheitToCelsius8.setFarenheit(212);</source><source lang=java>testStartfarenheitToCelsius() -> farenheitToCelsius8.setFarenheit(212);</source><source lang=java>testcelsiusToFarenheit() -> celsiusToFarenheit10.setCelsius(100);</source><source lang=java>testStartcelsiusToFarenheit() -> celsiusToFarenheit10.setCelsius(100);</source>Here the testcases were generated to test both the synchronous and asynchronous clients. <br />
testfarenheitToCelsius() -> farenheitToCelsius8.setFarenheit(212);
+
# 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 /><br />[[Image:Ws_buAxis2RunUnitTest.png|alt]]<br />Axis2 ver. 1.3 or later screenshot<br />[[Image:Ws_buAxis2RunUnitTest_1.3.jpg|alt]]<br /><br /><br />
+
testStartfarenheitToCelsius() -> farenheitToCelsius8.setFarenheit(212);
+
+
testcelsiusToFarenheit() -> celsiusToFarenheit10.setCelsius(100);
+
+
testStartcelsiusToFarenheit() -> celsiusToFarenheit10.setCelsius(100);
+
Here the testcases were generated to test both the synchronous and asynchronous clients. <br />
+
# 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 />[[Image:Ws_buAxis2RunUnitTest.png|alt]]<br />Axis2 ver. 1.3 or later screenshot<br />[[Image:Ws_buAxis2RunUnitTest_1.3.jpg|alt]]<br /><br /><br />
+
 
|-
 
|-
 
| colspan="2" bgcolor="#0080c0" align="left" valign="top" | ''' <font color="#ffffff" face="Arial,Helvetica">Summary</font>'''
 
| colspan="2" bgcolor="#0080c0" align="left" valign="top" | ''' <font color="#ffffff" face="Arial,Helvetica">Summary</font>'''
Line 81: Line 73:
 
* [http://www.eclipse.org/webtools/jst/components/ws/1.5/tutorials/TopDownWebService/TopDownWebService.html  Creating Top Down Web Service via Axis]
 
* [http://www.eclipse.org/webtools/jst/components/ws/1.5/tutorials/TopDownWebService/TopDownWebService.html  Creating Top Down Web Service via Axis]
 
* [http://www.eclipse.org/webtools/jst/components/ws/1.5/tutorials/WebServiceClient/WebServiceClient.html  Consuming Web service using Web Service Client via Axis]
 
* [http://www.eclipse.org/webtools/jst/components/ws/1.5/tutorials/WebServiceClient/WebServiceClient.html  Consuming Web service using Web Service Client via Axis]
 +
|-
 +
| colspan="2" bgcolor="#0080c0" align="left" valign="top" | ''' <font color="#ffffff" face="Arial,Helvetica"> Contributors </font> '''
 +
|-
 +
| valign="top" |
 +
* [mailto:sandakith@wso2.com Lahiru Sandakith], [http://www.wso2.org WSO2 Inc.]
 +
* [mailto:samindaw@wso2.com Saminda Wijeratne], [http://www.wso2.org WSO2 Inc.]
 
|}
 
|}

Latest revision as of 17:37, 12 September 2008

Eclipse WTP Tutorials - Creating Bottom Up Web Service via Apache Axis2

alt

By Lahiru Sandakith
WSO2 Inc.
June 29, 2007

Introduction


This tutorial is meant to demonstrate the use of the newly introduced Axis2 Web Services tools in the Web Tools Platform Project using the WTP 2.0 drivers. If you are using Axis2 1.4 or later version please use WTP 3.0 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.

Set Up

Before creating the Web service, there are two prerequisites:

  1. Download Eclipse WTP and unzip it.
  2. Configure Apache Tomcat inside Eclipse WTP.
Creating a bottom up JAVA bean Web service and Web service client using Axis2 WTP Tools

This tutorial need a Axis2 runtime. You can download the latest axis2 binary distribution from here.
Note : Currently Axis2 version 1.2 and 1.3 are the supported versions for the Web Services Scenarios using WTP 2.0. Axis2 version 1.4 is also supported for WTP 3.0.

  1. Download the latest Axis2 runtime from the above link and extract it.
  2. Now we point Eclipse WTP to downloaded Axis2 Runtime. Open Window -> Preferences -> Web Services -> Axis2 Preferences

    alt
    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.
  3. Click OK.

  4. Next we need to create a project with the support of Axis2 features. Open File -> New -> Other... -> Web -> Dynamic Web Project

    alt
    Click next
  5. Select the name Axis2WSTest as the Dynamic Web project name (you can specify any name you prefer), and select the configured Tomcat runtime as the target runtime.

    alt

    For WTP 3.0 or later
    Ws buAxis2CreateDWPnext wtp 2.0.png
    If you are using WTP 2.0 click Next to setup axis2 project facet or if you are using WTP 3.0 or later click Modify button in the configuration to setup axis2 project facet.
  6. For WTP 2.0 select the Axis2 Project Facet

    Ws buAxis2CreateDWPfacets.jpg
    Click Finish.
    For WTP 3.0 or later select the Axis2 Project Facet
    Ws buAxis2CreateDWPfacets wtp 3.0.png
    Click Ok and then click Finish.
  7. This will create a dynamic Web project in the workbench

    alt


  8. Import the wtp/Converter.java class into Axis2WSTest/src (be sure to preserve the package).

    alt
    Build the Project, if its not auto build.
  9. Select Converter.java, open File -> New -> Other... -> Web Services -> Web Service

    alt
    Click next.
  10. The Web service wizard would be brought up with Web service type set to Bottom up Java bean Web Service with the service implementation automatically filled in. Move the service scale to Start service.

    alt
  11. Click on the Web Service runtime link to select the Axis2 runtime.

    alt
    Click OK.
  12. Ensure that the correct server and service project are selected as displayed below.

    alt
    Click next.
  13. This page is the service.xml selection page. if you have a custom services.xml, you can include that by clicking the Browse button. For the moment, just leave it at the default.

    alt
    Click next.
  14. This page is the Start Server page. It will be displayed if the server has not been started. Click on the Start Server button. This will start the server runtime.

    alt
    Click next.
  15. This page is the Web services publication page, accept the defaults.

    alt
    Click Finish.

  16. Now, select the Axis2WSTest dynamic Web project, right-click and select Run -> Run As -> Run on Server to bring up the Axis2 servlet.

    alt
    Click Next.
  17. Make sure you have the Axis2WSTest dynamic Web project on the right-hand side under the Configured project.

    alt
    Click Finish.
  18. 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.

    alt


  19. Click on the Services link to view the available services. The newly created converter Web service will be shown there.

    alt


  20. Click on the Converter Service link to display the ?wsdl URL of the newly created Web service. Copy the URL.

    alt


  21. 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

    alt


  22. Paste the URL that was copied earlier into the service definition field.

    alt
  23. Click on the Client project hyperlink and enter Axis2WSTestClient as the name of the client project. Click OK.

    alt

  24. 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.

    alt


  25. Next page is the Client Configuration Page. Accept the defaults and click Finish.

    alt


  26. The Clients stubs will be generated to your Dynamic Web project Axis2WSTestClient. Following screen shot depicts the source files created when prior versions of axis2 1.2 is used.

    alt
    axis2 ver. 1.3 or later screenshot
    alt


  27. Now we are going to write Java main program to invoke the client stub. Import the ConverterClient.java file (if you are using axis2 version 1.3 or later use ConverterClient.java.zip) to the workspace into the wtp package in the src folder of Axis2WSTestClient.

    alt
    Axis2 ver. 1.3 or later screenshot
    alt


  28. Then select the ConverterClient file, right-click and select Run As -> Java Application. Here's what you get on the server console:

    alt
    Axis2 ver. 1.3 or later screenshot
    alt


  29. Another way to test and invoke the service is to select Generate test case to test the service check box on the Axis2 Client Web Service Configuration Page when going through the Web Service Client wizard.

    alt

  30. 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 Axis2WSTestClient project called test.

    alt
    Axis2 ver. 1.3 or later screenshot
    alt

  31. 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 (or ConverterTest.java for axis2 ver. 1.3 or later) 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:
    testfarenheitToCelsius() -> farenheitToCelsius8.setFarenheit(212);
    testStartfarenheitToCelsius() -> farenheitToCelsius8.setFarenheit(212);
    testcelsiusToFarenheit() -> celsiusToFarenheit10.setCelsius(100);
    testStartcelsiusToFarenheit() -> celsiusToFarenheit10.setCelsius(100);
    Here the testcases were generated to test both the synchronous and asynchronous clients.
  32. 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.

    alt
    Axis2 ver. 1.3 or later screenshot
    alt


Summary

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:
alt

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:

  • You can choose Web Services -> Test with Web Services Explorer to test the service.
  • You can choose Web Services -> Publish WSDL file to publish the service to a public UDDI registry.
Resources

You can also refer to the Axis Web services tutorials:

Contributors

Back to the top