...
- In Project Explorer view, expand jaxws-converter project, right click on Java Resources: src and select New->Package
- Name the package to org.apache.geronimo.samples.jaxws 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 class interface
Code Block title Converter.java borderStyle solid 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 title ConverterService.java borderStyle solid 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); } }
...
- Expand WEB-INF directory and add the following code to web.xml
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>Converter<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>
...
Now, we will look into the steps involved in deploying and testing our web service without any clients.
Deploy
- Right In Servers view, right click on the Apache Geronimo Server Runtime present in the servers view and select Add or and Remove Projects
- In the popup dialog, select the jaxws-converter project and , click Add
Make sure that jaxws-converter is in the configured projects list and then click Finish
- Wait for some time till the server status is changed to synchronized.
...
Using Web Services Explorer in Eclipse
- Go to Eclipse and select Run->Launch the Web Services Explorer from the main menu.
- Web Services Explorer opens up as shown below:
- 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 Click the WSDL icon to go to the WSDL main page.
Click the WSDL main link to enter the URL of WSDL document.
- 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.
- 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.
- Enter any argument and examine the status frame at the bottom to see the result.
...