Versions Compared

Key

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

...

  1. From Eclipse main menu, select File->New->Other
  2. In the New dialog, 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 (Geronimo has an embedded Axis2 container already running) and click Next
  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 to jaxws-converter.
  7. Click Finish

Add the POJO Interface

...

and 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. 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);
    }
    
  6. In Project Explorer view, right click on the new package and select New->Class
  7. Name the class as ConverterService, add org.apache.geronimo.samples.jaxws.Converter as Interface and click Finish
  8. 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);
    	}
    }
    

...

Code Block
xml
xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5">
	<display-name>jaxws-converter</display-name>
	<servlet>
		<display-name>Converter</display-name>
		<servlet-name>Converter</servlet-name>
		<servlet-class>
			org.apache.geronimo.samples.jaxws.ConverterService
		</servlet-class>
	</servlet>

	<servlet-mapping>
		<servlet-name>Converter</servlet-name>
		<url-pattern>/converter</url-pattern>
	</servlet-mapping>

</web-app>

Deploy the Web Service and let Geronimo create the required

...

WSDL and other artifacts

  1. In Servers view, right click on Apache Geronimo Server Runtime and select Add and Remove Projects
  2. In the popup dialog, select jaxws-converter project, click Add, and then click Finish
    The Web Service will now be deployed, and Geronimo will create the required .wsdl and other required artifacts.
  3. Once the Web Service is deployed on to the server (Server Status says Synchronized), launch a browser and go to the following url:
    http://localhost:8080/jaxws-converter/converter
    You should see a message from Axis2 engine as below:
  4. You can also view the WSDL file generated by Geronimo by going to the following url:
    http://localhost:8080/jaxws-converter/converter?wsdl

...

Tip
titleHow Geronimo creates the WSDL and other required files?

Geronimo has an in-built plug-in by name jaxws-builder which helps in creating the WSDL and other required files to deploy the web service by using the jaxws-tools provided by Sun

Try looking into source of jaxws-builder to better understand how the necessary files are getting created.

Test the Web Service using Eclipse

...

Web Services Explorer

  1. From Eclipse's main menu, click Run->Launch the Web Services Explorer
  2. Web Services Explorer will open up as shown below:
  3. On the top right corner of this explorer, click on the icon for "WSDL Page". Under Navigation frame, you will now see WSDL Main (instead of UDDI Main). Click that WSDL Main link and the Actions frame would show a form as below:
  4. Enter the URL of your 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 your Web Service.
  5. Clicking on any method would take you to a form asking for input parameters. If you don't see any field to enter input arguments click Add.
  6. Enter the input arguments and click Go. You can see the output of the Web Service in the Status frame at the bottom.

...