axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject cvs commit: xml-axis-wsif/java/samples/dslprovider README.html
Date Fri, 27 Dec 2002 22:12:09 GMT
nmukhi      2002/12/27 14:12:09

  Modified:    java/doc samples.html
  Added:       java/samples/dslprovider README.html
  Added new sample: application that ties some smaller samples together
  Revision  Changes    Path
  1.6       +5 -0      xml-axis-wsif/java/doc/samples.html
  Index: samples.html
  RCS file: /home/cvs/xml-axis-wsif/java/doc/samples.html,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- samples.html	12 Dec 2002 14:41:01 -0000	1.5
  +++ samples.html	27 Dec 2002 22:12:09 -0000	1.6
  @@ -89,6 +89,11 @@
      <td>The samples/customfactory directory under your WSIF installation</td>
      <td><a href="../samples/customfactory/README.html">The Sample README</a></td>
  +   <td>A sample application that builds on the EJB, JMS and complexsoap samples</td>
  +   <td>The samples/dslprovider directory under your WSIF installation</td>
  +   <td><a href="../samples/dslprovider/README.html">The Sample README</a></td>
   <hr width="100%">
  1.1                  xml-axis-wsif/java/samples/dslprovider/README.html
  Index: README.html
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="Author" content="Nirmal Mukhi">
  <meta http-equiv="Content-Style-Type" content="text/css">
  <title>Web Services Invocation Framework: Samples</title>
  <link rel="stylesheet" href="wsif.css" type="text/css"></head>
    <body alink="#0000ff" bgcolor="#ffffff" leftmargin="2" topmargin="2" marginwidth="2"
        Web Services Invocation Framework:<br>
        DSL Provider Sample Application</h1>
      <p>This is a sample application that shows how WSIF lets you write flexible applications
through its WSDL-driven, protocol-independent APIs.</p>
      <p>The application lets users enter their names and addresses and then tells them
whether DSL service is available in their area or not. It stores addresses once entered, so
returning users need not reenter that information. It also verifies the validity of addresses.</p>
      <p>The application uses three separate pieces of software to do its job:
        <li>An address book service: this is capable of storing addresses and allowing
        <li>A zip code service: this is capable of looking up information pertaining
to a particular zip code, and can be used to verify addresses</li>
        <li>An availability service : this checks if DSL service is available at a particular
zip code</li>
      <p>These three pieces of software are modeled as WSDL-described services. Once
we do this, we can then access their functionality using the WSIF API, giving us a consistent
view of the functionality being used, and allowing dynamic protocol switching and other WSIF
benefits. Our application is programmed against the following abstract service definitions:
  	<li>The address book service is described in the <a href="../ejb/AddressBook.wsdl">AddressBook.wsdl</a>
file in the <tt>samples/ejb</tt></p> directory</li>
  	<li>The zip code service is described in the <a href="../complexsoap/Zip2Geo.wsdl">Zip2Geo.wsdl</a>
file in the <tt>samples/complexsoap</tt></p> directory</li>
  	<li>The availability service is described in the <a href="../jms/ServiceAvailability.wsdl">Serviceavailability.wsdl</a>
file in the <tt>samples/jms</tt></p> directory</li>
      <p><a href="">Here</a> is the code for our application.
It takes as command line arguments the locations of the WSDL files for the three services.
Note that we can provide <em>absolutely any</em> WSDL files as long as the abstract
definitions match the ones we programed against. In particular, we can define new bindings,
move the service endpoints - for example, to a different application server - change client
libraries, etc. <em>without affecting the application code in any way</em>.</p>
      <img src="applicationview.jpg">
      <p>Above we show the application's view of the services it uses, along with a
different view that shows what could really be behind the WSDL service.</p>
      <h2>Running the application</h2>
      <p><b>It is advisable to try running this application after going through
the simplesoap, complexsoap, ejb and jms samples.</b></p>
      <p>The simplest way to run this application is to use the provided WSDL files.
First, you need to make sure all your services are deployed and available.</p>
      <p>The addressbook WSDL describes an EJB binding. To deploy the address book service
