Debian Codegraph @

samples/addr/Main.java

raw
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 samples.addr;
18
19 import org.apache.axis.utils.Options;
20
21 import java.net.URL;
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 ([email protected])
30 * @author Sanjiva Weerawarana <[email protected]>
31 */
32 public class Main {
33 static String 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.setPhoneNumber(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.getPhoneNumber();
62 System.err.println ("\tPhone: (" + ph.getAreaCode() + ") " +
63 ph.getExchange() + "-" + ph.getNumber());
64 }
65
66 private static Object doit (AddressBook ab) throws Exception {
67 System.err.println (">> Storing address for '" + name1 + "'");
68 ab.addEntry (name1, addr1);
69 System.err.println (">> Querying address for '" + name1 + "'");
70 Address resp = ab.getAddressFromName (name1);
71 System.err.println (">> Response is:");
72 printAddress (resp);
73
74 // if we are NOT maintaining session, resp must be == null.
75 // If we ARE, resp must be != null.
76
77 System.err.println (">> Querying address for '" + name1 + "' again");
78 resp = ab.getAddressFromName (name1);
79 System.err.println (">> Response is:");
80 printAddress (resp);
81 return resp;
82 }
83
84 public static void main (String[] args) throws Exception {
85 Options opts = new Options(args);
86
87 System.err.println ("Using proxy without session maintenance.");
88 System.err.println ("(queries without session should say: \"ADDRESS NOT FOUND!\")");
89
90 AddressBookService abs = new AddressBookServiceLocator();
91 opts.setDefaultURL( abs.getAddressBookAddress() );
92 URL serviceURL = new URL(opts.getURL());
93
94 AddressBook ab1 = null;
95 if (serviceURL == null) {
96 ab1 = abs.getAddressBook();
97 }
98 else {
99 ab1 = abs.getAddressBook(serviceURL);
100 }
101 Object ret = doit (ab1);
102 if (ret != null) {
103 throw new Exception("non-session test expected null response, got " + ret);
104 }
105
106 System.err.println ("\n\nUsing proxy with session maintenance.");
107 AddressBook ab2 = null;
108 if (serviceURL == null) {
109 ab2 = abs.getAddressBook();
110 }
111 else {
112 ab2 = abs.getAddressBook(serviceURL);
113 }
114 ((AddressBookSOAPBindingStub) ab2).setMaintainSession (true);
115 ret = doit (ab2);
116 if (ret == null) {
117 throw new Exception("session test expected non-null response, got " + ret);
118 }
119 }
120 }