Source Code Cross Referenced for FooEngine.java in  » ESB » open-esb » testengine1 » 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 » testengine1 
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 testengine1;
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:        import javax.jbi.component.Component;
043:        import javax.jbi.component.ComponentContext;
044:        import javax.jbi.component.ComponentLifeCycle;
045:        import javax.jbi.messaging.DeliveryChannel;
046:        import javax.jbi.messaging.ExchangeStatus;
047:        import javax.jbi.messaging.Fault;
048:        import javax.jbi.messaging.InOnly;
049:        import javax.jbi.messaging.InOut;
050:        import javax.jbi.messaging.MessageExchange;
051:        import javax.jbi.messaging.MessagingException;
052:        import javax.jbi.messaging.NormalizedMessage;
053:        import javax.jbi.messaging.RobustInOnly;
054:
055:        import javax.jbi.servicedesc.ServiceEndpoint;
056:
057:        import javax.xml.namespace.QName;
058:
059:        /**
060:         * This class implements EngineLifeCycle. The JBI framework will start this
061:         * engine class automatically when JBI framework starts up.
062:         *
063:         * @author Sun Microsystems, Inc.
064:         */
065:        public class FooEngine implements  ComponentLifeCycle, Component {
066:            /**
067:             * In Only MEP.
068:             */
069:            public static final String IN_ONLY = "http://www.w3.org/ns/wsdl/in-only";
070:
071:            /**
072:             * In Out MEP.
073:             */
074:            public static final String IN_OUT = "http://www.w3.org/ns/wsdl/in-out";
075:
076:            /**
077:             * In Optional Out MEP.
078:             */
079:            public static final String IN_OPTIONAL_OUT = "http://www.w3.org/ns/wsdl/in-opt-out";
080:
081:            /**
082:             * Robust In Only MEP.
083:             */
084:            public static final String ROBUST_IN_ONLY = "http://www.w3.org/ns/wsdl/robust-in-only";
085:
086:            /**
087:             *    
088:             */
089:            private static final String INOUT_SERVICE_NAME = "OnlineStockService";
090:
091:            /**
092:             *    
093:             */
094:            private static final String INOUT_SERVICE_NAMESPACE = "http://www.example.org/stock.wsdl";
095:            /**
096:             *    
097:             */
098:            private static final String INONLY_SERVICE_NAME = "stock:OnlineStockService";
099:
100:            /**
101:             *    
102:             */
103:            private static final String ROBUSTINONLY_SERVICE_NAME = "test:robustinonlyservice";
104:
105:            /**
106:             *    
107:             */
108:            private static final String OUTBOUND_SERVICE_NAME = "test:outboundservice";
109:
110:            /**
111:             *    
112:             */
113:            private static final String ENDPOINT = "testendpoint";
114:
115:            /**
116:             *    
117:             */
118:            public Thread mRecv;
119:
120:            /**
121:             *    
122:             */
123:            private ServiceEndpoint mEndpoint;
124:
125:            /**
126:             *
127:             */
128:
129:            /**
130:             *    
131:             */
132:            private DeliveryChannel mChannel;
133:
134:            /**
135:             * Environment conext passed down from framework to this stockquote engine.
136:             */
137:            private ComponentContext mContext = null;
138:
139:            /**
140:             * Refernce to logger.
141:             */
142:            private Logger mLog = null;
143:
144:            /**
145:             *    
146:             */
147:            private MessageExchange mReq;
148:
149:            /**
150:             *    
151:             */
152:            private ServiceEndpoint mInonlyReference;
153:
154:            /**
155:             *    
156:             */
157:            private ServiceEndpoint mInoutReference;
158:
159:            /**
160:             *    
161:             */
162:            private ServiceEndpoint mOutboundReference;
163:
164:            /**
165:             *    
166:             */
167:            private ServiceEndpoint mRobustinonlyReference;
168:
169:            /**
170:             *    
171:             */
172:            private boolean mRunFlag = true;
173:
174:            /**
175:             * Get the JMX ObjectName for the DeploymentMBean for this BPE. If there is
176:             * none, return null.
177:             *
178:             * @return ObjectName the JMX object name of the DeploymentMBean or null if
179:             *         there is no DeploymentMBean.
180:             */
181:            public javax.management.ObjectName getDeploymentMBeanName() {
182:                return null;
183:            }
184:
185:            /**
186:             * Get the JMX ObjectName for any additional MBean for this BC. If there is
187:             * none, return null.
188:             *
189:             * @return ObjectName the JMX object name of the additional MBean or null
190:             *         if there is no additional MBean.
191:             */
192:            public javax.management.ObjectName getExtensionMBeanName() {
193:                return null;
194:            }
195:
196:            /**
197:             * Initialize the test engine. This performs initialization required
198:             *
199:             * @param jbiContext the JBI environment mContext
200:             *
201:             * @throws javax.jbi.JBIException if the stockquote engine is unable to
202:             *         initialize.
203:             */
204:            public void init(javax.jbi.component.ComponentContext jbiContext)
205:                    throws javax.jbi.JBIException {
206:                mLog = Logger.getLogger(this .getClass().getPackage().getName());
207:                mLog.info("test engine INIT invoked");
208:
209:                if (jbiContext == null) {
210:                    throw (new javax.jbi.JBIException("Context is null",
211:                            new NullPointerException()));
212:                }
213:
214:                /* Assign values */
215:                mContext = jbiContext;
216:                Payload.mDefaultPath = mContext.getInstallRoot()
217:                        + File.separatorChar + "testengine1"
218:                        + File.separatorChar + "payload.xml";
219:                mLog.info(" INIT METHOD FINISHED ");
220:            }
221:
222:            /**
223:             * Shutdown the SE. This performs cleanup before the SE is terminated.
224:             * Once this has been called, init() must be called before the SE can be
225:             * started again with a call to start().
226:             *
227:             * @throws javax.jbi.JBIException if the SE is unable to shut down.
228:             */
229:            public void shutDown() throws javax.jbi.JBIException {
230:                mLog.info("test Engine Shutdown-Start");
231:                mLog.info("test Engine Shutdown-End");
232:            }
233:
234:            /**
235:             */
236:            public void start() throws javax.jbi.JBIException {
237:                mLog.info(" Test  ENGINE INVOKED ");
238:
239:                try {
240:                    mChannel = mContext.getDeliveryChannel();
241:                    mInoutReference = mContext.activateEndpoint(new QName(
242:                            INOUT_SERVICE_NAMESPACE, INOUT_SERVICE_NAME),
243:                            "stockEndpoint");
244:                    mInonlyReference = mContext.activateEndpoint(new QName(
245:                            INONLY_SERVICE_NAME), null);
246:                    mRobustinonlyReference = mContext.activateEndpoint(
247:                            new QName(ROBUSTINONLY_SERVICE_NAME),
248:                            "stockEndpoint");
249:                } catch (MessagingException me) {
250:                    me.printStackTrace();
251:                }
252:
253:                if (mChannel == null) {
254:                    mLog.severe("Cannot get Engine Channel from context ");
255:
256:                    return;
257:                }
258:
259:                /*
260:                   doTestGoodOutOnly();
261:                
262:                   doTestBadOutOnly();
263:                
264:                   doTestGoodRobustOutOnly();
265:                
266:                   doTestBadRobustOutOnly();
267:                 */
268:                mRecv = new Thread(new Receiver());
269:                mRecv.start();
270:                mLog.info(" START FINISHED  ");
271:            }
272:
273:            /**
274:             */
275:            public void stop() throws javax.jbi.JBIException {
276:                mLog.info("STOP INVOKED ");
277:                mRunFlag = false;
278:
279:                try {
280:                    if (mChannel != null) {
281:                        mChannel.close();
282:                    }
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:             * @author Sun Microsystems, Inc.
396:             * 
397:             */
398:            public class Receiver implements  Runnable {
399:                /**
400:                 *
401:                 */
402:                public void run() {
403:                    mLog.info("Test engine receiver started");
404:
405:                    try {
406:                        while (mRunFlag) {
407:                            mReq = mChannel.accept();
408:                            mLog.info("Got message i test ebgine");
409:
410:                            if (mReq instanceof  InOut) {
411:                                doTestGoodInOut();
412:                            } else if (mReq instanceof  InOnly) {
413:                                doTestGoodInOnly();
414:                            } else if (mReq instanceof  RobustInOnly) {
415:                                doTestGoodRobustInOnly();
416:                            }
417:                        }
418:                    } catch (Exception e) {
419:                        mLog.severe("Exception at receiver");
420:                        mLog.info("Test engine receiver ended");
421:                    }
422:                }
423:            }
424:
425:            public javax.jbi.component.ComponentLifeCycle getLifeCycle() {
426:                return this ;
427:            }
428:
429:            public javax.jbi.component.ServiceUnitManager getServiceUnitManager() {
430:                return null;
431:            }
432:
433:            public org.w3c.dom.Document getServiceDescription(
434:                    javax.jbi.servicedesc.ServiceEndpoint ServiceEndpoint) {
435:                return null;
436:            }
437:
438:            /** This method is called by JBI to check if this component, in the role of
439:             *  provider of the service indicated by the given exchange, can actually 
440:             *  perform the operation desired.
441:             */
442:            public boolean isExchangeWithConsumerOkay(
443:                    javax.jbi.servicedesc.ServiceEndpoint endpoint,
444:                    javax.jbi.messaging.MessageExchange exchange) {
445:                return true;
446:            }
447:
448:            /** This method is called by JBI to check if this component, in the role of
449:             *  consumer of the service indicated by the given exchange, can actually 
450:             *  interact with the the provider completely. 
451:             */
452:            public boolean isExchangeWithProviderOkay(
453:                    javax.jbi.servicedesc.ServiceEndpoint endpoint,
454:                    javax.jbi.messaging.MessageExchange exchange) {
455:                return true;
456:            }
457:
458:            /**
459:             * Resolve the given endpoint reference, given the capabilities of the
460:             * given consumer. This is called by JBI when it is attempting to resolve
461:             * the given endpoint reference on behalf of a component.
462:             * @param epr the endpoint reference, in some XML dialect understood by the
463:             * appropriate component (usually a Binding Component). 
464:             * @return the service endpoint for the endpoint reference;
465:             * <code>null</code> if the endpoint reference cannot be resolved.
466:             */
467:            public ServiceEndpoint resolveEndpointReference(DocumentFragment epr) {
468:                return null;
469:            }
470:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.