Versions Compared

Key

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

...

This tutorial will take you through the following steps:

Table of Contents
maxLevel2
typelist
separatorpipe

Web based Client

The following steps will help you in creating a Web based Client for a JAX-WS Web Service which is already deployed on the server.

...

Info
titleConverter

Note that we accessed the webservice in the jsp by creating a service, and then retrieving the Converter port from the WSDL document.

POJO Client

Here we will have a look on how to create a plain old java client for consuming the web service.

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

}


This completes the development section of our POJO client

Adding necessary jar files to the class path

Note
titleErrors in Java Project

Now our Java project might show many errors and even if we resolve the errors the application may not run properly. This is due to the missing jar files required to access and understand SOAP messages sent by web service.

  • Right click the jaxws-converterpojoclient project and then select Properties

  • Select Java Build Path and then go to Libraries tab

  • Click on Add External JARS 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
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
xml-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 which reduces the effort for adding some more jars.

This completes the adding external JARs to the project

Tip
titleJRE 6

If you are running Java 6 you don't need to worry about the external JARs as they are all inbuilt into JRE 6. But you should copy all the files generated by wsimport command into appropriate packages as Runtime Modeller in Java 6 is slightly different.

Testing

  1. Now Right click the ConverterClient.class and select Run As->Run as Java Application

  2. Now enter the amount in the console window of Eclipse
  3. The output will be shown which is retrieved by accessing the methods of Web service.

This completes the development and deployment of clients for consuming a Web Service. Even though this tutorial demonstrated for one particular Web Service, the method can be extended for any deployed web service.