1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.providers.oracle.jms; |
12 | |
|
13 | |
import org.mule.providers.jms.Jms102bSupport; |
14 | |
import org.mule.providers.jms.JmsConnector; |
15 | |
import org.mule.util.ClassUtils; |
16 | |
|
17 | |
import java.util.Map; |
18 | |
|
19 | |
import javax.jms.Connection; |
20 | |
import javax.jms.ConnectionFactory; |
21 | |
import javax.jms.Destination; |
22 | |
import javax.jms.JMSException; |
23 | |
import javax.jms.MessageConsumer; |
24 | |
import javax.jms.Queue; |
25 | |
import javax.jms.QueueSession; |
26 | |
import javax.jms.Session; |
27 | |
import javax.jms.Topic; |
28 | |
import javax.jms.TopicSession; |
29 | |
import javax.naming.Context; |
30 | |
|
31 | |
import oracle.jms.AQjmsSession; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
public class OracleJmsSupport extends Jms102bSupport |
46 | |
{ |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
private Map endpointProperties; |
54 | |
|
55 | |
public OracleJmsSupport(JmsConnector connector, |
56 | |
Context context, |
57 | |
boolean jndiDestinations, |
58 | |
boolean forceJndiDestinations) |
59 | |
{ |
60 | 4 | super(connector, context, jndiDestinations, forceJndiDestinations); |
61 | 4 | } |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
public Connection createConnection(ConnectionFactory connectionFactory) throws JMSException |
70 | |
{ |
71 | 0 | return createConnection(connectionFactory, null, null); |
72 | |
} |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
public javax.jms.Connection createConnection(ConnectionFactory connectionFactory, |
81 | |
String username, |
82 | |
String password) throws JMSException |
83 | |
{ |
84 | 0 | return new OracleJmsConnection((OracleJmsConnector) connector); |
85 | |
} |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public MessageConsumer createConsumer(Session session, |
95 | |
Destination destination, |
96 | |
String messageSelector, |
97 | |
boolean noLocal, |
98 | |
String durableName, |
99 | |
boolean topic) throws JMSException |
100 | |
{ |
101 | |
|
102 | 0 | Object payloadFactory = getPayloadFactory(); |
103 | 0 | if (payloadFactory == null) |
104 | |
{ |
105 | 0 | return super.createConsumer(session, destination, messageSelector, noLocal, durableName, topic); |
106 | |
} |
107 | |
else |
108 | |
{ |
109 | 0 | if (topic && session instanceof TopicSession) |
110 | |
{ |
111 | 0 | if (durableName == null) |
112 | |
{ |
113 | 0 | return ((AQjmsSession) session).createSubscriber((Topic) destination, messageSelector, |
114 | |
noLocal); |
115 | |
} |
116 | |
else |
117 | |
{ |
118 | 0 | return ((AQjmsSession) session).createDurableSubscriber((Topic) destination, |
119 | |
durableName, messageSelector, noLocal, payloadFactory); |
120 | |
} |
121 | |
} |
122 | 0 | else if (session instanceof QueueSession) |
123 | |
{ |
124 | 0 | if (messageSelector != null) |
125 | |
{ |
126 | 0 | return ((AQjmsSession) session).createReceiver((Queue) destination, messageSelector, |
127 | |
payloadFactory); |
128 | |
} |
129 | |
else |
130 | |
{ |
131 | 0 | return ((AQjmsSession) session).createReceiver((Queue) destination, payloadFactory); |
132 | |
} |
133 | |
} |
134 | |
else |
135 | |
{ |
136 | 0 | throw new IllegalArgumentException("Session and domain type do not match"); |
137 | |
} |
138 | |
} |
139 | |
} |
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
public Destination createDestination(Session session, String name, boolean topic) throws JMSException |
152 | |
{ |
153 | 0 | Destination dest = super.createDestination(session, name, topic); |
154 | 0 | if (dest != null) |
155 | |
{ |
156 | 0 | return dest; |
157 | |
} |
158 | |
else |
159 | |
{ |
160 | 0 | throw new JMSException( |
161 | |
"Oracle JMS was unable to bind to the " |
162 | |
+ (topic ? "topic" : "queue") |
163 | |
+ ": " |
164 | |
+ name |
165 | |
+ " but gives no exception nor error message to explain why (that's what you get for using proprietary software...)"); |
166 | |
} |
167 | |
} |
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
public Destination createTemporaryDestination(Session session, boolean topic) throws JMSException |
180 | |
{ |
181 | 0 | Destination dest = super.createTemporaryDestination(session, topic); |
182 | 0 | if (dest != null) |
183 | |
{ |
184 | 0 | return dest; |
185 | |
} |
186 | |
else |
187 | |
{ |
188 | 0 | throw new JMSException("Unable to create temporary " + (topic ? "topic" : "queue")); |
189 | |
} |
190 | |
} |
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
public Object getPayloadFactory() throws JMSException |
199 | |
{ |
200 | |
|
201 | |
|
202 | 0 | String payloadFactoryClass = ((OracleJmsConnector) connector).getPayloadFactory(); |
203 | |
|
204 | |
|
205 | |
|
206 | 0 | if ((endpointProperties != null) |
207 | |
&& (endpointProperties.get(OracleJmsConnector.PAYLOADFACTORY_PROPERTY) != null)) |
208 | |
{ |
209 | 0 | payloadFactoryClass = (String) endpointProperties.get(OracleJmsConnector.PAYLOADFACTORY_PROPERTY); |
210 | |
} |
211 | |
|
212 | 0 | Object payloadFactory = null; |
213 | 0 | if (payloadFactoryClass != null) |
214 | |
{ |
215 | 0 | Throwable ex = null; |
216 | |
try |
217 | |
{ |
218 | |
|
219 | 0 | payloadFactory = ClassUtils.loadClass(payloadFactoryClass, this.getClass()).newInstance(); |
220 | |
} |
221 | 0 | catch (ClassNotFoundException e) |
222 | |
{ |
223 | 0 | ex = e; |
224 | |
} |
225 | 0 | catch (IllegalAccessException e) |
226 | |
{ |
227 | 0 | ex = e; |
228 | |
} |
229 | 0 | catch (InstantiationException e) |
230 | |
{ |
231 | 0 | ex = e; |
232 | 0 | } |
233 | 0 | if (ex != null) |
234 | |
{ |
235 | 0 | throw new JMSException("Unable to instantiate payload factory class " + payloadFactoryClass |
236 | |
+ ": " + ex.getMessage()); |
237 | |
} |
238 | |
} |
239 | 0 | return payloadFactory; |
240 | |
} |
241 | |
|
242 | |
public Map getEndpointProperties() |
243 | |
{ |
244 | 0 | return endpointProperties; |
245 | |
} |
246 | |
|
247 | |
public void setEndpointProperties(Map endpointProperties) |
248 | |
{ |
249 | 0 | this.endpointProperties = endpointProperties; |
250 | 0 | } |
251 | |
|
252 | |
} |