| 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; |
| 24 |
import javax.xml.rpc.Service; |
| 25 |
import javax.xml.rpc.ServiceFactory; |
| 26 |
import javax.xml.rpc.Stub; |
| 27 |
import javax.xml.rpc.encoding.TypeMapping; |
| 28 |
import javax.xml.rpc.encoding.TypeMappingRegistry; |
| 29 |
import java.net.URL; |
| 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 name) { |
| 38 |
super(name); |
| 39 |
} |
| 40 |
|
| 41 |
// Use pure JAX-RPC to talk to the server. |
| 42 |
public void testAddressBookServiceUsingDynamicProxy() throws Exception { |
| 43 |
String nameSpaceUri = "http://addrNoImplSEI.wsdl.test"; |
| 44 |
String serviceName = "AddressBookNoImplSEIService"; |
| 45 |
|
| 46 |
String thisHost = NetworkUtils.getLocalHostname(); |
| 47 |
String thisPort = System.getProperty("test.functional.ServicePort", "8080"); |
| 48 |
|
| 49 |
//location of wsdl file |
| 50 |
String wsdlLocation = "http://" + thisHost + ":" + thisPort + "/axis/services/AddressBookNoImplSEI?WSDL"; |
| 51 |
URL orgWsdlUrl = new URL(wsdlLocation); |
| 52 |
|
| 53 |
ServiceFactory serviceFactory = ServiceFactory.newInstance(); |
| 54 |
Service addressBookService = |
| 55 |
serviceFactory.createService(orgWsdlUrl, |
| 56 |
new QName(nameSpaceUri, serviceName)); |
| 57 |
|
| 58 |
// Add the typemapping entries |
| 59 |
TypeMappingRegistry registry = addressBookService.getTypeMappingRegistry(); |
| 60 |
TypeMapping map = registry.getDefaultTypeMapping(); |
| 61 |
map.register(test.wsdl.addrNoImplSEI.Address.class, |
| 62 |
new QName("urn:AddrNoImplSEI", "Address"), |
| 63 |
new org.apache.axis.encoding.ser.BeanSerializerFactory(test.wsdl.addrNoImplSEI.Address.class, new QName("urn:AddrNoImplSEI", "Address")), |
| 64 |
new org.apache.axis.encoding.ser.BeanDeserializerFactory(test.wsdl.addrNoImplSEI.Address.class, new QName("urn:AddrNoImplSEI", "Address"))); |
| 65 |
map.register(test.wsdl.addrNoImplSEI.Phone.class, |
| 66 |
new QName("urn:AddrNoImplSEI", ">Phone"), |
| 67 |
new org.apache.axis.encoding.ser.BeanSerializerFactory(test.wsdl.addrNoImplSEI.Phone.class, new QName("urn:AddrNoImplSEI", ">Phone")), |
| 68 |
new org.apache.axis.encoding.ser.BeanDeserializerFactory(test.wsdl.addrNoImplSEI.Phone.class, new QName("urn:AddrNoImplSEI", ">Phone"))); |
| 69 |
map.register(test.wsdl.addrNoImplSEI.StateType.class, |
| 70 |
new QName("urn:AddrNoImplSEI", "StateType"), |
| 71 |
new org.apache.axis.encoding.ser.EnumSerializerFactory(test.wsdl.addrNoImplSEI.StateType.class, new QName("urn:AddrNoImplSEI", "StateType")), |
| 72 |
new org.apache.axis.encoding.ser.EnumDeserializerFactory(test.wsdl.addrNoImplSEI.StateType.class, new QName("urn:AddrNoImplSEI", "StateType"))); |
| 73 |
|
| 74 |
AddressBookNoImplSEI myProxy = (AddressBookNoImplSEI) addressBookService.getPort(AddressBookNoImplSEI.class); |
| 75 |
|
| 76 |
// Set session on. |
| 77 |
((Stub) myProxy)._setProperty(Stub.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE); |
| 78 |
|
| 79 |
String 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 |
|