001: package localjava.client.stub;
002:
003: import java.rmi.RemoteException;
004:
005: import localjava.client.stub.addressbook.wsifservice.AddressBook;
006: import localjava.client.stub.addressbook.wsiftypes.Address;
007: import localjava.client.stub.addressbook.wsiftypes.Phone;
008:
009: import org.apache.wsif.WSIFException;
010: import org.apache.wsif.WSIFService;
011: import org.apache.wsif.WSIFServiceFactory;
012:
013: /**
014: * Class that runs the localjava sample using a pregenerated stub interface
015: * To use this class provide the location of the address book service's WSDL
016: * location on the command line. WSIF
017: * should then invoke the local java service for populating and then
018: * querying an addressbook.
019: * @author Nirmal K. Mukhi (nmukhi@us.ibm.com)
020: */
021:
022: public class Run {
023: private static void addFirstAddress(AddressBook addressBook) {
024: try {
025:
026: // create an address object to populate the input
027: Address address = new Address();
028: address.setStreetNum(25);
029: address.setStreetName("Willow Road");
030: address.setCity("MyTown");
031: address.setState("PA");
032: address.setZip(28382);
033: Phone phone = new Phone();
034: phone.setAreaCode(288);
035: phone.setExchange("555");
036: phone.setNumber("9891");
037: address.setPhoneNumber(phone);
038:
039: // do the invocation
040: System.out.println("Adding address for John Smith...");
041: addressBook.addEntry("John Smith", address);
042:
043: } catch (WSIFException we) {
044: System.out.println("Got exception from WSIF, details:");
045: we.printStackTrace();
046: } catch (RemoteException re) {
047: System.out
048: .println("Got exception while invoking stub, details:");
049: re.printStackTrace();
050: }
051: }
052:
053: private static void addSecondAddress(AddressBook addressBook) {
054: try {
055:
056: // create an address object to populate the input
057: Address address = new Address();
058: address.setStreetNum(20);
059: address.setStreetName("Peachtree Avenue");
060: address.setCity("Atlanta");
061: address.setState("GA");
062: address.setZip(39892);
063: Phone phone = new Phone();
064: phone.setAreaCode(701);
065: phone.setExchange("555");
066: phone.setNumber("8721");
067: address.setPhoneNumber(phone);
068:
069: // do the invocation
070: System.out.println("Adding address for Jane White...");
071: addressBook.addEntry("Jane", "White", address);
072:
073: } catch (WSIFException we) {
074: System.out.println("Got exception from WSIF, details:");
075: we.printStackTrace();
076: } catch (RemoteException re) {
077: System.out
078: .println("Got exception while invoking stub, details:");
079: re.printStackTrace();
080: }
081: }
082:
083: private static void queryAddresses(AddressBook addressBook) {
084: try {
085:
086: // do the invocation
087: System.out.println("Querying address for John Smith...");
088: Address address = addressBook
089: .getAddressFromName("John Smith");
090:
091: System.out
092: .println("Service returned the following address:");
093: System.out.println(address.getStreetNum() + " "
094: + address.getStreetName() + ", "
095: + address.getCity() + " " + address.getState()
096: + " " + address.getZip() + "; Phone: ("
097: + address.getPhoneNumber().getAreaCode() + ") "
098: + address.getPhoneNumber().getExchange() + "-"
099: + address.getPhoneNumber().getNumber());
100:
101: System.out.println("Querying address for Jane White...");
102: address = addressBook.getAddressFromName("Jane White");
103:
104: System.out
105: .println("Service returned the following address:");
106: System.out.println(address.getStreetNum() + " "
107: + address.getStreetName() + ", "
108: + address.getCity() + " " + address.getState()
109: + " " + address.getZip() + "; Phone: ("
110: + address.getPhoneNumber().getAreaCode() + ") "
111: + address.getPhoneNumber().getExchange() + "-"
112: + address.getPhoneNumber().getNumber());
113:
114: } catch (WSIFException we) {
115: System.out.println("Got exception from WSIF, details:");
116: we.printStackTrace();
117: } catch (RemoteException re) {
118: System.out
119: .println("Got exception while invoking stub, details:");
120: re.printStackTrace();
121: }
122: }
123:
124: public static void main(String[] args) {
125: try {
126: if (args.length != 1) {
127: System.out
128: .println("Usage: java localjava.client.stub.Run <wsdl location>");
129: System.exit(1);
130: }
131:
132: // create a service factory
133: WSIFServiceFactory factory = WSIFServiceFactory
134: .newInstance();
135:
136: // parse WSDL
137: WSIFService service = factory.getService(args[0], null,
138: null, "http://wsifservice.addressbook/",
139: "AddressBook");
140:
141: // create the stub
142: AddressBook stub = (AddressBook) service
143: .getStub(AddressBook.class);
144:
145: // do the invocations
146: addFirstAddress(stub);
147: addSecondAddress(stub);
148: queryAddresses(stub);
149:
150: } catch (WSIFException we) {
151: System.out.println("Got exception from WSIF, details:");
152: we.printStackTrace();
153: }
154: }
155: }
|