2011/08/05 - Jakarta Cactus has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.cactus.spi.server;
22
23 import javax.ejb.CreateException;
24 import javax.ejb.EJBException;
25 import javax.ejb.MessageDrivenBean;
26 import javax.ejb.MessageDrivenContext;
27 import javax.jms.JMSException;
28 import javax.jms.Message;
29 import javax.jms.MessageListener;
30 import javax.jms.QueueConnection;
31 import javax.jms.QueueConnectionFactory;
32 import javax.jms.QueueSession;
33 import javax.naming.InitialContext;
34
35 import org.apache.cactus.internal.server.MessageDrivenBeanTestController;
36 import org.apache.commons.logging.Log;
37 import org.apache.commons.logging.LogFactory;
38
39
40
41
42
43
44
45
46
47
48
49 public class MessageDrivenBeanRedirector
50 implements MessageDrivenBean, MessageListener
51 {
52
53
54
55 private MessageDrivenContext context;
56 QueueConnection connection;
57 QueueSession session;
58
59
60
61
62 private static final Log LOGGER =
63 LogFactory.getLog(MessageDrivenBeanRedirector.class);
64
65
66
67
68
69
70 public void setMessageDrivenContext(MessageDrivenContext theContext)
71 {
72 this.context = theContext;
73 }
74
75
76
77
78
79
80
81 public void ejbCreate() throws CreateException
82 {
83 LOGGER.debug("------------- MDB redirector service created");
84
85 try
86 {
87 InitialContext initContext = new InitialContext();
88 QueueConnectionFactory qcf = (QueueConnectionFactory)
89 initContext.lookup("java:comp/env/jms/QCF1");
90 connection = qcf.createQueueConnection();
91 session = connection.createQueueSession(false,
92 QueueSession.AUTO_ACKNOWLEDGE);
93 connection.start();
94 }
95 catch(Exception e)
96 {
97 throw new EJBException("Failed to initialize MyMDB", e);
98 }
99 }
100
101
102
103
104
105
106 public void ejbRemove()
107 {
108 LOGGER.debug("------------- MDB redirector service removed");
109 }
110
111
112
113
114
115
116
117 public void onMessage(Message theMessage)
118 {
119
120 LOGGER.debug("------------- Start MDB service");
121
122
123 MessageDrivenBeanImplicitObjects implicitObjects =
124 new MessageDrivenBeanImplicitObjects();
125 implicitObjects.setMessage(theMessage);
126 implicitObjects.setMessageDrivenBeanContext(this.context);
127
128
129 MessageDrivenBeanTestController controller = new MessageDrivenBeanTestController();
130
131 try
132 {
133 controller.handleRequest(implicitObjects);
134 }
135 catch (JMSException e)
136 {
137 e.printStackTrace();
138 }
139
140 }
141
142 }