1 57 58 package jms; 59 60 import java.text.DateFormat ; 61 import java.util.Date ; 62 63 import junit.framework.Test; 64 import junit.framework.TestCase; 65 import junit.framework.TestSuite; 66 67 import org.apache.wsif.WSIFConstants; 68 import org.apache.wsif.WSIFCorrelationId; 69 import org.apache.wsif.WSIFException; 70 import org.apache.wsif.WSIFMessage; 71 import org.apache.wsif.WSIFOperation; 72 import org.apache.wsif.WSIFPort; 73 import org.apache.wsif.WSIFService; 74 import org.apache.wsif.WSIFServiceFactory; 75 import org.apache.wsif.util.WSIFProperties; 76 import util.AddressUtility; 77 import util.TestUtilities; 78 79 import addressbook.wsifservice.AddressBook; 80 import addressbook.wsiftypes.Address; 81 import addressbook.wsiftypes.Phone; 82 import async.AsyncResponseHandler; 83 84 93 public class JMSTimeoutTest extends TestCase { 94 String wsdlLocation = 95 TestUtilities.getWsdlPath("java\\test\\jms") + "Timeouts.wsdl"; 96 97 private static final long sps1 = 7000; 98 private static final long spa1 = 11000; 99 private static final long sps2 = 12000; 100 private static final long spa2 = 14000; 101 private static final long sps3 = 15000; 102 private static final long spa3 = 18000; 103 private static final long sps4 = 3000; private static final long spa4 = 10000; private static final long sps5 = 25000; 106 private static final long spa5 = 27000; 107 private static final long sps6 = 15000; 108 private static final long spa6 = 18000; 109 110 public JMSTimeoutTest(String name) { 111 super(name); 112 } 113 114 public static void main(String [] args) { 115 junit.textui.TestRunner.run(suite()); 117 } 119 120 public static Test suite() { 121 return new TestSuite(JMSTimeoutTest.class); 122 } 123 124 public void setUp() { 125 TestUtilities.setUpExtensionsAndProviders(); 126 } 127 128 165 public void testDynamicAxisJms6() { 199 testAsyncOPs("SOAPJMSPort6", "axis"); 200 } 201 202 239 private void doitDyn(String portName, String protocol) { 240 if (portName.toUpperCase().indexOf("JMS") != -1 241 && !TestUtilities.areWeTesting("jms")) 242 return; 243 244 TestUtilities.setProviderForProtocol(protocol); 245 246 try { 247 WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); 248 WSIFService service = 249 factory.getService( 250 wsdlLocation, 251 null, 252 null, 253 "http://wsifservice.addressbook/", 254 "AddressBook"); 255 256 service.mapType( 257 new javax.xml.namespace.QName ( 258 "http://wsiftypes.addressbook/", 259 "address"), 260 Class.forName("addressbook.wsiftypes.Address")); 261 262 service.mapType( 263 new javax.xml.namespace.QName ( 264 "http://wsiftypes.addressbook/", 265 "phone"), 266 Class.forName("addressbook.wsiftypes.Phone")); 267 268 WSIFPort port = service.getPort(portName); 269 270 WSIFOperation operation = 271 port.createOperation("getAddressFromName"); 272 273 WSIFMessage inputMessage = operation.createInputMessage(); 275 WSIFMessage outputMessage = operation.createOutputMessage(); 276 WSIFMessage faultMessage = operation.createFaultMessage(); 277 278 String nameToLookup = "Chris P. Bacon"; 280 inputMessage.setObjectPart("name", nameToLookup); 281 282 if ("SOAPJMSPort2".equals(portName) 283 || "NativeJmsPort2".equals(portName)) { 284 inputMessage.setObjectPart("syncTimeout", "" + sps2); 285 } 286 if ("SOAPJMSPort3".equals(portName) 287 || "NativeJmsPort3".equals(portName) 288 || "SOAPJMSPort6".equals(portName) 289 || "NativeJmsPort6".equals(portName)) { 290 WSIFMessage context = operation.getContext(); 291 context.setObjectPart( 292 WSIFConstants.WSIF_PROP_SYNC_TIMEOUT, 293 "" + sps3); 294 operation.setContext(context); 295 } 296 297 Date first = new Date (); 299 boolean operationSucceeded = 300 operation.executeRequestResponseOperation( 301 inputMessage, 302 outputMessage, 303 faultMessage); 304 305 if (operationSucceeded) { 306 assertTrue("it didn't timeout!!", false); 307 } else { 308 Date second = new Date (); 309 310 DateFormat df = DateFormat.getDateTimeInstance(); 311 long diff = second.getTime() - first.getTime(); 312 System.out.println("diff=" + diff); 313 } 315 316 } catch (Exception e) { 317 e.printStackTrace(); 318 assertTrue("exception running tests-" + e.getMessage(), false); 319 } 320 321 } 322 323 private void testAsyncOPs(String portName, String protocol) { 324 if (portName.toUpperCase().indexOf("JMS") != -1 325 && !TestUtilities.areWeTesting("jms")) 326 return; 327 328 TestUtilities.setProviderForProtocol(protocol); 329 330 try { 331 WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); 332 WSIFService service = 333 factory.getService( 334 wsdlLocation, 335 null, 336 null, 337 "http://wsifservice.addressbook/", 338 "AddressBook"); 339 340 service.mapType( 341 new javax.xml.namespace.QName ( 342 "http://wsiftypes.addressbook/", 343 "address"), 344 Class.forName("addressbook.wsiftypes.Address")); 345 346 service.mapType( 347 new javax.xml.namespace.QName ( 348 "http://wsiftypes.addressbook/", 349 "phone"), 350 Class.forName("addressbook.wsiftypes.Phone")); 351 352 WSIFPort port = 353 (portName == null) 354 ? service.getPort() 355 : service.getPort(portName); 356 357 if (!port.supportsAsync()) { 358 return; 359 } 360 361 WSIFOperation op = port.createOperation("getAddressFromName"); 362 363 AsyncResponseHandler abHandler = new AsyncResponseHandler(1); 364 366 WSIFMessage inMsg = op.createInputMessage(); 367 inMsg.setObjectPart("name", "fred"); 368 369 WSIFMessage outmsg = op.createOutputMessage(); 370 WSIFMessage faultMsg = op.createFaultMessage(); 371 372 WSIFMessage context = op.getContext(); 373 context.setObjectPart( 374 WSIFConstants.CONTEXT_JMS_PREFIX + "JMSReplyTo", 375 TestUtilities.getWsifProperty("wsif.async.replytoq")); 376 377 if ("SOAPJMSPort2".equals(portName) 378 || "NativeJmsPort2".equals(portName)) { 379 inMsg.setObjectPart("asyncTimeout", "" + spa2); 380 } 381 if ("SOAPJMSPort3".equals(portName) 382 || "NativeJmsPort3".equals(portName) 383 || "SOAPJMSPort6".equals(portName) 384 || "NativeJmsPort6".equals(portName)) { 385 context.setObjectPart( 386 WSIFConstants.WSIF_PROP_ASYNC_TIMEOUT, 387 "" + spa3); 388 } 389 390 op.setContext(context); 391 392 WSIFCorrelationId id = 393 op.executeRequestResponseAsync(inMsg, abHandler); 394 assertTrue( 395 "null correlation id returned from async request!", 396 id != null); 397 398 int i = 30; 399 while (i-- > 0 && !abHandler.isDone()) { 400 System.out.println("waiting for async responses - " + i); 401 try { 402 Thread.sleep(1000); 403 } catch (InterruptedException ex) { 404 } 405 } 406 407 } catch (Exception ex) { 408 ex.printStackTrace(); 409 assertTrue("exception making async request!!", false); 410 } 411 } 412 438 439 } 440 | Popular Tags |