as an EJB, follow the instructions provided <a href="../ejb/README.html">in the EJB
sample</a>. Test that your EJB works using the client provided with that sample.</p>
      <p>The zip code WSDL describes a SOAP binding. Fortunately this is an external,
publicly available web service. To verify that the server is up and the service is running,
try out one of the clients in the <a href="../complexsoap/README.html">complexsoap sample</a>.</p>
      <p>The availability WSDL describes a JMS binding. To deploy the availability service
so that it is accessible via JMS, follow the instructions provided <a href="../jms/README.html">in
the JMS sample</a>. Test that your JMS service works using the client provided with
that sample.</p>
      <p>Once you have all the pieces deployed and you have verified that they work,
you can then run this application. You can use the command
        <br><tt>java dslprovider.ServiceChecker samples/complexsoap/Zip2Geo.wsdl

  	<br>samples/ejb/AddressBook.wsdl samples/jms/ServiceAvailability.wsdl</tt>
  <hr width="100%">
  1.1                  xml-axis-wsif/java/samples/dslprovider/
  package dslprovider;
   * This is a toy application that demonstrates how WSIF can be used to create flexible 
   * applications.
   * This ServiceChecker application allows users to enter their names and addresses
   * through a command line interface and then checks if DSL service is available in
   * the user's area. If the user has previously registered their addresses, they need not
   * enter them again. The application also verifies that addresses are correct.
   * The application makes use of three WSDL-described services:
   * 1. Zip2Geo: this service provides information about a US zip code, such as the
   * corresponding city and state
   * 2. AddressBook: this service allows names and addresses to be stored and 
   * looked up 
   * 3. ServiceAvailability: this service checks if DSL service is available at a 
   * particular zip code
   * The locations of the WSDL documents corresponding to these services are provided at 
   * runtime as command line arguments.
   * The key feature of this application is that since it is completely WSDL driven, 
   * we can swap the service protocols, change their location, add new protocols and
   * make them available dynamically, etc. without having to touch the application code 
   * here.
   * @author Nirmal Mukhi (
  // types for address book service
  import ejb.service.addressbook.wsifservice.AddressBook;
  import ejb.service.addressbook.wsiftypes.Address;
  // types for Zip2Geo service
  // types for service availability service
  // wsif classes
  import org.apache.wsif.WSIFException;
  import org.apache.wsif.WSIFService;
  import org.apache.wsif.WSIFServiceFactory;
  import javax.xml.namespace.QName;
  // java IO classes
  public class ServiceChecker {
      static AddressBook addressBook;
      static Zip2GeoSoap zip2geo;
      static CheckAvailabilityPortType serviceAvailability;
      public static void printError(String message) {
      public static void printUsage() {
  	System.out.println("java dslprovider.ServiceChecker <zip2geo service WSDL>"+
  			   "<addressbook service WSDL> <serviceAvailability service WSDL>");
      private static void init(String zip2geoWSDL,
  			     String addressbookWSDL,
  			     String serviceAvailabilityWSDL) throws Exception {
  	// create a service factory
  	WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
  	// initialize the address book stub
  	// parse the WSDL
  	WSIFService service =
  	// create the stub
  	addressBook = (AddressBook) service.getStub(AddressBook.class);
  	// initialize the zip2geo stub
  	// parse the WSDL
  	service = factory.getService(zip2geoWSDL,null,null,"",
  	// map types
  	service.mapType(new QName("", "LatLongReturn"),
  	// create the stub
  	zip2geo = (Zip2GeoSoap) service.getStub(Zip2GeoSoap.class);
  	// initialize the service availability stub
  	// parse the WSDL
  	service = factory.getService(serviceAvailabilityWSDL,null,null,
  	// create the stub
  	serviceAvailability = 
  	    (CheckAvailabilityPortType) service.getStub(CheckAvailabilityPortType.class);
      private static Address lookupAddress(String name) throws Exception { 
  	// lookup and return the address for that name
  	return addressBook.getAddressFromName(name);
      private static Address createAndAddAddress(String name,String streetNum, String streetName,
  				String city, String state, String zip) throws Exception { 
  	// create an address
  	Address address = new Address();
  	address.setStreetNum(new Integer(streetNum).intValue());
  	address.setZip(new Integer(zip).intValue());
  	// add an entry to the addressbook
  	return address;
      private static void verifyAddress(Address address) throws Exception { 
  	// extract the zip code from the address
  	String zipCode = ""+address.getZip();
  	// look up information for that zip
  	LatLongReturn zipInfo = zip2geo.GetLatLong(zipCode,"");
  	if (!zipInfo.getCity().equals(address.getCity())) {
  	    printError("Zip "+zipCode+" is in city "+zipInfo.getCity()+
  		       ", not city "+address.getCity()+" as you specified");
  	if (!zipInfo.getStateAbbrev().equals(address.getState())) {
  	    printError("Zip "+zipCode+" is in state "+zipInfo.getStateAbbrev()+
  		       ", not state "+address.getState()+" as you specified");
      private static String serviceIsAvailable(int zipCode) throws Exception { 
  	return serviceAvailability.checkAvailability(""+zipCode);
      private static void loopInput() {
  	try {
  	    System.out.println("WELCOME TO FAST DSL INC.");
  	    System.out.println("\n\nInterested in DSL service? Enter your address "+
  			       "in the form below and we will check whether we have "+
  			       "service available in your area.");
  	    System.out.println("If you have previously expressed interest, just enter "+
  			       "your name (leave other fields blank) and we will look "+
  			       "up the rest of the information "+
  			       "in our records");
  	    LineNumberReader reader = new LineNumberReader(new InputStreamReader(;
  	    System.out.print("Name: ");
  	    String name = reader.readLine();
  	    System.out.print("Street Number: ");
  	    String streetNum = reader.readLine();
  	    System.out.print("Street Name: ");
  	    String streetName = reader.readLine();
  	    System.out.print("City: ");
  	    String city = reader.readLine();
  	    System.out.print("State: ");
  	    String state = reader.readLine();
  	    System.out.print("Zip: ");
  	    String zip = reader.readLine();
  	    Address address = null;
  	    // if street is blank, look for name in addressbook service
  	    // otherwise assume this is a new user and add information to addressbook
  	    if (streetName==null || streetName.equals("")) {
  		System.out.println("Looking up address...");
  		address = lookupAddress(name);
  		if (address==null) {
  		    // if address wasn't found, we have a problem
  		    printError("Address for "+name+" wasn't found");
  	    } else {
  		// create address from provided information and add to address book
  		System.out.println("Adding address to records...");
  		address = createAndAddAddress(name,streetNum,streetName,city,state,zip);
  	    // verify that address is correct
  	    System.out.println("Verifying validity of address...");
  	    // check if we offer DSL service in that zip code
  	    System.out.println("Customer: "+name);
  	    System.out.println("Address: "+
  			       + " "
  			       + address.getStreetName()
  			       + ", "
  			       + address.getCity()
  			       + " "
  			       + address.getState()
  			       + " "
  			       + address.getZip());
  	    System.out.println("Checking service availability...");
  	    if (serviceIsAvailable(address.getZip()).equals("true")) {
  		System.out.println("Yes, we offer service in your area,"+
  				   "please call 800 555 FST-DSL to order");
  	    } else {
  		System.out.println("No, we do not offer service in your area");
  	    System.out.println("Enter 'q' to quit, any other key continue...");
  	    String choice = reader.readLine();
  	    if (choice.equals("q"))
  	} catch (Exception e) {
  	    System.out.println("ServiceChecker application got exception "+e);
      public static void main(String [] args) {
  	try {
  	    // we must have three args
  	    // args[0] is the location of the Zip2Geo service WSDL
  	    // args[1] is the location of the AddressBook service WSDL
  	    // args[2] is the location of the ServiceAvailability service WSDL
  	    if (args.length!=3) {
  	} catch (Exception e) {
  	    System.out.println("ServiceChecker application got exception "+e);

View raw message