Source Code Cross Referenced for DummyClient.java in  » ESB » open-esb » testclient » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ESB » open esb » testclient 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)DummyClient.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package testclient;
030:
031:        import java.io.*;
032:
033:        import java.util.*;
034:
035:        import javax.jms.DeliveryMode;
036:        import javax.jms.JMSException;
037:        import javax.jms.Queue;
038:        import javax.jms.QueueConnection;
039:        import javax.jms.QueueConnectionFactory;
040:        import javax.jms.QueueReceiver;
041:        import javax.jms.QueueSender;
042:        import javax.jms.QueueSession;
043:        import javax.jms.Session;
044:        import javax.jms.TextMessage;
045:
046:        /*
047:         * @(#)DummyClient.java        1.5 04/09/15
048:         *
049:         * Copyright (c) 2001-2003 Sun Microsystems, Inc. All Rights Reserved.
050:         *
051:         * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
052:         * modify and redistribute this software in source and binary code form,
053:         * provided that i) this copyright notice and license appear on all copies of
054:         * the software; and ii) Licensee does not utilize the software in a manner
055:         * which is disparaging to Sun.
056:         *
057:         * This software is provided "AS IS," without a warranty of any kind. ALL
058:         * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
059:         * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
060:         * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
061:         * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
062:         * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
063:         * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
064:         * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
065:         * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
066:         * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
067:         * POSSIBILITY OF SUCH DAMAGES.
068:         *
069:         * This software is not designed or intended for use in on-line control of
070:         * aircraft, air traffic, aircraft navigation or aircraft communications; or in
071:         * the design, construction, operation or maintenance of any nuclear
072:         * facility. Licensee represents and warrants that it will not use or
073:         * redistribute the Software for such purposes.
074:         */
075:        import javax.naming.*;
076:
077:        /**
078:         * DOCUMENT ME!
079:         *
080:         * @author Sun Microsystems, Inc.
081:         */
082:        public class DummyClient {
083:            static String def_windows_url = "file:///";
084:            static String def_unix_url = "file:///tmp/imqobjects";
085:            static String OPERATION_NAMESPACE = "http://sun.com/testengine.wsdl";
086:
087:            /**
088:             *    
089:             */
090:            Queue receivequeue;
091:
092:            /**
093:             *
094:             */
095:
096:            /**
097:             *    
098:             */
099:            Queue sendqueue;
100:
101:            /**
102:             *    
103:             */
104:            Queue temporaryqueue;
105:
106:            /**
107:             *
108:             */
109:
110:            /**
111:             *    
112:             */
113:            QueueConnection queueConnection;
114:
115:            /**
116:             *
117:             */
118:
119:            /**
120:             *    
121:             */
122:            QueueConnectionFactory mQcf;
123:
124:            /**
125:             *
126:             */
127:
128:            /**
129:             *    
130:             */
131:            QueueReceiver queueReceiver;
132:
133:            QueueReceiver tmpReceiver;
134:
135:            /**
136:             *
137:             */
138:
139:            /**
140:             *    
141:             */
142:            QueueSender queueSender;
143:
144:            QueueSender tmpqueueSender;
145:
146:            /**
147:             *
148:             */
149:
150:            /**
151:             *    
152:             */
153:            QueueSession queueSession;
154:
155:            /**
156:             *
157:             */
158:
159:            /**
160:             *    
161:             */
162:            String MYQCF_LOOKUP_NAME = "MyQueueConnectionFactory";
163:
164:            /**
165:             *
166:             */
167:
168:            /**
169:             *    
170:             */
171:            String RECEIVE_QUEUE_LOOKUP_NAME = "receive_queue";
172:
173:            /**
174:             *
175:             */
176:
177:            /**
178:             *    
179:             */
180:            String SEND_QUEUE_LOOKUP_NAME = "send_queue";
181:
182:            /**
183:             *
184:             */
185:
186:            /**
187:             *    
188:             */
189:            String TEMP_QUEUE_LOOKUP_NAME = "external_queue";
190:
191:            /**
192:             *
193:             */
194:
195:            /**
196:             *    
197:             */
198:            TextMessage msg;
199:
200:            /**
201:             *
202:             */
203:
204:            /**
205:             *    
206:             */
207:            TextMessage rcvMsg;
208:
209:            /**
210:             *
211:             */
212:
213:            /**
214:             *    
215:             */
216:            private InitialContext mInitialContext;
217:
218:            /**
219:             * Creates a new DummyClient object.
220:             *
221:             * @param url
222:             */
223:            public DummyClient(String url) {
224:                Hashtable env;
225:                Context mInitialContext = null;
226:
227:                env = new Hashtable();
228:                env.put(Context.INITIAL_CONTEXT_FACTORY,
229:                        "com.sun.jndi.fscontext.RefFSContextFactory");
230:                env.put(Context.PROVIDER_URL, url);
231:
232:                try {
233:                    mInitialContext = new InitialContext(env);
234:                } catch (NamingException ne) {
235:                    System.err
236:                            .println(" JMS Client : Failed to create InitialContext.");
237:                    System.err
238:                            .println(" JMS Client : The Context.PROVIDER_URL used/specified was: "
239:                                    + url);
240:                    System.err
241:                            .println("Please make sure that the path to the above URL exists");
242:                    System.err
243:                            .println("and matches with the objstore.attrs.java.naming.provider.url");
244:                    System.err
245:                            .println("property value specified in the imqobjmgr command files:");
246:                    ne.printStackTrace();
247:                    System.exit(-1);
248:                }
249:
250:                try {
251:                    /*
252:                    System.out.println(
253:                        "Looking up Queue Connection Factory object with lookup name: "
254:                        + MYQCF_LOOKUP_NAME);
255:                     */
256:                    mQcf = (javax.jms.QueueConnectionFactory) mInitialContext
257:                            .lookup(MYQCF_LOOKUP_NAME);
258:                    //    System.out.println(" JMS Client : Queue Connection Factory object found.");
259:                } catch (NamingException ne) {
260:                    System.err
261:                            .println("Failed to lookup Queue Connection Factory object.");
262:                    ne.printStackTrace();
263:                    System.exit(-1);
264:                }
265:
266:                javax.jms.Queue response = null;
267:
268:                try {
269:                    /* System.out.println(" JMS Client : Looking up Queue object with lookup name: "
270:                         + MYQCF_LOOKUP_NAME);
271:                     */
272:                    sendqueue = (javax.jms.Queue) mInitialContext
273:                            .lookup(SEND_QUEUE_LOOKUP_NAME);
274:                    // System.out.println(" JMS Client : Send Queue object found.");
275:                    receivequeue = (javax.jms.Queue) mInitialContext
276:                            .lookup(RECEIVE_QUEUE_LOOKUP_NAME);
277:                    //System.out.println(" JMS Client : Receive Queue object found.");
278:                    temporaryqueue = (javax.jms.Queue) mInitialContext
279:                            .lookup(TEMP_QUEUE_LOOKUP_NAME);
280:                    //System.out.println(" JMS Client : Temporary Queue object found.");
281:                } catch (NamingException ne) {
282:                    System.err
283:                            .println(" JMS Client : Failed to lookup Queue object.");
284:                    System.err
285:                            .println("Please make sure you have created the Queue object using the command:");
286:                    System.err
287:                            .println(" JMS Client : \timqobjmgr -i add_q.props");
288:
289:                    System.err
290:                            .println(" JMS Client : \nThe exception details:");
291:                    ne.printStackTrace();
292:                    System.exit(-1);
293:                }
294:
295:                //System.out.println(" JMS Client : ");
296:
297:            }
298:
299:            /**
300:             * Creates a new doDummyOutOnly object.
301:             */
302:            private void doTestOutOnly() {
303:                try {
304:
305:                    // Tell the provider to start sending messages.
306:                    queueConnection.start();
307:
308:                    javax.jms.Message msg = tmpReceiver.receive(15000);
309:
310:                    if (msg == null) {
311:                        // System.out.println(" JMS Client : JMSTest Out only Failed");
312:
313:                        return;
314:                    } else {
315:                        //  System.out.println(" JMS Client : JMSTest Out only Passed");
316:                        msg.acknowledge();
317:                        return;
318:                    }
319:
320:                } catch (Exception e) {
321:                    System.out.println(" JMS Client : JMSTest Out only Failed");
322:
323:                    return;
324:                }
325:            }
326:
327:            /**
328:             * Creates a new doTestOutIn object.
329:             *
330:             * @param time
331:             */
332:            private void doTestOutIn(long time) {
333:                try {
334:
335:                    // Tell the provider to start sending messages.
336:                    queueConnection.start();
337:
338:                    javax.jms.Message msg = tmpReceiver.receive(time);
339:
340:                    if (msg == null) {
341:                        //  System.out.println(" JMS Client : JMSTest Out in Failed");
342:
343:                        return;
344:                    } else {
345:                        msg.acknowledge();
346:
347:                        if (msg instanceof  javax.jms.TextMessage) {
348:                            TextMessage txt = (TextMessage) msg;
349:                            javax.jms.Destination dest = msg.getJMSReplyTo();
350:                            TextMessage resp = queueSession.createTextMessage();
351:                            String s = txt.getText();
352:                            String reader = new String(
353:                                    "<?xml version=\"1.0\" encoding=\"UTF-8\"?><jbi:message xmlns:msgns=\"http://sun.com/testengine.wsdl\" type=\"msgns:transformOutput\" version=\"1.0\" xmlns:jbi=\"http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper\"><jbi:part><response>What is OpenESB</response></jbi:part></jbi:message>");
354:
355:                            if (s == null) {
356:                                resp
357:                                        .setText("<message>Cannot process Message</message>");
358:                                resp.setStringProperty("JBI_STATUS", "ERROR");
359:                            } else if (s.trim().indexOf(
360:                                    "<message>Bad_JMS_Message</message>") > 0) {
361:                                resp
362:                                        .setText("<message>Cannot process Message</message>");
363:                                resp.setStringProperty("JBI_STATUS", "FAULT");
364:                            } else {
365:                                resp.setText(reader);
366:                                resp.setStringProperty("JBI_STATUS", "SUCCESS");
367:                            }
368:
369:                            /*System.out.println("JMS Client : Sending out in response to" 
370:                                + dest.toString());
371:                             */
372:                            /** set the correlation id
373:                             */
374:                            resp.setJMSCorrelationID(txt.getJMSCorrelationID());
375:
376:                            tmpqueueSender = (QueueSender) queueSession
377:                                    .createProducer(dest);
378:                            tmpqueueSender.send(resp);
379:                            tmpqueueSender.close();
380:                            // System.out.println(" JMS Client : JMSTest Out in Success");
381:                        } else {
382:                            //  System.out.println(" JMS Client : JMSTest Out in Failed");
383:                        }
384:
385:                        return;
386:                    }
387:
388:                } catch (Exception e) {
389:                    System.out.println(" JMS Client : JMSTest Out in Failed");
390:                    e.printStackTrace();
391:
392:                    return;
393:                }
394:            }
395:
396:            /**
397:             * Creates a new doTestRobustOutOnly object.
398:             *
399:             * @param time
400:             */
401:            private void doTestRobustOutOnly(long time) {
402:                try {
403:
404:                    // Tell the provider to start sending messages.
405:                    queueConnection.start();
406:
407:                    javax.jms.Message msg = tmpReceiver.receive(time);
408:
409:                    if (msg == null) {
410:                        //  System.out.println(" JMS Client : JMSTest Robust Out only Failed");
411:
412:                        return;
413:                    } else {
414:                        msg.acknowledge();
415:
416:                        if (msg instanceof  javax.jms.TextMessage) {
417:                            TextMessage txt = (TextMessage) msg;
418:                            javax.jms.Destination dest = msg.getJMSReplyTo();
419:                            TextMessage resp = queueSession.createTextMessage();
420:                            String s = txt.getText();
421:
422:                            if (s == null) {
423:                                resp
424:                                        .setText("<message>Cannot process Message</message>");
425:                                resp.setStringProperty("JBI_STATUS", "ERROR");
426:                            } else if (s.trim().indexOf(
427:                                    "<message>Bad_JMS_Message</message>") > 0) {
428:                                resp
429:                                        .setText("<message>Cannot process Message</message>");
430:                                resp.setStringProperty("JBI_STATUS", "FAULT");
431:                            } else {
432:                                //  System.out.println(" JMS Client : JMSTest Robust Out Only Success");
433:
434:                                return;
435:                            }
436:
437:                            resp.setJMSCorrelationID(txt.getJMSCorrelationID());
438:                            tmpqueueSender = (QueueSender) queueSession
439:                                    .createProducer(dest);
440:                            tmpqueueSender.send(resp);
441:                            tmpqueueSender.close();
442:                            //  System.out.println(" JMS Client : JMSTest Robust Out Only Success");
443:                        } else {
444:                            // System.out.println(" JMS Client : JMSTest Robust Out Only Failed");
445:                        }
446:
447:                        return;
448:                    }
449:
450:                } catch (Exception e) {
451:                    System.out
452:                            .println(" JMS Client : JMSTest Robust Out only Failed");
453:                    e.printStackTrace();
454:
455:                    return;
456:                }
457:            }
458:
459:            private void doTests() {
460:                if (!init()) {
461:                    System.out
462:                            .println(" JMS Client : JMS Client : Cannot initialize");
463:                    System.exit(-1);
464:                }
465:
466:                //System.out.println(" JMS Client : Test 1: Test Out only");
467:                doTestOutOnly();
468:                //System.out.println(" JMS Client : Test 2: Test Good Out in");
469:                doTestOutIn(3000);
470:                //System.out.println(" JMS Client : Test 3: Test Bad Out in");
471:                doTestOutIn(3000);
472:
473:                try {
474:                    // Wait for sometime before starting other tests
475:                    Thread.sleep(3000);
476:                } catch (Exception e) {
477:                    ;
478:                }
479:                //System.out.println(" JMS Client : Test 6: Test In only");
480:                doTestInOnly(3000);
481:                //System.out.println(" JMS Client : Test 7: Test Good in out");
482:                doTestGoodInOut(3000);
483:
484:                if (!cleanup()) {
485:                    System.out
486:                            .println(" JMS Client : JMS Client : Cannot clean up");
487:                }
488:
489:            }
490:
491:            /**
492:             * DOCUMENT ME!
493:             *
494:             * @param args NOT YET DOCUMENTED
495:             */
496:            public static void main(String[] args) {
497:                String url = def_unix_url;
498:
499:                if (args.length > 0) {
500:                    url = args[0];
501:                }
502:
503:                DummyClient simple_client = new DummyClient(url);
504:
505:                //WSDL 11 tests
506:
507:                simple_client.doTests();
508:
509:                //WSDL 20 tests
510:                //        simple_client.doTests();
511:            }
512:
513:            /**
514:             *
515:             *
516:             * @return  NOT YET DOCUMENTED
517:             */
518:            private String getBadString() {
519:                String s = new String("<message>Bad_JMS_Message</message>");
520:
521:                return s;
522:            }
523:
524:            /**
525:             * DOCUMENT ME!
526:             *
527:             * @return NOT YET DOCUMENTED
528:             */
529:            private String getString() {
530:                /*
531:                   File f = new File("sample.xml");
532:                   FileReader reader = null;
533:                   char [] buf = new char[2048];
534:                   try
535:                   {
536:                   reader = new FileReader(f);
537:                   reader.read(buf, 0, 2000);
538:                   }
539:                   catch (Exception e)
540:                   {
541:                           e.printStackTrace();
542:                   }
543:                
544:                   String s = new String(buf);
545:                   System.out.println(" JMS Client : Sending " + s);
546:                 */
547:                String s = new String(
548:                        "<?xml version=\"1.0\" encoding=\"UTF-8\"?><jbi:message xmlns:msgns=\"http://sun.com/testengine.wsdl\" type=\"msgns:transformInput\" version=\"1.0\" xmlns:jbi=\"http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper\"><jbi:part><request>What is OpenESB</request></jbi:part></jbi:message>");
549:
550:                return s;
551:            }
552:
553:            /**
554:             *
555:             *
556:             * @param time  NOT YET DOCUMENTED
557:             */
558:            private void doTestBadInOut(long time) {
559:                try {
560:
561:                    TextMessage msg = queueSession
562:                            .createTextMessage(getBadString());
563:                    msg.setStringProperty("JBI_OPERATION", "getMessageInOut");
564:                    msg.setStringProperty("JBI_OPERATION_NAMESPACE",
565:                            OPERATION_NAMESPACE);
566:                    msg.setJMSReplyTo(receivequeue);
567:
568:                    /*   System.out.println(" JMS Client : Publishing a message to Queue: "
569:                           + sendqueue.getQueueName());
570:                     */
571:                    queueSender.send(msg, DeliveryMode.NON_PERSISTENT, 4, 0);
572:                    // Wait for it to be sent back.
573:
574:                    TextMessage rcvMsg = (TextMessage) queueReceiver
575:                            .receive(time);
576:
577:                    if (rcvMsg == null) {
578:                        // System.out.println(" JMS Client : JMSTest Bad inout success");
579:
580:                        return;
581:                    }
582:
583:                    String status = null;
584:
585:                    try {
586:                        rcvMsg.acknowledge();
587:                        status = rcvMsg.getStringProperty("JBI_STATUS");
588:                    } catch (JMSException e) {
589:                        e.printStackTrace();
590:                    }
591:
592:                    if (status == null) {
593:                        //  System.out.println(" JMS Client : JMSTest Bad inout failed");
594:                    } else if (status.trim().equals("ERROR")) {
595:                        //  System.out.println(" JMS Client : JMSTest Bad inout success");
596:                    } else if (status.trim().equals("FAULT")) {
597:                        // System.out.println(" JMS Client : JMSTest Bad inout success");
598:                    } else {
599:                        //    System.out.println(" JMS Client : JMSTest Bad inout failed");
600:                    }
601:
602:                } catch (JMSException e) {
603:                    System.err.println(" JMS Client : JMS Exception: " + e);
604:                    e.printStackTrace();
605:                    System.exit(-1);
606:                }
607:            }
608:
609:            /**
610:             *
611:             *
612:             * @param time  NOT YET DOCUMENTED
613:             */
614:            private void doTestBadRobustInOnly(long time) {
615:                try {
616:
617:                    TextMessage msg = queueSession
618:                            .createTextMessage(getBadString());
619:                    msg.setStringProperty("JBI_OPERATION",
620:                            "getMessageRobustInOnly");
621:                    msg.setStringProperty("JBI_OPERATION_NAMESPACE",
622:                            OPERATION_NAMESPACE);
623:                    msg.setJMSReplyTo(receivequeue);
624:
625:                    /* System.out.println(" JMS Client : Publishing a message to Queue: "
626:                         + sendqueue.getQueueName());
627:                     */
628:                    queueSender.send(msg, DeliveryMode.NON_PERSISTENT, 4, 0);
629:                    // Wait for it to be sent back.
630:
631:                    TextMessage rcvMsg = null;
632:                    rcvMsg = (TextMessage) queueReceiver.receive(time);
633:
634:                    if (rcvMsg == null) {
635:                        //  System.out.println(" JMS Client : JMSTest Bad robust in only failed");
636:
637:                        return;
638:                    } else {
639:                        String status = null;
640:
641:                        try {
642:                            rcvMsg.acknowledge();
643:                            status = rcvMsg.getStringProperty("JBI_STATUS");
644:                        } catch (JMSException e) {
645:                            e.printStackTrace();
646:                        }
647:
648:                        if (status == null) {
649:                            //  System.out.println(" JMS Client : JMSTest Bad robust inonly failed");
650:                        } else if (status.trim().equals("ERROR")) {
651:                            //    System.out.println(" JMS Client : JMSTest Bad robust inonly success");
652:                        } else if (status.trim().equals("FAULT")) {
653:                            //  System.out.println(" JMS Client : JMSTest Bad robust inonly success");
654:                        } else {
655:                            // System.out.println(" JMS Client : JMSTest Bad robust inonly failed");
656:                        }
657:                    }
658:
659:                } catch (JMSException e) {
660:                    System.out
661:                            .println(" JMS Client : JMSTest Bad robust inonly failed");
662:                    System.err.println(" JMS Client : JMS Exception: " + e);
663:                    e.printStackTrace();
664:                    System.exit(-1);
665:                }
666:            }
667:
668:            /**
669:             *
670:             *
671:             * @param time  NOT YET DOCUMENTED
672:             */
673:            private void doTestGoodRobustInOnly(long time) {
674:                try {
675:
676:                    TextMessage msg = queueSession
677:                            .createTextMessage(getString());
678:                    msg.setStringProperty("JBI_OPERATION",
679:                            "getMessageRobustInOnly");
680:                    msg.setStringProperty("JBI_OPERATION_NAMESPACE",
681:                            OPERATION_NAMESPACE);
682:                    msg.setJMSReplyTo(receivequeue);
683:
684:                    /* System.out.println(" JMS Client : Publishing a message to Queue: "
685:                         + sendqueue.getQueueName());
686:                     */
687:                    queueSender.send(msg, DeliveryMode.NON_PERSISTENT, 4, 0);
688:                    // Wait for it to be sent back.
689:
690:                    TextMessage rcvMsg = null;
691:                    rcvMsg = (TextMessage) queueReceiver.receive(time);
692:
693:                    if (rcvMsg == null) {
694:                        //  System.out.println(" JMS Client : JMSTest Good robust in only success");
695:
696:                        return;
697:                    } else {
698:                        //  System.out.println(" JMS Client : JMSTest Good robust in only failed");
699:                        rcvMsg.acknowledge();
700:
701:                        return;
702:                    }
703:
704:                } catch (JMSException e) {
705:                    System.err.println(" JMS Client : JMS Exception: " + e);
706:                    e.printStackTrace();
707:                    System.exit(-1);
708:                }
709:            }
710:
711:            /**
712:             *
713:             *
714:             * @param time  NOT YET DOCUMENTED
715:             */
716:            private void doTestInOnly(long time) {
717:                try {
718:
719:                    TextMessage msg = queueSession
720:                            .createTextMessage(getString());
721:                    msg.setStringProperty("JBI_OPERATION", "getMessageInOnly");
722:                    msg.setStringProperty("JBI_OPERATION_NAMESPACE",
723:                            OPERATION_NAMESPACE);
724:                    /*  System.out.println(" JMS Client : Publishing a message to Queue: "
725:                          + sendqueue.getQueueName());
726:                     */
727:                    queueSender.send(msg, DeliveryMode.NON_PERSISTENT, 4, 0);
728:                    // System.out.println(" JMS Client : JMSTest In only success");
729:                } catch (JMSException e) {
730:                    System.out.println(" JMS Client : JMSTest Inponly failed");
731:                    System.err.println(" JMS Client : JMS Exception: " + e);
732:                    e.printStackTrace();
733:                    System.exit(-1);
734:                }
735:            }
736:
737:            /**
738:             * DOCUMENT ME!
739:             *
740:             * @param time NOT YET DOCUMENTED
741:             */
742:            private void doTestGoodInOut(long time) {
743:                try {
744:
745:                    TextMessage msg = queueSession
746:                            .createTextMessage(getString());
747:                    msg.setStringProperty("JBI_OPERATION", "getMessageInOut");
748:                    msg.setStringProperty("JBI_OPERATION_NAMESPACE",
749:                            OPERATION_NAMESPACE);
750:                    msg.setJMSReplyTo(receivequeue);
751:
752:                    /* System.out.println(" JMS Client : Publishing a message to Queue: "
753:                         + sendqueue.getQueueName());
754:                     */
755:                    queueSender.send(msg, DeliveryMode.NON_PERSISTENT, 4, 0);
756:                    // Wait for it to be sent back.
757:
758:                    TextMessage rcvMsg = (TextMessage) queueReceiver
759:                            .receive(time);
760:
761:                    if (rcvMsg == null) {
762:                        //  System.out.println(" JMS Client : JMSTest Good inout success");
763:
764:                        return;
765:                    }
766:
767:                    String status = null;
768:
769:                    try {
770:                        rcvMsg.acknowledge();
771:                        status = rcvMsg.getStringProperty("JBI_STATUS");
772:                    } catch (JMSException e) {
773:                        e.printStackTrace();
774:                    }
775:
776:                    if (status == null) {
777:                        // System.out.println(" JMS Client : JMSTest Good inout success");
778:                    } else if (status.trim().equals("ERROR")) {
779:                        // System.out.println(" JMS Client : Error status ");
780:                    } else if (status.trim().equals("FAULT")) {
781:                        // System.out.println(" JMS Client : Fault staus");
782:                    } else {
783:                        // System.out.println(" JMS Client : JMSTest Good inout success");
784:                    }
785:
786:                } catch (JMSException e) {
787:                    System.err.println(" JMS Client : JMS Exception: " + e);
788:                    e.printStackTrace();
789:                    System.exit(-1);
790:                }
791:            }
792:
793:            private boolean cleanup() {
794:                try {
795:                    queueReceiver.close();
796:                    queueSender.close();
797:                    tmpReceiver.close();
798:                    queueSession.close();
799:                    queueConnection.close();
800:                } catch (Exception e) {
801:                    return false;
802:                }
803:                return true;
804:            }
805:
806:            private boolean init() {
807:                try {
808:                    queueConnection = mQcf.createQueueConnection();
809:                    queueSession = queueConnection.createQueueSession(false,
810:                            Session.AUTO_ACKNOWLEDGE);
811:                    queueSender = queueSession.createSender(sendqueue);
812:                    queueReceiver = queueSession.createReceiver(receivequeue);
813:                    tmpReceiver = queueSession.createReceiver(temporaryqueue);
814:                } catch (JMSException e) {
815:                    System.err
816:                            .println(" JMS Client : Failed to create connection.");
817:                    System.err
818:                            .println(" JMS Client : Please make sure that the broker was started.");
819:
820:                    System.err
821:                            .println(" JMS Client : \nThe exception details:");
822:                    e.printStackTrace();
823:                    return false;
824:
825:                }
826:                return true;
827:            }
828:
829:            private boolean closeSender() {
830:                try {
831:                    queueSender.close();
832:                } catch (Exception e) {
833:                    return false;
834:                }
835:                return true;
836:            }
837:
838:            /**
839:             *
840:             */
841:            private void usage() {
842:                System.err.println(" JMS Client : Usage: "
843:                        + "\tjava TestClient[Context.PROVIDER_URL]\n"
844:                        + "\nOn Unix:\n\tjava TestClient" + def_unix_url
845:                        + "\nOn Windows:\n\tjava TestClient" + def_windows_url);
846:            }
847:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.