Debian Codegraph @

test/jaxrpc/TestSOAPService.java

raw
1 package test.jaxrpc;
2
3 import junit.framework.TestCase;
4 import org.apache.axis.AxisFault;
5 import org.apache.axis.Constants;
6 import org.apache.axis.Handler;
7 import org.apache.axis.Message;
8 import org.apache.axis.MessageContext;
9 import org.apache.axis.handlers.BasicHandler;
10 import org.apache.axis.handlers.HandlerInfoChainFactory;
11 import org.apache.axis.handlers.soap.SOAPService;
12 import org.apache.axis.message.Detail;
13 import org.apache.axis.server.AxisServer;
14
15 import javax.xml.rpc.JAXRPCException;
16 import javax.xml.rpc.handler.HandlerChain;
17 import javax.xml.rpc.handler.HandlerInfo;
18 import javax.xml.rpc.soap.SOAPFaultException;
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Map;
23
24 public class TestSOAPService
25 extends AJAXRPC {
26 /**
27 * All Handlers in Chain return true for handleRequest and handleResponse
28 * <p/>
29 * <p/>
30 * * Expected Chain invocation sequence looks like.....
31 * H0.handleRequest
32 * H1.handleRequest
33 * H2.handleRequest
34 * H2.handleResponse
35 * H1.handleResponse
36 * H0.handleResponse
37 *
38 * @throws Exception
39 */
40 public void testPositiveCourseFlow() throws Exception {
41 TestHandlerInfoChainFactory factory = buildInfoChainFactory();
42 SOAPService soapService = new SOAPService();
43 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
44 soapService.init();
45 soapService.invoke(new TestMessageContext());
46 AAAHandler handlerZero = factory.getHandlers()[0];
47 AAAHandler handlerOne = factory.getHandlers()[1];
48 AAAHandler handlerTwo = factory.getHandlers()[2];
49 assertHandlerRuntime("handlerZero", handlerZero, 1, 1, 0);
50 assertHandlerRuntime("handlerOne", handlerOne, 1, 1, 0);
51 assertHandlerRuntime("handlerTwo", handlerTwo, 1, 1, 0);
52 }
53
54 /**
55 * Tests scenario where one handler returns false on a call
56 * to handleRequest(...).
57 * <p/>
58 * Expected Chain invocation sequence looks like.....
59 * H0.handleRequest
60 * H1.handleRequest returns false
61 * H1.handleResponse
62 * H0.handleResponse
63 *
64 * @throws Exception
65 */
66 public void testRequestHandlerReturnsFalse() throws Exception {
67 SOAPService soapService = new SOAPService();
68
69 // SETUP THE 2nd HANDLER IN THE REQUEST CHAIN TO RETURN FALSE
70 handler1Config.put("HANDLE_REQUEST_RETURN_VALUE", Boolean.FALSE);
71 TestHandlerInfoChainFactory factory = buildInfoChainFactory();
72 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
73 soapService.init();
74 MessageContext msgContext = new TestMessageContext();
75 soapService.invoke(msgContext);
76 AAAHandler handlerZero = factory.getHandlers()[0];
77 AAAHandler handlerOne = factory.getHandlers()[1];
78 AAAHandler handlerTwo = factory.getHandlers()[2];
79 assertHandlerRuntime("handlerZero", handlerZero, 1, 1, 0);
80 assertHandlerRuntime("handlerOne", handlerOne, 1, 1, 0);
81 assertHandlerRuntime("handlerTwo", handlerTwo, 0, 0, 0);
82 }
83
84 /**
85 * @throws Exception
86 */
87 public void testRequestHandlerThrowsSFE() throws Exception {
88 SOAPService soapService = new SOAPService();
89
90 // SETUP THE 2nd HANDLER IN THE REQUEST CHAIN TO THROW SOAPFaultException
91 handler1Config.put("HANDLE_REQUEST_RETURN_VALUE",
92 new SOAPFaultException(null, "f", "f", new Detail()));
93 TestHandlerInfoChainFactory factory = buildInfoChainFactory();
94 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
95 soapService.init();
96 MessageContext msgContext = new TestMessageContext();
97 soapService.invoke(msgContext);
98 AAAHandler handlerZero = factory.getHandlers()[0];
99 AAAHandler handlerOne = factory.getHandlers()[1];
100 AAAHandler handlerTwo = factory.getHandlers()[2];
101 assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 1);
102 assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 1);
103 assertHandlerRuntime("handlerTwo", handlerTwo, 0, 0, 0);
104 }
105
106 /**
107 * @throws Exception
108 */
109 public void testRequestHandlerThrowsJAXRPCException() throws Exception {
110 SOAPService soapService = new SOAPService();
111
112 // SETUP THE 2nd HANDLER IN THE REQUEST CHAIN TO THROW JAXRPCException
113 handler1Config.put("HANDLE_REQUEST_RETURN_VALUE",
114 new JAXRPCException());
115 TestHandlerInfoChainFactory factory = buildInfoChainFactory();
116 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
117 soapService.init();
118 MessageContext msgContext = new TestMessageContext();
119 try {
120 soapService.invoke(msgContext);
121 } catch (AxisFault e) {
122 AAAHandler handlerZero = factory.getHandlers()[0];
123 AAAHandler handlerOne = factory.getHandlers()[1];
124 AAAHandler handlerTwo = factory.getHandlers()[2];
125 assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
126 assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 0);
127 assertHandlerRuntime("handlerTwo", handlerTwo, 0, 0, 0);
128 }
129 }
130
131 public void testRequestHandlerThrowsRuntimeException() throws Exception {
132 SOAPService soapService = new SOAPService();
133
134 // SETUP THE 2nd HANDLER IN THE REQUEST CHAIN TO THROW JAXRPCException
135 handler1Config.put("HANDLE_REQUEST_RETURN_VALUE",
136 new RuntimeException());
137 TestHandlerInfoChainFactory factory = buildInfoChainFactory();
138 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
139 soapService.init();
140 MessageContext msgContext = new TestMessageContext();
141 try {
142 soapService.invoke(msgContext);
143 } catch (AxisFault e) {
144 AAAHandler handlerZero = factory.getHandlers()[0];
145 AAAHandler handlerOne = factory.getHandlers()[1];
146 AAAHandler handlerTwo = factory.getHandlers()[2];
147 assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
148 assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 0);
149 assertHandlerRuntime("handlerTwo", handlerTwo, 0, 0, 0);
150 }
151 }
152
153 public void testResponseHandlerReturnsFalse() throws Exception {
154 SOAPService soapService = new SOAPService();
155
156 // SETUP THE 3rd HANDLER IN THE CHAIN TO RETURN FALSE on handleResponse
157 handler2Config.put("HANDLE_RESPONSE_RETURN_VALUE", Boolean.FALSE);
158 TestHandlerInfoChainFactory factory = buildInfoChainFactory();
159 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
160 soapService.init();
161 MessageContext msgContext = new TestMessageContext();
162 soapService.invoke(msgContext);
163 AAAHandler handlerZero = factory.getHandlers()[0];
164 AAAHandler handlerOne = factory.getHandlers()[1];
165 AAAHandler handlerTwo = factory.getHandlers()[2];
166 assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
167 assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 0);
168 assertHandlerRuntime("handlerTwo", handlerTwo, 1, 1, 0);
169 }
170
171 public void testResponseHandlerThrowsJAXRPCException() throws Exception {
172 SOAPService soapService = new SOAPService();
173
174 // SETUP THE 2nd HANDLER IN THE CHAIN TO THROW JAXRPCException on handleResponse
175 handler1Config.put("HANDLE_RESPONSE_RETURN_VALUE",
176 new JAXRPCException());
177 TestHandlerInfoChainFactory factory = buildInfoChainFactory();
178 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
179 soapService.init();
180 MessageContext msgContext = new TestMessageContext();
181 try {
182 soapService.invoke(msgContext);
183 fail("Expected AxisFault to be thrown");
184 } catch (AxisFault e) {
185 AAAHandler handlerZero = factory.getHandlers()[0];
186 AAAHandler handlerOne = factory.getHandlers()[1];
187 AAAHandler handlerTwo = factory.getHandlers()[2];
188 assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
189 assertHandlerRuntime("handlerOne", handlerOne, 1, 1, 0);
190 assertHandlerRuntime("handlerTwo", handlerTwo, 1, 1, 0);
191 }
192 }
193
194 public void testResponseHandlerThrowsRuntimeException() throws Exception {
195 SOAPService soapService = new SOAPService();
196
197 // SETUP THE 2nd HANDLER IN THE CHAIN TO THROW RuntimeException on handleResponse
198 handler1Config.put("HANDLE_RESPONSE_RETURN_VALUE",
199 new RuntimeException());
200 TestHandlerInfoChainFactory factory = buildInfoChainFactory();
201 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
202 soapService.init();
203 MessageContext msgContext = new TestMessageContext();
204 try {
205 soapService.invoke(msgContext);
206 fail("Expected AxisFault to be thrown");
207 } catch (AxisFault e) {
208 AAAHandler handlerZero = factory.getHandlers()[0];
209 AAAHandler handlerOne = factory.getHandlers()[1];
210 AAAHandler handlerTwo = factory.getHandlers()[2];
211 assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
212 assertHandlerRuntime("handlerOne", handlerOne, 1, 1, 0);
213 assertHandlerRuntime("handlerTwo", handlerTwo, 1, 1, 0);
214 }
215 }
216
217 public void testHandleFaultReturnsFalse() throws Exception {
218 SOAPService soapService = new SOAPService();
219
220 // SETUP THE LAST HANDLER IN THE REQUEST CHAIN TO THROW SOAPFaultException
221 handler2Config.put("HANDLE_REQUEST_RETURN_VALUE",
222 new SOAPFaultException(null, "f", "f", new Detail()));
223 handler1Config.put("HANDLE_FAULT_RETURN_VALUE", Boolean.FALSE);
224 TestHandlerInfoChainFactory factory = buildInfoChainFactory();
225 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
226 soapService.init();
227 MessageContext msgContext = new TestMessageContext();
228 soapService.invoke(msgContext);
229 AAAHandler handlerZero = factory.getHandlers()[0];
230 AAAHandler handlerOne = factory.getHandlers()[1];
231 AAAHandler handlerTwo = factory.getHandlers()[2];
232 assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
233 assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 1);
234 assertHandlerRuntime("handlerTwo", handlerTwo, 1, 0, 1);
235 }
236
237 /**
238 * Tests to see if we handle the scenario of a handler throwing a
239 * runtime exception during the handleFault(...) processing correctly
240 * <p/>
241 * Expected chain sequence:
242 * H0.handleRequest
243 * H1.handleRequest
244 * H2.handleRequest SOAPFaultException
245 * H2.handleFault
246 * H1.handleFault throws JAXRPCException
247 *
248 * @throws Exception
249 */
250 public void testFaultHandlerThrowsJAXRPCException() throws Exception {
251 SOAPService soapService = new SOAPService();
252
253 // SETUP THE LAST HANDLER IN THE REQUEST CHAIN TO THROW SOAPFaultException
254 handler2Config.put("HANDLE_REQUEST_RETURN_VALUE",
255 new SOAPFaultException(null, "f", "f", new Detail()));
256 handler1Config.put("HANDLE_FAULT_RETURN_VALUE", new JAXRPCException());
257 TestHandlerInfoChainFactory factory = buildInfoChainFactory();
258 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
259 soapService.init();
260 MessageContext msgContext = new TestMessageContext();
261 try {
262 soapService.invoke(msgContext);
263 fail("Expected AxisFault to be thrown");
264 } catch (AxisFault e) {
265 AAAHandler handlerZero = factory.getHandlers()[0];
266 AAAHandler handlerOne = factory.getHandlers()[1];
267 AAAHandler handlerTwo = factory.getHandlers()[2];
268 assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
269 assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 1);
270 assertHandlerRuntime("handlerTwo", handlerTwo, 1, 0, 1);
271 }
272 }
273
274 /**
275 * Tests to see if we handle the scenario of a handler throwing a
276 * runtime exception during the handleFault(...) processing correctly
277 * <p/>
278 * Expected chain sequence:
279 * H0.handleRequest
280 * H1.handleRequest
281 * H2.handleRequest throws SOAPFaultException
282 * H2.handleFault
283 * H1.handleFault throws RuntimeException
284 *
285 * @throws Exception
286 */
287 public void testFaultHandlerThrowsRuntimeException() throws Exception {
288 SOAPService soapService = new SOAPService();
289
290 // SETUP THE LAST HANDLER IN THE REQUEST CHAIN TO THROW SOAPFaultException
291 handler2Config.put("HANDLE_REQUEST_RETURN_VALUE",
292 new SOAPFaultException(null, "f", "f", new Detail()));
293 handler1Config.put("HANDLE_FAULT_RETURN_VALUE", new RuntimeException());
294 TestHandlerInfoChainFactory factory = buildInfoChainFactory();
295 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
296 soapService.init();
297 MessageContext msgContext = new TestMessageContext();
298 try {
299 soapService.invoke(msgContext);
300 fail("Expected AxisFault to be thrown");
301 } catch (AxisFault e) {
302 AAAHandler handlerZero = factory.getHandlers()[0];
303 AAAHandler handlerOne = factory.getHandlers()[1];
304 AAAHandler handlerTwo = factory.getHandlers()[2];
305 assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
306 assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 1);
307 assertHandlerRuntime("handlerTwo", handlerTwo, 1, 0, 1);
308 }
309 }
310
311 /**
312 * Tests scenario where service object throws Axis Fault.
313 * <p/>
314 * Expected chain sequence:
315 * H0.handleRequest
316 * H1.handleRequest
317 * H2.handleRequest
318 * ServiceObject.invoke() throws AxisFault
319 * H2.handleFault
320 * H1.handleFault
321 * H0.handleFault
322 *
323 * @throws Exception
324 */
325 public void testServiceObjectThrowsAxisFault() throws Exception {
326 Handler serviceHandler = new MockServiceHandler();
327 SOAPService soapService = new SOAPService(null, null, serviceHandler);
328 TestHandlerInfoChainFactory factory = buildInfoChainFactory();
329 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
330 soapService.init();
331 MessageContext msgContext = new TestMessageContext();
332 try {
333 soapService.invoke(msgContext);
334 fail("Expected AxisFault to be thrown");
335 } catch (AxisFault e) {
336 AAAHandler handlerZero = factory.getHandlers()[0];
337 AAAHandler handlerOne = factory.getHandlers()[1];
338 AAAHandler handlerTwo = factory.getHandlers()[2];
339 assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 1);
340 assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 1);
341 assertHandlerRuntime("handlerTwo", handlerTwo, 1, 0, 1);
342 }
343 }
344
345 private class TestMessageContext extends org.apache.axis.MessageContext {
346
347 public String listByAreaCode = "<soap:Envelope\n" +
348 "xmlns:s0=\"http://www.tilisoft.com/ws/LocInfo/literalTypes\"\n" +
349 "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
350 "xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" +
351 "<soap:Header>\n" +
352 "<WSABIHeader>\n" +
353 "<SubscriptionId>192168001100108165800640600008</SubscriptionId>\n" +
354 "</WSABIHeader>\n" +
355 "</soap:Header>\n" +
356 "<soap:Body>\n" +
357 "<s0:ListByAreaCode>\n" +
358 "<s0:AreaCode>617</s0:AreaCode>\n" +
359 "</s0:ListByAreaCode>\n" +
360 "</soap:Body>\n" +
361 "</soap:Envelope>\n";
362
363 public TestMessageContext() {
364 super(new AxisServer());
365 Message message = new Message(listByAreaCode);
366 message.setMessageType(Message.REQUEST);
367 setRequestMessage(message);
368 }
369 }
370
371 }