KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.TestCase;
20 import org.apache.axis.transport.http.SimpleAxisWorker;
21 import org.apache.axis.utils.NetworkUtils;
22
23 import javax.xml.namespace.QName JavaDoc;
24 import javax.xml.rpc.Service JavaDoc;
25 import javax.xml.rpc.ServiceFactory JavaDoc;
26 import javax.xml.rpc.Stub JavaDoc;
27 import javax.xml.rpc.encoding.TypeMapping JavaDoc;
28 import javax.xml.rpc.encoding.TypeMappingRegistry JavaDoc;
29 import java.net.URL JavaDoc;
30
31
32 /**
33  * Test the address book sample code using JAX-RPC's Dynamic Proxy support.
34  */

35 public class AddressBookDynamicProxyTestCase extends TestCase {
36
37     public AddressBookDynamicProxyTestCase(String JavaDoc name) {
38         super(name);
39     }
40
41     // Use pure JAX-RPC to talk to the server.
42
public void testAddressBookServiceUsingDynamicProxy() throws Exception JavaDoc {
43         String JavaDoc nameSpaceUri = "http://addrNoImplSEI.wsdl.test";
44         String JavaDoc serviceName = "AddressBookNoImplSEIService";
45
46         String JavaDoc thisHost = NetworkUtils.getLocalHostname();
47         String JavaDoc thisPort = System.getProperty("test.functional.ServicePort", "8080");
48
49         //location of wsdl file
50
String JavaDoc wsdlLocation = "http://" + thisHost + ":" + thisPort + "/axis/services/AddressBookNoImplSEI?WSDL";
51         URL JavaDoc orgWsdlUrl = new URL JavaDoc(wsdlLocation);
52
53         ServiceFactory JavaDoc serviceFactory = ServiceFactory.newInstance();
54         Service JavaDoc addressBookService =
55                 serviceFactory.createService(orgWsdlUrl,
56                         new QName JavaDoc(nameSpaceUri, serviceName));
57
58         // Add the typemapping entries
59
TypeMappingRegistry JavaDoc registry = addressBookService.getTypeMappingRegistry();
60         TypeMapping JavaDoc map = registry.getDefaultTypeMapping();
61         map.register(test.wsdl.addrNoImplSEI.Address.class,
62                 new QName JavaDoc("urn:AddrNoImplSEI", "Address"),
63                 new org.apache.axis.encoding.ser.BeanSerializerFactory(test.wsdl.addrNoImplSEI.Address.class, new QName JavaDoc("urn:AddrNoImplSEI", "Address")),
64                 new org.apache.axis.encoding.ser.BeanDeserializerFactory(test.wsdl.addrNoImplSEI.Address.class, new QName JavaDoc("urn:AddrNoImplSEI", "Address")));
65         map.register(test.wsdl.addrNoImplSEI._Phone.class,
66                 new QName JavaDoc("urn:AddrNoImplSEI", "_Phone"),
67                 new org.apache.axis.encoding.ser.BeanSerializerFactory(test.wsdl.addrNoImplSEI._Phone.class, new QName JavaDoc("urn:AddrNoImplSEI", "_Phone")),
68                 new org.apache.axis.encoding.ser.BeanDeserializerFactory(test.wsdl.addrNoImplSEI._Phone.class, new QName JavaDoc("urn:AddrNoImplSEI", "_Phone")));
69         map.register(test.wsdl.addrNoImplSEI.StateType.class,
70                 new QName JavaDoc("urn:AddrNoImplSEI", "StateType"),
71                 new org.apache.axis.encoding.ser.EnumSerializerFactory(test.wsdl.addrNoImplSEI.StateType.class, new QName JavaDoc("urn:AddrNoImplSEI", "StateType")),
72                 new org.apache.axis.encoding.ser.EnumDeserializerFactory(test.wsdl.addrNoImplSEI.StateType.class, new QName JavaDoc("urn:AddrNoImplSEI", "StateType")));
73
74         AddressBookNoImplSEI myProxy = (AddressBookNoImplSEI) addressBookService.getPort(AddressBookNoImplSEI.class);
75         
76         // Set session on.
77
((Stub JavaDoc) myProxy)._setProperty(Stub.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
78
79         String JavaDoc name1;
80         Address addr1;
81         _Phone phone1;
82
83         name1 = "Purdue Boilermaker";
84         addr1 = new Address();
85         phone1 = new _Phone();
86         addr1.setStreetNum(1);
87         addr1.setStreetName("University Drive");
88         addr1.setCity("West Lafayette");
89         addr1.setState(StateType.IN);
90         addr1.setZip(47907);
91         phone1.setAreaCode(765);
92         phone1.setExchange("494");
93         phone1.setNumber("4900");
94         addr1.setPhone(phone1);
95         
96         // Add an entry
97
myProxy.addEntry(name1, addr1);
98         
99         // Get the list of entries
100
test.wsdl.addrNoImplSEI.Address[] addresses = myProxy.getAddresses();
101         assertTrue(addresses.length > 0);
102     }
103 }
104
105
106
Popular Tags