Versions Compared

Key

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

...

  • In Project Explorer view, expand jaxws-converter project, right click on Java Resources: src and select New->Package

  • Specify org.apache.geronimo.samples.jaxws as the package name and click Finish

  • Right click on the new package and select New->Interface
  • Name the interface as Converter and click Finish

  • 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);
    }
    


  • In Project Explorer view, right click on the new package and select New->Class

  • Name the class as ConverterService, add org.apache.geronimo.samples.jaxws.Converter as Interface and click Finish

  • 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 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 specified the user defined class name for of 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 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 don't use this annotation all the public methods will be exposed as WebService.
  • @WebParam - This 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.

...