KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > wsdl > addrNoImplSEI > Main


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package test.wsdl.addrNoImplSEI;
18
19 import org.apache.axis.utils.Options;
20
21 import java.net.URL JavaDoc;
22
23
24
25 /**
26  * This class shows how to use the Call object's ability to
27  * become session aware.
28  *
29  * @author Rob Jellinghaus (robj@unrealities.com)
30  * @author Sanjiva Weerawarana <sanjiva@watson.ibm.com>
31  */

32 public class Main {
33     static String JavaDoc name1;
34     static Address addr1;
35     static Phone phone1;
36     
37     static {
38         name1 = "Purdue Boilermaker";
39         addr1 = new Address();
40         phone1 = new Phone();
41         addr1.setStreetNum(1);
42         addr1.setStreetName("University Drive");
43         addr1.setCity("West Lafayette");
44         addr1.setState(StateType.IN);
45         addr1.setZip(47907);
46         phone1.setAreaCode(765);
47         phone1.setExchange("494");
48         phone1.setNumber("4900");
49         addr1.setPhone(phone1);
50         
51     }
52     private static void printAddress (Address ad) {
53         if (ad == null) {
54             System.err.println ("\t[ADDRESS NOT FOUND!]");
55             return;
56         }
57         System.err.println ("\t" + ad.getStreetNum() + " " +
58                                 ad.getStreetName());
59         System.err.println ("\t" + ad.getCity() + ", " + ad.getState() + " " +
60                                 ad.getZip());
61         Phone ph = ad.getPhone();
62         System.err.println ("\tPhone: (" + ph.getAreaCode() + ") " +
63                                 ph.getExchange() + "-" + ph.getNumber());
64     }
65     
66     private static Object JavaDoc doit (AddressBookNoImplSEI ab) throws Exception JavaDoc {
67         ab.addEntry (name1, addr1);
68         Address resp = ab.getAddressFromName (name1);
69         
70         // if we are NOT maintaining session, resp must be == null.
71
// If we ARE, resp must be != null.
72

73         resp = ab.getAddressFromName (name1);
74         
75         // Test NPE
76
try {
77             ab.addEntry(null, null);
78             throw new Exception JavaDoc("Expected exception when calling addEntry with null params");
79         } catch (org.apache.axis.AxisFault e) {
80             if ("java.lang.IllegalArgumentException".equals(e.getFaultString())) {
81                 // Good! Expected this!
82
} else {
83                 throw e; // This is not right!
84
}
85         }
86         
87         return resp;
88     }
89     
90     public static void main (String JavaDoc[] args) throws Exception JavaDoc {
91         Options opts = new Options(args);
92
93         AddressBookNoImplSEIService abs = new AddressBookNoImplSEIServiceLocator();
94         opts.setDefaultURL( abs.getAddressBookNoImplSEIAddress() );
95         URL JavaDoc serviceURL = new URL JavaDoc(opts.getURL());
96
97         AddressBookNoImplSEI ab1 = null;
98         if (serviceURL == null) {
99             ab1 = abs.getAddressBookNoImplSEI();
100         }
101         else {
102             ab1 = abs.getAddressBookNoImplSEI(serviceURL);
103         }
104         Object JavaDoc ret = doit (ab1);
105         if (ret != null) {
106             throw new Exception JavaDoc("non-session test expected null response, got "+ret);
107         }
108
109         AddressBookNoImplSEI ab2 = null;
110         if (serviceURL == null) {
111             ab2 = abs.getAddressBookNoImplSEI();
112         }
113         else {
114             ab2 = abs.getAddressBookNoImplSEI(serviceURL);
115         }
116         ((AddressBookNoImplSEISoapBindingStub) ab2).setMaintainSession (true);
117         ret = doit (ab2);
118         if (ret == null) {
119             throw new Exception JavaDoc("session test expected non-null response, got "+ret);
120         }
121     }
122 }
123
Popular Tags