1 16 17 package test.dynamic; 18 19 import junit.framework.TestCase; 20 import org.apache.axis.AxisFault; 21 22 import javax.xml.namespace.QName ; 23 import javax.xml.rpc.Call ; 24 import javax.xml.rpc.Service ; 25 import javax.xml.rpc.ServiceFactory ; 26 import java.io.InterruptedIOException ; 27 import java.net.ConnectException ; 28 import java.net.URL ; 29 30 public class TestJAXRPCDII extends TestCase { 31 public TestJAXRPCDII(String name) { 32 super(name); 33 } 35 public void test1() throws Exception { 36 try { 37 String wsdlLocation = "http://www.xmethods.net/sd/2001/TemperatureService.wsdl"; 38 String wsdlNsp = "http://www.xmethods.net/sd/TemperatureService.wsdl"; 39 ServiceFactory factory = ServiceFactory.newInstance(); 40 Service service = factory.createService(new URL (wsdlLocation), 41 new QName (wsdlNsp, "TemperatureService")); 42 Call [] calls = service.getCalls(new QName (wsdlNsp,"TemperaturePort")); 43 assertTrue(calls != null); 44 assertEquals(calls[0].getOperationName().getLocalPart(),"getTemp"); 45 ((org.apache.axis.client.Call)calls[0]).setTimeout(new Integer (15*1000)); 46 Object ret = calls[0].invoke(new Object []{"02067"}); 47 System.out.println("Temperature:" + ret); 48 } catch (java.rmi.RemoteException re) { 49 if (re instanceof AxisFault) { 50 AxisFault fault = (AxisFault) re; 51 if (fault.detail instanceof ConnectException || 52 fault.detail instanceof InterruptedIOException || 53 (fault.getFaultString().indexOf("Connection timed out") != -1) || 54 fault.getFaultCode().getLocalPart().equals("HTTP")) { 55 System.err.println("getTemp HTTP error: " + fault); 56 return; 57 } 58 } 59 throw new junit.framework.AssertionFailedError("Remote Exception caught: " + re); 60 } catch (java.io.IOException ioe) { 61 System.err.println("getTemp connect error: " + ioe); 62 return; 63 } 64 } 65 } 66 | Popular Tags |