KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > wsdl > jaxrpcdynproxy > JAXRPCDynProxyTestCase


1 package test.wsdl.jaxrpcdynproxy;
2
3 import javax.xml.namespace.QName JavaDoc;
4 import javax.xml.rpc.Service JavaDoc;
5 import javax.xml.rpc.ServiceFactory JavaDoc;
6 import java.net.URL JavaDoc;
7 import test.wsdl.jaxrpcdynproxy.holders.AddressBeanHolder;
8 import junit.framework.TestCase;
9 import java.net.URL JavaDoc;
10 import java.lang.reflect.Proxy JavaDoc;
11
12 import org.apache.axis.encoding.TypeMappingRegistry;
13 import org.apache.axis.encoding.TypeMapping;
14 import org.apache.axis.encoding.ser.BeanSerializerFactory;
15 import org.apache.axis.encoding.ser.BeanDeserializerFactory;
16 import org.apache.axis.client.AxisClientProxy;
17
18 public class JAXRPCDynProxyTestCase extends TestCase {
19
20   /**
21    * Default constructor for use as service
22    */

23   public JAXRPCDynProxyTestCase() {
24       super("JAXRPCDynProxyTest");
25   }
26
27   public JAXRPCDynProxyTestCase(String JavaDoc name) {
28       super(name);
29   }
30
31   public void testInOut() throws Exception JavaDoc {
32       URL JavaDoc urlWsdl = new URL JavaDoc("http://localhost:8080/axis/services/AddressInOut?wsdl");
33       String JavaDoc nameSpaceUri = "http://jaxrpcdynproxy.wsdl.test";
34       String JavaDoc serviceName = "AddressInOut";
35       String JavaDoc portName = "AddressInOut";
36       ServiceFactory JavaDoc serviceFactory = ServiceFactory.newInstance();
37       Service JavaDoc service = serviceFactory.createService(urlWsdl, new
38               QName JavaDoc(nameSpaceUri, serviceName));
39       AddressService myProxy = (AddressService) service.getPort(new
40               QName JavaDoc(nameSpaceUri, portName), AddressService.class);
41       AddressBean addressBean = new AddressBean();
42       addressBean.setStreet("55, rue des Lilas");
43       AddressBeanHolder addressBeanHolder = new AddressBeanHolder(addressBean);
44         
45       QName JavaDoc qName = new QName JavaDoc("http://jaxrpcdynproxy.wsdl.test", "AddressBean");
46       AxisClientProxy clientProxy = (AxisClientProxy) Proxy.getInvocationHandler(myProxy);
47       clientProxy.getCall().registerTypeMapping(AddressBean.class,
48                                                 qName,
49                                                 BeanSerializerFactory.class,
50                                                 BeanDeserializerFactory.class,
51                                                 false);
52       myProxy.updateAddress(addressBeanHolder, 75005);
53       addressBean = addressBeanHolder.value;
54       assertEquals("New postcode is not the expected 75005", addressBean.getPostcode(), 75005);
55   }
56
57   public static void main(String JavaDoc[] args) throws Exception JavaDoc {
58       JAXRPCDynProxyTestCase test = new JAXRPCDynProxyTestCase("test");
59       test.testInOut();
60   }
61 }
62
Popular Tags