Debian Codegraph @

test/functional/TestJAXMSamples.java

raw
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;
27 import javax.xml.soap.Name;
28 import javax.xml.soap.SOAPBody;
29 import javax.xml.soap.SOAPBodyElement;
30 import javax.xml.soap.SOAPConnection;
31 import javax.xml.soap.SOAPConnectionFactory;
32 import javax.xml.soap.SOAPElement;
33 import javax.xml.soap.SOAPEnvelope;
34 import javax.xml.soap.SOAPMessage;
35 import java.net.SocketException;
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 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 {
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 e) {
85 Throwable t = e.getCause();
86 if (t != null) {
87 t.printStackTrace();
88 if (t instanceof AxisFault) {
89 AxisFault af = (AxisFault) t;
90 if ((af.detail instanceof SocketException)
91 || (af.getFaultCode().getLocalPart().equals("HTTP"))) {
92 System.out.println("Connect failure caused JAXM DelayedStockQuote to be skipped.");
93 return;
94 }
95 }
96 throw new Exception("Fault returned from test: " + t);
97 } else {
98 e.printStackTrace();
99 throw new Exception("Exception returned from test: " + e);
100 }
101 } catch (Throwable t) {
102 t.printStackTrace();
103 throw new Exception("Fault returned from test: " + t);
104 }
105 } // testGetQuote
106
107 public void testJWSFault() throws Exception {
108 try {
109 SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance();
110 SOAPConnection con = scFactory.createConnection();
111
112 MessageFactory factory = MessageFactory.newInstance();
113 SOAPMessage message = factory.createMessage();
114
115 SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
116 SOAPBody body = envelope.getBody();
117
118 Name bodyName = envelope.createName("echo");
119 SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
120
121 Name name = envelope.createName("arg0");
122 SOAPElement symbol = bodyElement.addChildElement(name);
123 symbol.addTextNode("Hello");
124
125 URLEndpoint endpoint = new URLEndpoint("http://localhost:8080/jws/FaultTest.jws");
126 SOAPMessage response = con.call(message, endpoint);
127 SOAPBody respBody = response.getSOAPPart().getEnvelope().getBody();
128 assertTrue(respBody.hasFault());
129 } catch (javax.xml.soap.SOAPException e) {
130 Throwable t = e.getCause();
131 if (t != null) {
132 t.printStackTrace();
133 if (t instanceof AxisFault) {
134 AxisFault af = (AxisFault) t;
135 if ((af.detail instanceof SocketException)
136 || (af.getFaultCode().getLocalPart().equals("HTTP"))) {
137 System.out.println("Connect failure caused testJWSFault to be skipped.");
138 return;
139 }
140 }
141 throw new Exception("Fault returned from test: " + t);
142 } else {
143 e.printStackTrace();
144 throw new Exception("Exception returned from test: " + e);
145 }
146 } catch (Throwable t) {
147 t.printStackTrace();
148 throw new Exception("Fault returned from test: " + t);
149 }
150 }
151
152 public static void main(String args[]) throws Exception {
153 TestJAXMSamples tester = new TestJAXMSamples("tester");
154 //tester.testUddiPing();
155 } // main
156 }
157
158