1 package test.jaxrpc; 2 3 import javax.xml.namespace.QName ; 4 import javax.xml.rpc.JAXRPCException ; 5 6 import org.apache.axis.AxisFault; 7 import org.apache.axis.ConfigurationException; 8 import org.apache.axis.Constants; 9 import org.apache.axis.EngineConfiguration; 10 import org.apache.axis.Handler; 11 import org.apache.axis.Message; 12 import org.apache.axis.MessageContext; 13 import org.apache.axis.client.AxisClient; 14 import org.apache.axis.client.Call; 15 import org.apache.axis.client.Service; 16 import org.apache.axis.configuration.EngineConfigurationFactoryFinder; 17 import org.apache.axis.configuration.FileProvider; 18 import org.apache.axis.deployment.wsdd.WSDDDeployment; 19 import org.apache.axis.deployment.wsdd.WSDDTransport; 20 import org.apache.axis.handlers.soap.SOAPService; 21 22 23 28 public class TestAxisClient extends AJAXRPC { 29 30 31 36 protected class AxisFaultWSDDTransport extends WSDDTransport { 37 38 41 public Handler makeNewInstance(EngineConfiguration registry) throws ConfigurationException { 42 return new MockServiceHandler(); 43 } 44 47 public QName getQName() { 48 return new QName ("faulter"); 49 } 50 } 51 54 protected void setUp() throws Exception { 55 super.setUp(); 56 } 57 58 61 protected void tearDown() throws Exception { 62 super.tearDown(); 63 } 64 78 public void testPositiveCourseFlow() throws Exception { 79 80 TestHandlerInfoChainFactory factory = buildInfoChainFactory(); 81 SOAPService soapService = new SOAPService(); 82 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory); 83 soapService.setOption(Call.WSDL_SERVICE, new Service()); 84 soapService.setOption(Call.WSDL_PORT_NAME, new QName ("Fake")); 85 soapService.init(); 86 AxisClient client = new AxisClient(); 87 MessageContext context = new TestMessageContext(client); 88 context.setTransportName("local"); 89 context.setService(soapService); 90 client.invoke(context); 91 92 AAAHandler handlerZero = factory.getHandlers()[0]; 93 AAAHandler handlerOne = factory.getHandlers()[1]; 94 AAAHandler handlerTwo = factory.getHandlers()[2]; 95 assertHandlerRuntime("handlerZero", handlerZero, 1, 1, 0); 96 assertHandlerRuntime("handlerOne", handlerOne, 1, 1, 0); 97 assertHandlerRuntime("handlerTwo", handlerTwo, 1, 1, 0); 98 } 99 100 112 public void testRequestHandlerReturnsFalse() throws Exception { 113 handler1Config.put("HANDLE_REQUEST_RETURN_VALUE", Boolean.FALSE); 115 116 TestHandlerInfoChainFactory factory = buildInfoChainFactory(); 117 SOAPService soapService = new SOAPService(); 118 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory); 119 soapService.setOption(Call.WSDL_SERVICE, new Service()); 120 soapService.setOption(Call.WSDL_PORT_NAME, new QName ("Fake")); 121 soapService.init(); 122 AxisClient client = new AxisClient(); 123 MessageContext context = new TestMessageContext(client); 124 context.setTransportName("local"); 125 context.setService(soapService); 126 client.invoke(context); 127 128 AAAHandler handlerZero = factory.getHandlers()[0]; 129 AAAHandler handlerOne = factory.getHandlers()[1]; 130 AAAHandler handlerTwo = factory.getHandlers()[2]; 131 assertHandlerRuntime("handlerZero", handlerZero, 1, 1, 0); 132 assertHandlerRuntime("handlerOne", handlerOne, 1, 1, 0); 133 assertHandlerRuntime("handlerTwo", handlerTwo, 0, 0, 0); 134 } 135 136 146 public void testRequestHandlerThrowsJAXRPCException() throws Exception { 147 handler1Config.put("HANDLE_REQUEST_RETURN_VALUE", 149 new JAXRPCException ()); 150 151 TestHandlerInfoChainFactory factory = buildInfoChainFactory(); 152 SOAPService soapService = new SOAPService(); 153 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory); 154 soapService.setOption(Call.WSDL_SERVICE, new Service()); 155 soapService.setOption(Call.WSDL_PORT_NAME, new QName ("Fake")); 156 soapService.init(); 157 AxisClient client = new AxisClient(); 158 MessageContext context = new TestMessageContext(client); 159 context.setTransportName("local"); 160 context.setService(soapService); 161 162 try { 163 client.invoke(context); 164 } catch (AxisFault e) { 165 AAAHandler handlerZero = factory.getHandlers()[0]; 166 AAAHandler handlerOne = factory.getHandlers()[1]; 167 AAAHandler handlerTwo = factory.getHandlers()[2]; 168 assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0); 169 assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 0); 170 assertHandlerRuntime("handlerTwo", handlerTwo, 0, 0, 0); 171 } 172 } 173 174 184 public void testRequestHandlerThrowsRuntimeException() throws Exception { 185 handler1Config.put("HANDLE_REQUEST_RETURN_VALUE", 187 new RuntimeException ()); 188 189 TestHandlerInfoChainFactory factory = buildInfoChainFactory(); 190 SOAPService soapService = new SOAPService(); 191 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory); 192 soapService.setOption(Call.WSDL_SERVICE, new Service()); 193 soapService.setOption(Call.WSDL_PORT_NAME, new QName ("Fake")); 194 soapService.init(); 195 AxisClient client = new AxisClient(); 196 MessageContext context = new TestMessageContext(client); 197 context.setTransportName("local"); 198 context.setService(soapService); 199 200 try { 201 client.invoke(context); 202 fail("Expected AxisFault to be thrown"); 203 } catch (AxisFault e) { 204 AAAHandler handlerZero = factory.getHandlers()[0]; 205 AAAHandler handlerOne = factory.getHandlers()[1]; 206 AAAHandler handlerTwo = factory.getHandlers()[2]; 207 assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0); 208 assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 0); 209 assertHandlerRuntime("handlerTwo", handlerTwo, 0, 0, 0); 210 } 211 } 212 213 225 public void testResponseHandlerReturnsFalse() throws Exception { 226 handler2Config.put("HANDLE_RESPONSE_RETURN_VALUE", Boolean.FALSE); 228 229 TestHandlerInfoChainFactory factory = buildInfoChainFactory(); 230 SOAPService soapService = new SOAPService(); 231 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory); 232 soapService.setOption(Call.WSDL_SERVICE, new Service()); 233 soapService.setOption(Call.WSDL_PORT_NAME, new QName ("Fake")); 234 soapService.init(); 235 AxisClient client = new AxisClient(); 236 MessageContext context = new TestMessageContext(client); 237 context.setTransportName("local"); 238 context.setService(soapService); 239 240 client.invoke(context); 241 242 AAAHandler handlerZero = factory.getHandlers()[0]; 243 AAAHandler handlerOne = factory.getHandlers()[1]; 244 AAAHandler handlerTwo = factory.getHandlers()[2]; 245 assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0); 246 assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 0); 247 assertHandlerRuntime("handlerTwo", handlerTwo, 1, 1, 0); 248 } 249 250 263 public void testResponseHandlerThrowsJAXRPCException() throws Exception { 264 handler1Config.put("HANDLE_RESPONSE_RETURN_VALUE", 266 new JAXRPCException ()); 267 268 TestHandlerInfoChainFactory factory = buildInfoChainFactory(); 269 SOAPService soapService = new SOAPService(); 270 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory); 271 soapService.setOption(Call.WSDL_SERVICE, new Service()); 272 soapService.setOption(Call.WSDL_PORT_NAME, new QName ("Fake")); 273 soapService.init(); 274 AxisClient client = new AxisClient(); 275 MessageContext context = new TestMessageContext(client); 276 context.setTransportName("local"); 277 context.setService(soapService); 278 279 try { 280 client.invoke(context); 281 fail("Expected AxisFault to be thrown"); 282 } catch (AxisFault e) { 283 AAAHandler handlerZero = factory.getHandlers()[0]; 284 AAAHandler handlerOne = factory.getHandlers()[1]; 285 AAAHandler handlerTwo = factory.getHandlers()[2]; 286 assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0); 287 assertHandlerRuntime("handlerOne", handlerOne, 1, 1, 0); 288 assertHandlerRuntime("handlerTwo", handlerTwo, 1, 1, 0); 289 } 290 } 291 292 305 public void testResponseHandlerThrowsRuntimeException() throws Exception { 306 handler1Config.put("HANDLE_RESPONSE_RETURN_VALUE", 308 new RuntimeException ()); 309 310 TestHandlerInfoChainFactory factory = buildInfoChainFactory(); 311 SOAPService soapService = new SOAPService(); 312 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory); 313 soapService.setOption(Call.WSDL_SERVICE, new Service()); 314 soapService.setOption(Call.WSDL_PORT_NAME, new QName ("Fake")); 315 soapService.init(); 316 AxisClient client = new AxisClient(); 317 MessageContext context = new TestMessageContext(client); 318 context.setTransportName("local"); 319 context.setService(soapService); 320 321 try { 322 client.invoke(context); 323 fail("Expected AxisFault to be thrown"); 324 } catch (AxisFault e) { 325 AAAHandler handlerZero = factory.getHandlers()[0]; 326 AAAHandler handlerOne = factory.getHandlers()[1]; 327 AAAHandler handlerTwo = factory.getHandlers()[2]; 328 assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0); 329 assertHandlerRuntime("handlerOne", handlerOne, 1, 1, 0); 330 assertHandlerRuntime("handlerTwo", handlerTwo, 1, 1, 0); 331 } 332 } 333 334 347 public void testHandleFaultReturnsFalse() throws Exception { 348 handler1Config.put("HANDLE_FAULT_RETURN_VALUE", Boolean.FALSE); 350 351 TestHandlerInfoChainFactory factory = buildInfoChainFactory(); 352 SOAPService soapService = new SOAPService(); 353 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory); 354 soapService.setOption(Call.WSDL_SERVICE, new Service()); 355 soapService.setOption(Call.WSDL_PORT_NAME, new QName ("Fake")); 356 soapService.init(); 357 AxisClient client = new AxisClient(); 358 addFaultTransport(client); 359 360 MessageContext context = new TestMessageContext(client); 361 context.setTransportName("faulter"); 362 context.setService(soapService); 363 364 try { 365 client.invoke(context); 366 fail("Expecting an AxisFault"); 367 } catch (AxisFault f) { 368 AAAHandler handlerZero = factory.getHandlers()[0]; 369 AAAHandler handlerOne = factory.getHandlers()[1]; 370 AAAHandler handlerTwo = factory.getHandlers()[2]; 371 assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0); 372 assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 0); 373 assertHandlerRuntime("handlerTwo", handlerTwo, 1, 0, 0); 374 } 375 } 376 377 390 public void testFaultHandlerThrowsJAXRPCException() throws Exception { 391 handler1Config.put("HANDLE_FAULT_RETURN_VALUE", new JAXRPCException ()); 392 393 TestHandlerInfoChainFactory factory = buildInfoChainFactory(); 394 Handler serviceHandler = new MockServiceHandler(); 395 SOAPService soapService = new SOAPService(null, serviceHandler, null); 396 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory); 397 soapService.setOption(Call.WSDL_SERVICE, new Service()); 398 soapService.setOption(Call.WSDL_PORT_NAME, new QName ("Fake")); 399 soapService.init(); 400 AxisClient client = new AxisClient(); 401 addFaultTransport(client); 402 403 MessageContext context = new TestMessageContext(client); 404 context.setTransportName("faulter"); 405 context.setService(soapService); 406 407 try { 408 client.invoke(context); 409 fail("Expected AxisFault to be thrown"); 410 } catch (AxisFault e) { 411 AAAHandler handlerZero = factory.getHandlers()[0]; 412 AAAHandler handlerOne = factory.getHandlers()[1]; 413 AAAHandler handlerTwo = factory.getHandlers()[2]; 414 assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0); 415 assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 0); 416 assertHandlerRuntime("handlerTwo", handlerTwo, 1, 0, 0); 417 } 418 } 419 420 433 public void testFaultHandlerThrowsRuntimeException() throws Exception { 434 handler1Config.put("HANDLE_FAULT_RETURN_VALUE", new RuntimeException ()); 436 437 TestHandlerInfoChainFactory factory = buildInfoChainFactory(); 438 Handler serviceHandler = new MockServiceHandler(); 439 SOAPService soapService = new SOAPService(null, serviceHandler, null); 440 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory); 441 soapService.setOption(Call.WSDL_SERVICE, new Service()); 442 soapService.setOption(Call.WSDL_PORT_NAME, new QName ("Fake")); 443 soapService.init(); 444 AxisClient client = new AxisClient(); 445 addFaultTransport(client); 446 447 MessageContext context = new TestMessageContext(client); 448 context.setTransportName("faulter"); 449 context.setService(soapService); 450 451 try { 452 client.invoke(context); 453 fail("Expected AxisFault to be thrown"); 454 } catch (AxisFault e) { 455 AAAHandler handlerZero = factory.getHandlers()[0]; 456 AAAHandler handlerOne = factory.getHandlers()[1]; 457 AAAHandler handlerTwo = factory.getHandlers()[2]; 458 assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0); 459 assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 0); 460 assertHandlerRuntime("handlerTwo", handlerTwo, 1, 0, 0); 461 } 462 } 463 464 478 public void testServiceObjectThrowsAxisFault() throws Exception { 479 TestHandlerInfoChainFactory factory = buildInfoChainFactory(); 480 Handler serviceHandler = new MockServiceHandler(); 481 SOAPService soapService = new SOAPService(null, serviceHandler, null); 482 soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory); 483 soapService.setOption(Call.WSDL_SERVICE, new Service()); 484 soapService.setOption(Call.WSDL_PORT_NAME, new QName ("Fake")); 485 soapService.init(); 486 AxisClient client = new AxisClient(); 487 addFaultTransport(client); 488 489 MessageContext context = new TestMessageContext(client); 490 context.setTransportName("faulter"); 491 context.setService(soapService); 492 493 try { 494 client.invoke(context); 495 fail("Expected AxisFault to be thrown"); 496 } catch (AxisFault e) { 497 AAAHandler handlerZero = factory.getHandlers()[0]; 498 AAAHandler handlerOne = factory.getHandlers()[1]; 499 AAAHandler handlerTwo = factory.getHandlers()[2]; 500 assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0); 501 assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 0); 502 assertHandlerRuntime("handlerTwo", handlerTwo, 1, 0, 0); 503 } 504 } 505 506 510 private void addFaultTransport(AxisClient client) { 511 512 FileProvider config = (FileProvider) client.getConfig(); 513 514 WSDDDeployment depl = config.getDeployment(); 515 if (depl == null) { 516 depl = new WSDDDeployment(); 517 } 518 WSDDTransport trans = new AxisFaultWSDDTransport(); 519 depl.deployTransport(trans); 520 521 } 522 523 private class TestMessageContext extends org.apache.axis.MessageContext { 524 525 public String listByAreaCode = "<soap:Envelope\n" + 526 "xmlns:s0=\"http://www.tilisoft.com/ws/LocInfo/literalTypes\"\n" + 527 "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" + 528 "xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" + 529 "<soap:Header>\n" + 530 "<WSABIHeader>\n" + 531 "<SubscriptionId>192168001100108165800640600008</SubscriptionId>\n" + 532 "</WSABIHeader>\n" + 533 "</soap:Header>\n" + 534 "<soap:Body>\n" + 535 "<s0:ListByAreaCode>\n" + 536 "<s0:AreaCode>617</s0:AreaCode>\n" + 537 "</s0:ListByAreaCode>\n" + 538 "</soap:Body>\n" + 539 "</soap:Envelope>\n"; 540 541 public TestMessageContext(AxisClient client) { 542 super(client); 543 Message message = new Message(listByAreaCode); 544 message.setMessageType(Message.REQUEST); 545 setRequestMessage(message); 546 } 547 } 548 549 } 550 | Popular Tags |