| 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; |
| 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 |
} // ctor |
| 34 |
|
| 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 |
} |