Versions Compared

Key

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

...

  • 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
titleModified result.jsp
borderStylesolid
........
<%@ 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
titleConverter

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.

  • 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
titleConverterClient.java
borderStylesolid

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
    titleVersion Numbers

    The version numbers may differ slightly. It wont matter much.

  • Repeat the above step for the following external JARS
Panel
borderColor#ccc
bgColor#FFFFCE
titleBGColor#F7D6C1
titleExternal JARS Required(Axis2)
borderStylesolid

axis2-adb-1.3.jar - <GERONIMO_INSTALL_DIR>/repository/org/apache/axis2/axis2-adb/1.3/axis2-adb-1.3.jar
axis2-java2wsdl-1.3.jar - <GERONIMO_INSTALL_DIR>\repository\org\apache\axis2\axis2-java2wsdl\1.3\axis2-java2wsdl-1.3.jar
axis2-jaxws-1.3.jar - <GERONIMO_INSTALL_DIR>\repository\org\apache\axis2\axis2-jaxws\1.3\axis2-jaxws-1.3.jar
axis2-kernel-1.3.jar - <GERONIMO_INSTALL_DIR>\repository\org\apache\axis2\axis2-kernel\1.3\axis2-kernel-1.3.jar
axis2-metadata-1.3.jar - <GERONIMO_INSTALL_DIR>\repository\org\apache\axis2\axis2-metadata\1.3\axis2-metadata-1.3.jar
axis2-saaj-1.3.jar - <GERONIMO_INSTALL_DIR>\repository\org\apache\axis2\axis2-saaj\1.3\axis2-saaj-1.3.jar
axiom-api-1.2.5.jar - <GERONIMO_INSTALL_DIR>\repository\org\apache\ws\commons\axiom\axiom-api\1.2.5\axiom-api-1.2.5.jar
axiom-dom-1.2.5.jar - <GERONIMO_INSTALL_DIR>\repository\org\apache\ws\commons\axiom\axiom-dom\1.2.5\axiom-dom-1.2.5.jar
axiom-impl-1.2.5.jar - <GERONIMO_INSTALL_DIR>\repository\org\apache\ws\commons\axiom\axiom-impl\1.2.5\axiom-impl-1.2.5.jar
XmlSchema-1.3.1.jar - <GERONIMO_INSTALL_DIR>\repository\org\apache\ws\commons\schema\XmlSchema\1.3.1\XmlSchema-1.3.1.jar
neethi-2.0.jar - <GERONIMO_INSTALL_DIR>\repository\org\apache\neethi\neethi\2.0\neethi-2.0.jar
wsdl4j-1.6.1.jar - <GERONIMO_INSTALL_DIR>\repository\wsdl4j\wsdl4j\1.6.1\wsdl4j-1.6.1.jar
xml-resolver-1.1.jar - <GERONIMO_INSTALL_DIR>\repository\xml-resolver\xml-resolver\1.1\xml-resolver-1.1.jar
xmlxmlbeans-beans-2.3.0.jar - <GERONIMO_INSTALL_DIR>\repository\org\apache\xmlbeans\xmlbeans\2.3.0\xmlbeans-2.3.0.jar
commons-codec-1.3.jar - <GERONIMO_INSTALL_DIR>\repository\commons-codec\commons-codec\1.3\commons-codec-1.3.jar
commons-httpclient-3.0.1.jar - <GERONIMO_INSTALL_DIR>\repository\commons-httpclient\commons-httpclient\3.0.1\commons-httpclient-3.0.1.jar
wstx-asl-3.2.1.jar - <GERONIMO_INSTALL_DIR>\repository\woodstox\wstx-asl\3.2.1\wstx-asl-3.2.1.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.

...