Source Code Cross Referenced for PublisherBean.java in  » EJB-Server-JBoss-4.2.1 » testsuite » org » jboss » test » jmsra » bean » 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 » EJB Server JBoss 4.2.1 » testsuite » org.jboss.test.jmsra.bean 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.test.jmsra.bean;
023:
024:        import java.rmi.RemoteException;
025:        import javax.ejb.EJBException;
026:        import javax.ejb.SessionBean;
027:        import javax.ejb.SessionContext;
028:        import javax.jms.JMSException;
029:        import javax.jms.QueueConnection;
030:        import javax.jms.QueueConnectionFactory;
031:        import javax.jms.QueueSender;
032:        import javax.jms.QueueSession;
033:        import javax.jms.Session;
034:        import javax.jms.TextMessage;
035:        import javax.jms.Queue;
036:        import javax.naming.Context;
037:        import javax.naming.InitialContext;
038:
039:        import org.apache.log4j.Category;
040:
041:        /**
042:         * Bean to help JMS RA test publish/send JMS messages and test transactional
043:         * behavior.
044:         *
045:         * <p>Created: Mon Apr 23 21:35:25 2001
046:         *
047:         * @author  Unknown
048:         * @author  <a href="mailto:jason@planet57.com">Jason Dillon</a>
049:         * @version $Revision: 57211 $
050:         */
051:        public class PublisherBean implements  SessionBean {
052:            private static final String CONNECTION_JNDI = "java:comp/env/jms/MyQueueConnection";
053:
054:            private static final String QUEUE_JNDI = "java:comp/env/jms/QueueName";
055:
056:            private static final String BEAN_JNDI = "java:comp/env/ejb/PublisherCMP";
057:
058:            private final Category log = Category.getInstance(this .getClass());
059:
060:            private SessionContext ctx; // = null;
061:            private Queue queue; // = null;
062:            private QueueConnection queueConnection; // = null;
063:
064:            public PublisherBean() {
065:                // empty
066:            }
067:
068:            public void setSessionContext(final SessionContext ctx) {
069:                this .ctx = ctx;
070:            }
071:
072:            public void ejbCreate() {
073:                try {
074:                    Context context = new InitialContext();
075:                    queue = (Queue) context.lookup(QUEUE_JNDI);
076:
077:                    QueueConnectionFactory factory = (QueueConnectionFactory) context
078:                            .lookup(CONNECTION_JNDI);
079:                    queueConnection = factory.createQueueConnection();
080:                } catch (Exception e) {
081:                    // JMSException or NamingException could be thrown
082:                    log.error("failed to create bean", e);
083:                    throw new EJBException(e);
084:                }
085:            }
086:
087:            /**
088:             * Send a message with a message nr in property MESSAGE_NR
089:             */
090:            public void simple(int messageNr) {
091:                log.info("sending message");
092:                sendMessage(messageNr);
093:                log.info("sent");
094:            }
095:
096:            /**
097:             * Try send a message with a message nr in property MESSAGE_NR,
098:             * but set rollback only
099:             */
100:            public void simpleFail(int messageNr) {
101:                log.info("sending message");
102:                sendMessage(messageNr);
103:                log.info("sent");
104:
105:                // Roll it back, no message should be sent if transactins work
106:                log.info("Setting rollbackOnly");
107:                ctx.setRollbackOnly();
108:                log.info("rollback set: " + ctx.getRollbackOnly());
109:            }
110:
111:            public void beanOk(int messageNr) {
112:                log.info("sending message");
113:                // DO JMS - First transaction
114:                sendMessage(messageNr);
115:                log.info("sent");
116:
117:                PublisherCMPHome h = null;
118:                try {
119:                    // DO entity bean - Second transaction
120:                    h = (PublisherCMPHome) new InitialContext()
121:                            .lookup(BEAN_JNDI);
122:                    PublisherCMP b = h.create(new Integer(messageNr));
123:                    log.info("calling bean");
124:                    b.ok(messageNr);
125:                    log.info("called bean");
126:                } catch (Exception e) {
127:                    log.error("failed to contact 3rdparty bean", e);
128:                    throw new EJBException(e);
129:                } finally {
130:                    try {
131:                        h.remove(new Integer(messageNr));
132:                    } catch (Exception e) {
133:                        log.error("failed to remove 3rdparty bean", e);
134:                    } finally {
135:                        log.info("done");
136:                    }
137:                }
138:            }
139:
140:            public void beanError(int messageNr) {
141:                log.info("sending message");
142:                // DO JMS - First transaction
143:                sendMessage(messageNr);
144:                log.info("sent");
145:
146:                PublisherCMPHome h = null;
147:                try {
148:                    // DO entity bean - Second transaction
149:                    h = (PublisherCMPHome) new InitialContext()
150:                            .lookup(BEAN_JNDI);
151:                    PublisherCMP b = h.create(new Integer(messageNr));
152:                    log.info("calling bean");
153:                    b.error(messageNr);
154:                    log.info("bean called (should never get here)");
155:                } catch (Exception e) {
156:                    log.info("caught exception (as expected)");
157:                    throw new EJBException("Exception in erro: " + e);
158:                } finally {
159:                    try {
160:                        h.remove(new Integer(messageNr));
161:                    } catch (Exception e) {
162:                        log.error("failed to remove 3rdparty bean", e);
163:                    } finally {
164:                        log.info("done");
165:                    }
166:                }
167:            }
168:
169:            public void ejbRemove() throws RemoteException {
170:                if (queueConnection != null) {
171:                    try {
172:                        queueConnection.close();
173:                    } catch (Exception e) {
174:                        log.error("failed to close connection", e);
175:                    }
176:                }
177:            }
178:
179:            public void ejbActivate() {
180:            }
181:
182:            public void ejbPassivate() {
183:            }
184:
185:            private void sendMessage(int messageNr) {
186:                log.info("sending message wtih nr: " + messageNr);
187:                QueueSession queueSession = null;
188:                try {
189:                    QueueSender queueSender = null;
190:                    TextMessage message = null;
191:                    queueSession = queueConnection.createQueueSession(true,
192:                            Session.AUTO_ACKNOWLEDGE);
193:                    queueSender = queueSession.createSender(queue);
194:
195:                    message = queueSession.createTextMessage();
196:                    message.setText(String.valueOf(messageNr));
197:                    message.setIntProperty(Publisher.JMS_MESSAGE_NR, messageNr);
198:                    queueSender.send(message);
199:                    log.info("sent message with nr = " + messageNr);
200:                } catch (JMSException e) {
201:                    log.debug("failed to send", e);
202:                    ctx.setRollbackOnly();
203:                    throw new EJBException(e);
204:                } finally {
205:                    if (queueSession != null) {
206:                        try {
207:                            queueSession.close();
208:                        } catch (Exception e) {
209:                            log.error("failed to close session", e);
210:                        } finally {
211:                            log.info("done sending message");
212:                        }
213:                    }
214:                }
215:            }
216:
217:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.