KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > dynamic > TestJAXRPCDII


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.dynamic;
18
19 import junit.framework.TestCase;
20 import org.apache.axis.AxisFault;
21
22 import javax.xml.namespace.QName JavaDoc;
23 import javax.xml.rpc.Call JavaDoc;
24 import javax.xml.rpc.Service JavaDoc;
25 import javax.xml.rpc.ServiceFactory JavaDoc;
26 import java.io.InterruptedIOException JavaDoc;
27 import java.net.ConnectException JavaDoc;
28 import java.net.URL JavaDoc;
29
30 public class TestJAXRPCDII extends TestCase {
31     public TestJAXRPCDII(String JavaDoc name) {
32         super(name);
33     } // ctor
34

35     public void test1() throws Exception JavaDoc {
36         try {
37             String JavaDoc wsdlLocation = "http://www.xmethods.net/sd/2001/TemperatureService.wsdl";
38             String JavaDoc wsdlNsp = "http://www.xmethods.net/sd/TemperatureService.wsdl";
39             ServiceFactory JavaDoc factory = ServiceFactory.newInstance();
40             Service JavaDoc service = factory.createService(new URL JavaDoc(wsdlLocation),
41                                   new QName JavaDoc(wsdlNsp, "TemperatureService"));
42             Call JavaDoc[] calls = service.getCalls(new QName JavaDoc(wsdlNsp,"TemperaturePort"));
43             assertTrue(calls != null);
44             assertEquals(calls[0].getOperationName().getLocalPart(),"getTemp");
45             ((org.apache.axis.client.Call)calls[0]).setTimeout(new Integer JavaDoc(15*1000));
46             Object JavaDoc ret = calls[0].invoke(new Object JavaDoc[]{"02067"});
47             System.out.println("Temperature:" + ret);
48         } catch (java.rmi.RemoteException JavaDoc re) {
49             if (re instanceof AxisFault) {
50                 AxisFault fault = (AxisFault) re;
51                 if (fault.detail instanceof ConnectException JavaDoc ||
52                     fault.detail instanceof InterruptedIOException JavaDoc ||
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 JavaDoc ioe) {
61             System.err.println("getTemp connect error: " + ioe);
62             return;
63         }
64     }
65 }
66
Popular Tags