1 package test.wsdl.jaxrpcdynproxy; 2 3 import javax.xml.namespace.QName ; 4 import javax.xml.rpc.Service ; 5 import javax.xml.rpc.ServiceFactory ; 6 import java.net.URL ; 7 import test.wsdl.jaxrpcdynproxy.holders.AddressBeanHolder; 8 import junit.framework.TestCase; 9 import java.net.URL ; 10 import java.lang.reflect.Proxy ; 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 23 public JAXRPCDynProxyTestCase() { 24 super("JAXRPCDynProxyTest"); 25 } 26 27 public JAXRPCDynProxyTestCase(String name) { 28 super(name); 29 } 30 31 public void testInOut() throws Exception { 32 URL urlWsdl = new URL ("http://localhost:8080/axis/services/AddressInOut?wsdl"); 33 String nameSpaceUri = "http://jaxrpcdynproxy.wsdl.test"; 34 String serviceName = "AddressInOut"; 35 String portName = "AddressInOut"; 36 ServiceFactory serviceFactory = ServiceFactory.newInstance(); 37 Service service = serviceFactory.createService(urlWsdl, new 38 QName (nameSpaceUri, serviceName)); 39 AddressService myProxy = (AddressService) service.getPort(new 40 QName (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 qName = new QName ("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 [] args) throws Exception { 58 JAXRPCDynProxyTestCase test = new JAXRPCDynProxyTestCase("test"); 59 test.testInOut(); 60 } 61 } 62 | Popular Tags |