...
- Let us walkthrough the elements that we added to web.xml
- service-ref-name - This is the name by which JNDI identifies our deployed service. The location that these services are located are java:comp/env/<service-ref-name>
- service-interface - This is the interface which client uses to access the web service and create necessary stubs under covers. This interface should compulsorily extend either javax.xml.ws.Service or javax.xml.rpc.Service. Observer that this is not the Service-Endpoint Interface that we used to deploy the service.
- wsdl-file - The location of WSDL file specified the location of deployed web service. Suppose the web service is deployed at *http://localhost:8080/jaxws-converter/converter*, then the WSDL file is located at *http://localhost:8080/jaxws-converter/converter?wsdl*
- The changes required in accessing the service are as follows:
Code Block | ||||
---|---|---|---|---|
| ||||
........ <%@ page import="javax.naming.InitialContext" %> ........ Context ctx= new InitialContext(); Object obj = ctx.lookup("java:comp/env/services/Converter"); Converter service= (Converter) obj; ConverterPortType port = service.getConverterPort(); BigDecimal rupees =port.dollarToRupees(dollars); BigDecimal euros = conv.rupeesToEuro(rupees); ........ |
Deploying and Testing the Web Client
...
- Right click on the Apache Geronimo Server Runtime present in the servers view and select Add and Remove Projects
- Add jaxws-converterclient to configured projects list and then click Finish
- Wait for some time till the server status changes to Synchronized
Info Note that you may get some error and/or warning messages in the server console tab. These usually can be ignored as long as the projects deploy correctly, which they should.
Testing
- Right click the index.jsp present under WebContent directory of our project and select Run As --> Run On Server
- In the popup, check the check box Always use this server when running the project and then click Finish
- Now Eclipse will try to open the jsp JSP in a web browser which shows you a form to enter amount in Dollars.
- Enter any amount and press submit, the jsp should display the result that is returned by the web service.
Info | ||
---|---|---|
| ||
Note that we accessed the webservice web service in the jsp JSP by creating a service, and then retrieving the Converter port from the WSDL document. |
...
Developing the Client
- Create a Java Project
- Select File --> New --> Project
- In the popup window select Java --> Java Project and then click Next
- Name the project as jaxws-converterpojoclient and click Finish in the New Java Project dialog.
- Select File --> New --> Project
- Copy the files Converter.java and ConverterPortType.java into the appropriate package.
- Add another class with the name ConverterClient.java in the same package.
- Add the following code to the ConverterClient.java
Code Block | ||||
---|---|---|---|---|
| ||||
package org.apache.geronimo.samples.jaxws; import java.io.BufferedReader; import java.io.InputStreamReader; import java.math.BigDecimal; public class ConverterClient { public static void main(String args[]) { try { BufferedReader dataIn = new BufferedReader(new InputStreamReader( System.in)); System.out.println("enter a amount to convert:"); String number = new String(); number = dataIn.readLine(); BigDecimal amount = new BigDecimal(number); Converter conv = new Converter(); ConverterPortType port = conv.getConverterPort(); BigDecimal result = port.dollarToRupees(amount); System.out.println(amount + " dollars equals to " + result + " rupees"); BigDecimal result1 = port.rupeesToEuro(result); System.out.println(result + " rupees equals to " + result1 + " euros"); } catch (Exception e) { e.printStackTrace(); } } } |
...
- Right click the jaxws-converterpojoclient project and then select Properties
- Select Java Build Path and then go to Libraries tab
- Click on Add External JARSJARs... and then add the axis2-adb-1.3.jar from the location <GERONIMO_INSTALL_DIR>/repository/org/apache/axis2/axis2-adb/1.3/ and then click Open
Info title Version Numbers The version numbers may differ slightly. It wont matter much.
- Repeat the above step for the following external JARS
Panel | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
axis2-adb-1.3.jar - <GERONIMO_INSTALL_DIR>/repository/org/apache/axis2/axis2-adb/1.3/axis2-adb-1.3.jar Also add Server Runtime Library to class path (i.e., via clicking on Add Library...) which reduces the effort for adding some more jars. Note that these jars are used when JAX-WS Engine is configured as Axis2. If JAX-WS engine is configured as CXF the jars may differ slightly. |
...