Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Details on installing eclipse are provided in the Development environment section.

This tutorial will take you through the following steps:

Table of Contents
maxLevel2
typelist
separatorpipe

...

Create a Dynamic Web Project to host the Web Service

  1. From Eclipse main menu, select Select File->New->Other
  2. In the popup window New dialog, Select select Web->Dynamic Web Project and click Next
  3. Type jaxws-converter as the Project Name and click Next
  4. On the Project Facets page, the default selections ( as shown below ) are enough as (Geronimo has axis2 web an embedded Axis2 container already running, ) and click Next
    Image Modified
  5. Make sure that the check box Generate Deployment Descriptor is selected and click Next
  6. On the Geronimo Deployment Page modify the Group Id to org.apache.geronimo.samples.jaxws and the artifact id Artifact Id to jaxws-converter.
  7. Click Finish

This completes the configuration of Eclipse for application development.

Creating the Web Services Implementation code

To deploy the Converter service we are going to create a POJO interface and a class and expose it as a servlet. The steps required are:

Create the POJO Interface & Class that implement the Web Service

  1. In Project Explorer view, expand jaxws-converter project, right click on Java Resources: src and select New->Package
  2. Name the package to Specify org.apache.geronimo.samples.jaxws as the package name and click Finish
  3. Right click on the new package and select New->Interface
  4. Name the interface as Converter and click Finish
  5. Add the following code to the Converter interface
Code Block
titleConverter.java
borderStylesolid

...


package org.apache.geronimo.samples.jaxws;

import java.math.BigDecimal;
import javax.jws.WebService;

@WebService(name="ConverterPortType",
        targetNamespace = "http://jaxws.samples.geronimo.apache.org")
public interface Converter {
	

...

public BigDecimal dollarToRupees(BigDecimal dollars);
	public BigDecimal rupeesToEuro(BigDecimal rupees);

...

}

...


  1. In Project Explorer view, right click on the new package and select New->Class
  2. Name the class as ConverterService, add org.apache.geronimo.samples.jaxws.Converter as Interface and click Finish
  3. Add the following code to the ConverterService class
Code Block
titleConverterService.java
borderStylesolid

...


package org.apache.geronimo.samples.jaxws;

import java.math.BigDecimal;

...


import javax.jws.WebService;

@WebService(serviceName = "Converter",
        portName="ConverterPort",
        endpointInterface = "org.apache.geronimo.samples.jaxws.Converter",
        targetNamespace = "http://jaxws.samples.geronimo.apache.org"
        )
public class ConverterService implements Converter {
	private BigDecimal rupeeRate = new BigDecimal("40.58");
	private BigDecimal euroRate = new BigDecimal("0.018368");

	public BigDecimal dollarToRupees(BigDecimal dollars) {
		BigDecimal result = dollars.multiply(rupeeRate);
		return result.setScale(2, BigDecimal.ROUND_UP);
	}

	public BigDecimal rupeesToEuro(BigDecimal rupees) {
		BigDecimal result = rupees.multiply(euroRate);
		return result.setScale(2, BigDecimal.ROUND_UP);
	}
}

...


Let us try to understand each annotation

  • @WebService- This annotation can be used with a Java class as well as with interface. In our case we used it with both interface as well as the POJO. This annotation declares the POJO as a WebService. @WebService annotation is utilized in generating the WSDL file.
    • serviceName is same as the WSDL element service
    • name is same as the WSDL element <portType name>
    • endpointInterface suggests the user defined name for the Service Endpoint Interface(SEI).
    • portName is the element portName
    • targetNamespace is the XML namespace of the WSDL and some of the XML elements generated from the WebService
  • @WebMethod- This annotation is applied to a method to expose it as a WebService method. In case you have multiple methods you can use this annotation to selectively expose methods as WebService method. If you donot use this annotation all the public methods will be exposed as WebService.
  • @WebParam- This annotation is used along with @WebMethod annotation to define the WebService. It is used to customize parameter used in the message part of the wsdl.

...

  • .

Setting Up the Deployment Descriptor and Deployment Plan

...

  1. Once the application is deployed on to the server, Launch a browser and go to the following url.
    http://localhost:8080/jaxws-converter/converter
  2. Now you should see the screen telling that this is Converter Web Service





    Info
    titleWSDL File

    You can also view the WSDL file generated by Geronimo based on the annotations specified by going to the following url
    http://localhost:8080/jaxws-converter/converter?wsdl

Using Web Services Explorer in Eclipse

  1. Go to Eclipse and select Run->Launch the Web Services Explorer from the main menu.
  2. Web Services Explorer opens up as shown below:





  3. On the top right corner of this explorer, click on the icon for "WSDL Page". Under Navigation section, you will now see WSDL Main. Click that WSDL Main link to enter the URL of WSDL document.





  4. Enter the URL of our WSDL document i.e http://localhost:8080/jaxws-converter/converter?wsdl in the form and click Go. Now you can see the methods that are exposed by our Web Service.





  5. Clicking on any method takes us to a page with form asking for input parameters.If you dont see any field to enter input arguments click Add.





  6. Enter any argument and examine the status frame at the bottom to see the result.





...