KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > functional > TestJAXMSamples


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.functional;
18
19 import junit.framework.TestCase;
20 import org.apache.axis.AxisFault;
21 import org.apache.axis.components.logger.LogFactory;
22 import org.apache.commons.logging.Log;
23 import samples.jaxm.DelayedStockQuote;
24
25 import javax.xml.messaging.URLEndpoint;
26 import javax.xml.soap.MessageFactory JavaDoc;
27 import javax.xml.soap.Name JavaDoc;
28 import javax.xml.soap.SOAPBody JavaDoc;
29 import javax.xml.soap.SOAPBodyElement JavaDoc;
30 import javax.xml.soap.SOAPConnection JavaDoc;
31 import javax.xml.soap.SOAPConnectionFactory JavaDoc;
32 import javax.xml.soap.SOAPElement JavaDoc;
33 import javax.xml.soap.SOAPEnvelope JavaDoc;
34 import javax.xml.soap.SOAPMessage JavaDoc;
35 import java.net.SocketException JavaDoc;
36
37
38 /**
39  * Test the JAX-RPC compliance samples.
40  */

41 public class TestJAXMSamples extends TestCase {
42     static Log log = LogFactory.getLog(TestJAXMSamples.class.getName());
43
44     public TestJAXMSamples(String JavaDoc name) {
45         super(name);
46     } // ctor
47

48 // // This is timing out for some reason - removed for the nonce.
49
// // -- gdaniels, 4/21/2003
50
// public void testUddiPing() throws Exception {
51
// try {
52
// log.info("Testing JAXM UddiPing sample.");
53
// UddiPing.searchUDDI("IBM", "http://www-3.ibm.com/services/uddi/testregistry/inquiryapi");
54
// log.info("Test complete.");
55
// } catch (javax.xml.soap.SOAPException e) {
56
// Throwable t = e.getCause();
57
// if (t != null) {
58
// t.printStackTrace();
59
// if (t instanceof AxisFault) {
60
// AxisFault af = (AxisFault) t;
61
// if ((af.detail instanceof SocketException) ||
62
// (af.getFaultCode().getLocalPart().equals("HTTP")) ) {
63
// System.out.println("Connect failure caused JAXM UddiPing to be skipped.");
64
// return;
65
// }
66
// }
67
// throw new Exception("Fault returned from test: " + t);
68
// } else {
69
// e.printStackTrace();
70
// throw new Exception("Exception returned from test: " + e);
71
// }
72
// } catch (Throwable t) {
73
// t.printStackTrace();
74
// throw new Exception("Fault returned from test: " + t);
75
// }
76
// } // testGetQuote
77

78     public void testDelayedStockQuote() throws Exception JavaDoc {
79         try {
80             log.info("Testing JAXM DelayedStockQuote sample.");
81             DelayedStockQuote stockQuote = new DelayedStockQuote();
82             System.out.print("The last price for SUNW is " + stockQuote.getStockQuote("SUNW"));
83             log.info("Test complete.");
84         } catch (javax.xml.soap.SOAPException JavaDoc e) {
85             Throwable JavaDoc t = e.getCause();
86             if (t != null) {
87                 t.printStackTrace();
88                 if (t instanceof AxisFault) {
89                     if (((AxisFault) t).detail instanceof SocketException JavaDoc) {
90                         System.out.println("Connect failure caused JAXM DelayedStockQuote to be skipped.");
91                         return;
92                     }
93                 }
94                 throw new Exception JavaDoc("Fault returned from test: " + t);
95             } else {
96                 e.printStackTrace();
97                 throw new Exception JavaDoc("Exception returned from test: " + e);
98             }
99         } catch (Throwable JavaDoc t) {
100             t.printStackTrace();
101             throw new Exception JavaDoc("Fault returned from test: " + t);
102         }
103     } // testGetQuote
104

105     public void testJWSFault() throws Exception JavaDoc {
106         SOAPConnectionFactory JavaDoc scFactory = SOAPConnectionFactory.newInstance();
107         SOAPConnection JavaDoc con = scFactory.createConnection();
108
109         MessageFactory JavaDoc factory = MessageFactory.newInstance();
110         SOAPMessage JavaDoc message = factory.createMessage();
111
112         SOAPEnvelope JavaDoc envelope = message.getSOAPPart().getEnvelope();
113         SOAPBody JavaDoc body = envelope.getBody();
114
115         Name JavaDoc bodyName = envelope.createName("echo");
116         SOAPBodyElement JavaDoc bodyElement = body.addBodyElement(bodyName);
117
118         Name JavaDoc name = envelope.createName("arg0");
119         SOAPElement JavaDoc symbol = bodyElement.addChildElement(name);
120         symbol.addTextNode("Hello");
121
122         URLEndpoint endpoint = new URLEndpoint("http://localhost:8080/jws/FaultTest.jws");
123         SOAPMessage JavaDoc response = con.call(message, endpoint);
124         SOAPBody JavaDoc respBody = response.getSOAPPart().getEnvelope().getBody();
125         assertTrue(respBody.hasFault());
126     }
127
128     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
129         TestJAXMSamples tester = new TestJAXMSamples("tester");
130         //tester.testUddiPing();
131
} // main
132
}
133
134
135
Popular Tags