Source Code Cross Referenced for FooEngine.java in  » ESB » open-esb » testengine2 » 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 » testengine2 
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:         * @(#)FooEngine.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package testengine2;
030:
031:        import org.w3c.dom.Document;
032:        import org.w3c.dom.DocumentFragment;
033:
034:        import java.io.File;
035:
036:        import java.util.ArrayList;
037:        import java.util.HashMap;
038:        import java.util.Iterator;
039:        import java.util.LinkedList;
040:        import java.util.Set;
041:        import java.util.logging.Logger;
042:
043:        import javax.jbi.component.Component;
044:        import javax.jbi.component.ComponentContext;
045:        import javax.jbi.component.ComponentLifeCycle;
046:        import javax.jbi.messaging.DeliveryChannel;
047:        import javax.jbi.messaging.ExchangeStatus;
048:        import javax.jbi.messaging.Fault;
049:        import javax.jbi.messaging.InOnly;
050:        import javax.jbi.messaging.InOut;
051:        import javax.jbi.messaging.MessageExchange;
052:        import javax.jbi.messaging.MessageExchangeFactory;
053:        import javax.jbi.messaging.MessagingException;
054:        import javax.jbi.messaging.NormalizedMessage;
055:        import javax.jbi.messaging.RobustInOnly;
056:
057:        import javax.jbi.servicedesc.ServiceEndpoint;
058:
059:        import javax.xml.namespace.QName;
060:
061:        /**
062:         * This class implements EngineLifeCycle. The JBI framework will start this
063:         * engine class automatically when JBI framework starts up.
064:         *
065:         * @author Sun Microsystems, Inc.
066:         */
067:        public class FooEngine implements  ComponentLifeCycle, Component {
068:            /**
069:             * In Only MEP.
070:             */
071:            public static final String IN_ONLY = "http://www.w3.org/ns/wsdl/in-only";
072:
073:            /**
074:             * In Out MEP.
075:             */
076:            public static final String IN_OUT = "http://www.w3.org/ns/wsdl/in-out";
077:
078:            /**
079:             * In Optional Out MEP.
080:             */
081:            public static final String IN_OPTIONAL_OUT = "http://www.w3.org/ns/wsdl/in-opt-out";
082:
083:            /**
084:             * Robust In Only MEP.
085:             */
086:            public static final String ROBUST_IN_ONLY = "http://www.w3.org/ns/wsdl/robust-in-only";
087:
088:            /**
089:             *    
090:             */
091:            private static final String INOUT_SERVICE_NAME = "test:inoutservice";
092:
093:            /**
094:             *    
095:             */
096:            private static final String INONLY_SERVICE_NAME = "test:inonlyservice";
097:
098:            /**
099:             *    
100:             */
101:            private static final String ROBUSTINONLY_SERVICE_NAME = "test:robustinonlyservice";
102:
103:            /**
104:             *    
105:             */
106:            private static final String OUTBOUND_SERVICE_NAME = "AdaptionService";
107:
108:            private static final String OUTBOUND_SERVICE_NAMESPACE = "http://www.sun.com/jbi/servicelist.wsdl";
109:            /**
110:             *    
111:             */
112:            private static final String ENDPOINT = "testendpoint";
113:
114:            /**
115:             *    
116:             */
117:            public Thread mRecv;
118:
119:            /**
120:             *    
121:             */
122:            private ServiceEndpoint mEndpoint;
123:
124:            /**
125:             *
126:             */
127:
128:            /**
129:             *    
130:             */
131:            private DeliveryChannel mChannel;
132:
133:            /**
134:             *    
135:             */
136:            private MessageExchangeFactory mFactory;
137:
138:            /**
139:             * Environment conext passed down from framework to this stockquote engine.
140:             */
141:            private ComponentContext mContext = null;
142:
143:            /**
144:             * Refernce to logger.
145:             */
146:            private Logger mLog = null;
147:
148:            /**
149:             *    
150:             */
151:            private MessageExchange mReq;
152:
153:            /**
154:             *    
155:             */
156:            private ServiceEndpoint mInonlyReference;
157:
158:            /**
159:             *    
160:             */
161:            private ServiceEndpoint mInoutReference;
162:
163:            /**
164:             *    
165:             */
166:            private ServiceEndpoint mOutboundReference;
167:
168:            /**
169:             *    
170:             */
171:            private ServiceEndpoint mRobustinonlyReference;
172:
173:            /**
174:             *    
175:             */
176:            private boolean mRunFlag = true;
177:
178:            /**
179:             * Get the JMX ObjectName for the DeploymentMBean for this BPE. If there is
180:             * none, return null.
181:             *
182:             * @return ObjectName the JMX object name of the DeploymentMBean or null if
183:             *         there is no DeploymentMBean.
184:             */
185:            public javax.management.ObjectName getDeploymentMBeanName() {
186:                return null;
187:            }
188:
189:            /**
190:             * Get the JMX ObjectName for any additional MBean for this BC. If there is
191:             * none, return null.
192:             *
193:             * @return ObjectName the JMX object name of the additional MBean or null
194:             *         if there is no additional MBean.
195:             */
196:            public javax.management.ObjectName getExtensionMBeanName() {
197:                return null;
198:            }
199:
200:            /**
201:             * Initialize the test engine. This performs initialization required
202:             *
203:             * @param jbiContext the JBI environment mContext
204:             *
205:             * @throws javax.jbi.JBIException if the stockquote engine is unable to
206:             *         initialize.
207:             */
208:            public void init(javax.jbi.component.ComponentContext jbiContext)
209:                    throws javax.jbi.JBIException {
210:                mLog = Logger.getLogger(this .getClass().getPackage().getName());
211:                mLog.info("test engine INIT invoked");
212:
213:                if (jbiContext == null) {
214:                    throw (new javax.jbi.JBIException("Context is null",
215:                            new NullPointerException()));
216:                }
217:
218:                /* Assign values */
219:                mContext = jbiContext;
220:                Payload.mDefaultPath = mContext.getInstallRoot()
221:                        + File.separatorChar + "testengine2"
222:                        + File.separatorChar + "payload.xml";
223:                mLog.info(" INIT METHOD FINISHED ");
224:            }
225:
226:            /**
227:             * Shutdown the SE. This performs cleanup before the SE is terminated.
228:             * Once this has been called, init() must be called before the SE can be
229:             * started again with a call to start().
230:             *
231:             * @throws javax.jbi.JBIException if the SE is unable to shut down.
232:             */
233:            public void shutDown() throws javax.jbi.JBIException {
234:                mLog.info("test Engine Shutdown-Start");
235:                mLog.info("test Engine Shutdown-End");
236:            }
237:
238:            /**
239:             */
240:            public void start() throws javax.jbi.JBIException {
241:                mLog.info(" Test  ENGINE INVOKED ");
242:
243:                try {
244:                    mChannel = mContext.getDeliveryChannel();
245:                    mFactory = mChannel.createExchangeFactory();
246:                    /*mOutboundReference =
247:                        mChannel.activateEndpoint(new QName(OUTBOUND_SERVICE_NAMESPACE,
248:                                OUTBOUND_SERVICE_NAME), OUTBOUND_SERVICE_NAME);
249:                     */
250:                } catch (MessagingException me) {
251:                    me.printStackTrace();
252:                }
253:
254:                if (mChannel == null) {
255:                    mLog.severe("Cannot get Engine Channel from context ");
256:
257:                    return;
258:                }
259:
260:                doTestOutIn();
261:
262:                //  doTestOutOnly();
263:                /*
264:                   doTestGoodRobustOutOnly();
265:                
266:                   doTestBadRobustOutOnly();
267:                
268:                   mRecv = new Thread(new Receiver());
269:                   mRecv.start();
270:                
271:                   String compRoot = mContext.getComponentRoot();
272:                 */
273:                mLog.info(" START FINISHED  ");
274:            }
275:
276:            /**
277:             */
278:            public void stop() throws javax.jbi.JBIException {
279:                mLog.info("STOP INVOKED ");
280:                mRunFlag = false;
281:
282:                try {
283:                    mRecv.interrupt();
284:                    mRecv.join();
285:                } catch (Exception e) {
286:                    ;
287:                }
288:
289:                mLog.info(" STOP FINISHED ");
290:            }
291:
292:            /**
293:             *
294:             */
295:            private void doTestGoodInOnly() {
296:                /* start accpeting the in-only, in-out and robust in-only
297:                 */
298:                try {
299:                    InOnly inonly = (InOnly) mReq;
300:
301:                    if (inonly.getInMessage() == null) {
302:                        mLog.info("Test-GOODINONLY-Failed");
303:
304:                        return;
305:                    }
306:
307:                    if (inonly.getInMessage().getContent() == null) {
308:                        mLog.info("Test-GOODINONLY-Failed");
309:
310:                        return;
311:                    }
312:
313:                    inonly.setStatus(ExchangeStatus.DONE);
314:                    mChannel.send(inonly);
315:                    mLog.info("Test-GOODINONLY-Passed");
316:                } catch (Exception e) {
317:                    mLog.severe("Test-GOODINONLY-threw-Exception"
318:                            + e.getMessage());
319:                    e.printStackTrace();
320:                }
321:            }
322:
323:            /**
324:             *
325:             */
326:            private void doTestGoodInOut() {
327:                /* start accpeting the in-only, in-out and robust in-only
328:                 */
329:                try {
330:                    InOut inout = (InOut) mReq;
331:
332:                    if (inout.getStatus() == ExchangeStatus.DONE) {
333:                        mLog.info("Test-GOODINOUT-Passed");
334:
335:                        return;
336:                    }
337:
338:                    if (inout.getStatus() == ExchangeStatus.ERROR) {
339:                        mLog.info("Test-GOODINOUT-Failed");
340:
341:                        return;
342:                    }
343:
344:                    if (inout.getInMessage() == null) {
345:                        mLog.info("Test-GOODINOUT-Failed");
346:
347:                        return;
348:                    }
349:
350:                    inout.setOutMessage(inout.getInMessage());
351:                    mChannel.send(inout);
352:                } catch (Exception e) {
353:                    mLog.severe("Test-GOODINOUT-threw-Exception"
354:                            + e.getMessage());
355:                    e.printStackTrace();
356:                }
357:            }
358:
359:            /**
360:             *
361:             */
362:            private void doTestGoodRobustInOnly() {
363:                /* start accpeting the in-only, in-out and robust in-only
364:                 */
365:                try {
366:                    RobustInOnly robinonly = (RobustInOnly) mReq;
367:
368:                    if (robinonly.getInMessage() == null) {
369:                        mLog.info("Test-GOODROBUSTINONLY-Failed");
370:                        robinonly.setError(new Exception("Message is null"));
371:                        mChannel.send(robinonly);
372:
373:                        return;
374:                    }
375:
376:                    if (robinonly.getInMessage().getContent() == null) {
377:                        mLog.info("Test-GOODROBUSTINONLY-Failed");
378:
379:                        return;
380:                    }
381:
382:                    robinonly.setStatus(ExchangeStatus.DONE);
383:                    mChannel.send(robinonly);
384:                    mLog.info("Test-GOODROBUSTINONLY-Passed");
385:                } catch (Exception e) {
386:                    mLog.severe("Test-GOODROBUSTINONLY-threw-Exception"
387:                            + e.getMessage());
388:                    e.printStackTrace();
389:                }
390:            }
391:
392:            /**
393:             *
394:             */
395:            private void doTestOutIn() {
396:                mLog.info("Test engine sending good out-in message to engine");
397:
398:                NormalizedMessage outMsg;
399:                InOut inout;
400:
401:                try {
402:                    // create the exchange
403:                    inout = mFactory.createInOutExchange();
404:                    outMsg = inout.createMessage();
405:
406:                    // set the stuff we know
407:                    //outIn.setService(mOutboundReference);
408:                    inout.setOperation(new QName(OUTBOUND_SERVICE_NAMESPACE,
409:                            "inputxml"));
410:
411:                    //ServiceEndpoint [] mEndpoint;
412:                    ServiceEndpoint mEndpoint;
413:
414:                    // lookup the endpoint reference and set on exchange
415:                    mEndpoint = mContext.getEndpointsForService(new QName(
416:                            OUTBOUND_SERVICE_NAMESPACE, OUTBOUND_SERVICE_NAME))[0];
417:
418:                    /*
419:                     for (int i = 0; i < mEndpoint.length; i++)
420:                     {
421:                     if (mEndpoint[i].isLocal())
422:                     {
423:                     outIn.setEndpoint(mEndpoint[i]);
424:                     }
425:                     }
426:                     */
427:                    // set the payload
428:                    Payload.setPayload(outMsg);
429:                    inout.setService(new QName(OUTBOUND_SERVICE_NAMESPACE,
430:                            OUTBOUND_SERVICE_NAME));
431:                    inout.setEndpoint(mEndpoint);
432:                    // set the message on the exchange
433:                    inout.setInMessage(outMsg);
434:
435:                    // send the exchange
436:                    mChannel.send(inout);
437:
438:                    // receive the response
439:                    inout = (InOut) mChannel.accept();
440:
441:                    if (inout.getStatus() == ExchangeStatus.ERROR) {
442:                        mLog.info("Test-SEQ-GOODOUTIN-Failed");
443:
444:                        return;
445:                    } else if (inout.getStatus() == ExchangeStatus.ACTIVE) {
446:                        if (inout.getOutMessage() != null) {
447:                            mLog.info("Test-SEQ-GOODOUTIN-Passed");
448:                        } else {
449:                            mLog.info("Test-SEQ-GOODOUTIN-Failed");
450:                        }
451:                    }
452:
453:                    inout.setStatus(ExchangeStatus.DONE);
454:                    mChannel.send(inout);
455:                } catch (Exception e) {
456:                    mLog.severe("Test-SEQ-GOODOUTIN-threw-Exception");
457:                    e.printStackTrace();
458:                }
459:            }
460:
461:            /**
462:             *   
463:             *
464:             * @author Sun Microsystems, Inc.
465:             * 
466:             */
467:            public class Receiver implements  Runnable {
468:                /**
469:                 *
470:                 */
471:                public void run() {
472:                    mLog.info("Test engine receiver started");
473:
474:                    try {
475:                        while (mRunFlag) {
476:                            mReq = mChannel.accept();
477:                            mLog.info("Got message i test ebgine");
478:
479:                            if (mReq instanceof  InOut) {
480:                                doTestGoodInOut();
481:                            } else if (mReq instanceof  InOnly) {
482:                                doTestGoodInOnly();
483:                            } else if (mReq instanceof  RobustInOnly) {
484:                                doTestGoodRobustInOnly();
485:                            }
486:                        }
487:                    } catch (Exception e) {
488:                        mLog.severe("Exception at receiver");
489:                        mLog.info("Test engine receiver ended");
490:                    }
491:                }
492:            }
493:
494:            public javax.jbi.component.ComponentLifeCycle getLifeCycle() {
495:                return this ;
496:            }
497:
498:            public javax.jbi.component.ServiceUnitManager getServiceUnitManager() {
499:                return null;
500:            }
501:
502:            public org.w3c.dom.Document getServiceDescription(
503:                    javax.jbi.servicedesc.ServiceEndpoint ServiceEndpoint) {
504:                return null;
505:            }
506:
507:            /** This method is called by JBI to check if this component, in the role of
508:             *  provider of the service indicated by the given exchange, can actually 
509:             *  perform the operation desired. 
510:             */
511:            public boolean isExchangeWithConsumerOkay(
512:                    javax.jbi.servicedesc.ServiceEndpoint endpoint,
513:                    javax.jbi.messaging.MessageExchange exchange) {
514:                return true;
515:            }
516:
517:            /** This method is called by JBI to check if this component, in the role of
518:             *  consumer of the service indicated by the given exchange, can actually 
519:             *  interact with the the provider completely. 
520:             */
521:            public boolean isExchangeWithProviderOkay(
522:                    javax.jbi.servicedesc.ServiceEndpoint endpoint,
523:                    javax.jbi.messaging.MessageExchange exchange) {
524:                return true;
525:            }
526:
527:            /**
528:             * Resolve the given endpoint reference, given the capabilities of the
529:             * given consumer. This is called by JBI when it is attempting to resolve
530:             * the given endpoint reference on behalf of a component.
531:             * @param epr the endpoint reference, in some XML dialect understood by the
532:             * appropriate component (usually a Binding Component).
533:             * @return the service endpoint for the endpoint reference;
534:             * <code>null</code> if the endpoint reference cannot be resolved.
535:             */
536:            public ServiceEndpoint resolveEndpointReference(DocumentFragment epr) {
537:                return null;
538:            }
539:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.