1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.impl; |
12 | |
|
13 | |
import org.mule.MuleRuntimeException; |
14 | |
import org.mule.config.i18n.CoreMessages; |
15 | |
import org.mule.providers.AbstractMessageAdapter; |
16 | |
import org.mule.providers.DefaultMessageAdapter; |
17 | |
import org.mule.umo.UMOExceptionPayload; |
18 | |
import org.mule.umo.UMOMessage; |
19 | |
import org.mule.umo.provider.UMOMessageAdapter; |
20 | |
|
21 | |
import java.util.Iterator; |
22 | |
import java.util.Map; |
23 | |
import java.util.Set; |
24 | |
|
25 | |
import javax.activation.DataHandler; |
26 | |
|
27 | |
import org.apache.commons.logging.Log; |
28 | |
import org.apache.commons.logging.LogFactory; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public class MuleMessage implements UMOMessage, ThreadSafeAccess |
36 | |
{ |
37 | |
|
38 | |
|
39 | |
|
40 | |
private static final long serialVersionUID = 1541720810851984842L; |
41 | |
|
42 | 4 | private static Log logger = LogFactory.getLog(MuleMessage.class); |
43 | |
|
44 | |
private UMOMessageAdapter adapter; |
45 | |
|
46 | |
protected UMOExceptionPayload exceptionPayload; |
47 | |
|
48 | |
public MuleMessage(Object message) |
49 | |
{ |
50 | 208 | this(message, (Map) null); |
51 | 208 | } |
52 | |
|
53 | |
public MuleMessage(Object message, Map properties) |
54 | 522 | { |
55 | 522 | if (message instanceof UMOMessageAdapter) |
56 | |
{ |
57 | 8 | adapter = (UMOMessageAdapter) message; |
58 | |
} |
59 | |
else |
60 | |
{ |
61 | 514 | adapter = new DefaultMessageAdapter(message); |
62 | |
} |
63 | 522 | addProperties(properties); |
64 | 522 | resetAccessControl(); |
65 | 522 | } |
66 | |
|
67 | |
public MuleMessage(Object message, UMOMessageAdapter previous) |
68 | 266 | { |
69 | 266 | if (message instanceof UMOMessageAdapter) |
70 | |
{ |
71 | 214 | adapter = (UMOMessageAdapter) message; |
72 | |
} |
73 | |
else |
74 | |
{ |
75 | 52 | adapter = new DefaultMessageAdapter(message, previous); |
76 | |
} |
77 | 266 | if (previous.getExceptionPayload() != null) |
78 | |
{ |
79 | 0 | setExceptionPayload(previous.getExceptionPayload()); |
80 | |
} |
81 | 266 | setEncoding(previous.getEncoding()); |
82 | 266 | if (previous.getAttachmentNames().size() > 0) |
83 | |
{ |
84 | 0 | Set attNames = adapter.getAttachmentNames(); |
85 | 0 | synchronized (attNames) |
86 | |
{ |
87 | 0 | for (Iterator iterator = attNames.iterator(); iterator.hasNext();) |
88 | |
{ |
89 | 0 | String s = (String) iterator.next(); |
90 | |
try |
91 | |
{ |
92 | 0 | addAttachment(s, adapter.getAttachment(s)); |
93 | |
} |
94 | 0 | catch (Exception e) |
95 | |
{ |
96 | 0 | throw new MuleRuntimeException(CoreMessages.failedToReadAttachment(s), e); |
97 | 0 | } |
98 | 0 | } |
99 | 0 | } |
100 | |
} |
101 | 266 | resetAccessControl(); |
102 | 266 | } |
103 | |
|
104 | |
public UMOMessageAdapter getAdapter() |
105 | |
{ |
106 | 0 | return adapter; |
107 | |
} |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
public Object getProperty(String key) |
116 | |
{ |
117 | 410 | return adapter.getProperty(key); |
118 | |
} |
119 | |
|
120 | |
public Object removeProperty(String key) |
121 | |
{ |
122 | 106 | return adapter.removeProperty(key); |
123 | |
} |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
public void setProperty(String key, Object value) |
132 | |
{ |
133 | 76 | adapter.setProperty(key, value); |
134 | 76 | } |
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
public String getPayloadAsString() throws Exception |
143 | |
{ |
144 | 48 | return adapter.getPayloadAsString(); |
145 | |
} |
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
public String getPayloadAsString(String encoding) throws Exception |
156 | |
{ |
157 | 42 | if (encoding == null) |
158 | |
{ |
159 | 8 | return adapter.getPayloadAsString(); |
160 | |
} |
161 | |
else |
162 | |
{ |
163 | 34 | return adapter.getPayloadAsString(encoding); |
164 | |
} |
165 | |
} |
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
public Set getPropertyNames() |
171 | |
{ |
172 | 346 | return adapter.getPropertyNames(); |
173 | |
} |
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
public byte[] getPayloadAsBytes() throws Exception |
182 | |
{ |
183 | 2 | return adapter.getPayloadAsBytes(); |
184 | |
} |
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
public Object getPayload() |
190 | |
{ |
191 | 844 | return adapter.getPayload(); |
192 | |
} |
193 | |
|
194 | |
public void addProperties(Map properties) |
195 | |
{ |
196 | 528 | adapter.addProperties(properties); |
197 | 528 | } |
198 | |
|
199 | |
public void clearProperties() |
200 | |
{ |
201 | 0 | adapter.clearProperties(); |
202 | 0 | } |
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
public double getDoubleProperty(String name, double defaultValue) |
212 | |
{ |
213 | 0 | return adapter.getDoubleProperty(name, defaultValue); |
214 | |
} |
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
public void setDoubleProperty(String name, double value) |
223 | |
{ |
224 | 0 | adapter.setDoubleProperty(name, value); |
225 | 0 | } |
226 | |
|
227 | |
public String getUniqueId() |
228 | |
{ |
229 | 154 | return adapter.getUniqueId(); |
230 | |
} |
231 | |
|
232 | |
public Object getProperty(String name, Object defaultValue) |
233 | |
{ |
234 | 6 | return adapter.getProperty(name, defaultValue); |
235 | |
} |
236 | |
|
237 | |
public int getIntProperty(String name, int defaultValue) |
238 | |
{ |
239 | 18 | return adapter.getIntProperty(name, defaultValue); |
240 | |
} |
241 | |
|
242 | |
public long getLongProperty(String name, long defaultValue) |
243 | |
{ |
244 | 0 | return adapter.getLongProperty(name, defaultValue); |
245 | |
} |
246 | |
|
247 | |
public boolean getBooleanProperty(String name, boolean defaultValue) |
248 | |
{ |
249 | 0 | return adapter.getBooleanProperty(name, defaultValue); |
250 | |
} |
251 | |
|
252 | |
public void setBooleanProperty(String name, boolean value) |
253 | |
{ |
254 | 0 | adapter.setBooleanProperty(name, value); |
255 | 0 | } |
256 | |
|
257 | |
public void setIntProperty(String name, int value) |
258 | |
{ |
259 | 0 | adapter.setIntProperty(name, value); |
260 | 0 | } |
261 | |
|
262 | |
public void setLongProperty(String name, long value) |
263 | |
{ |
264 | 0 | adapter.setLongProperty(name, value); |
265 | 0 | } |
266 | |
|
267 | |
|
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
|
276 | |
|
277 | |
|
278 | |
public void setCorrelationId(String id) |
279 | |
{ |
280 | 94 | adapter.setCorrelationId(id); |
281 | 94 | } |
282 | |
|
283 | |
|
284 | |
|
285 | |
|
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
|
293 | |
|
294 | |
|
295 | |
public String getCorrelationId() |
296 | |
{ |
297 | 248 | return adapter.getCorrelationId(); |
298 | |
} |
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | |
|
304 | |
|
305 | |
|
306 | |
|
307 | |
|
308 | |
public void setReplyTo(Object replyTo) |
309 | |
{ |
310 | 8 | adapter.setReplyTo(replyTo); |
311 | 8 | } |
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | |
|
318 | |
|
319 | |
|
320 | |
|
321 | |
public Object getReplyTo() |
322 | |
{ |
323 | 22 | return adapter.getReplyTo(); |
324 | |
} |
325 | |
|
326 | |
|
327 | |
|
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | |
public int getCorrelationSequence() |
333 | |
{ |
334 | 8 | return adapter.getCorrelationSequence(); |
335 | |
} |
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
|
341 | |
|
342 | |
|
343 | |
public void setCorrelationSequence(int sequence) |
344 | |
{ |
345 | 44 | adapter.setCorrelationSequence(sequence); |
346 | 44 | } |
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
|
352 | |
|
353 | |
public int getCorrelationGroupSize() |
354 | |
{ |
355 | 52 | return adapter.getCorrelationGroupSize(); |
356 | |
} |
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
|
362 | |
|
363 | |
public void setCorrelationGroupSize(int size) |
364 | |
{ |
365 | 72 | adapter.setCorrelationGroupSize(size); |
366 | 72 | } |
367 | |
|
368 | |
public UMOExceptionPayload getExceptionPayload() |
369 | |
{ |
370 | 338 | return exceptionPayload; |
371 | |
} |
372 | |
|
373 | |
public void setExceptionPayload(UMOExceptionPayload exceptionPayload) |
374 | |
{ |
375 | 10 | this.exceptionPayload = exceptionPayload; |
376 | 10 | } |
377 | |
|
378 | |
public String toString() |
379 | |
{ |
380 | 8 | return adapter.toString(); |
381 | |
} |
382 | |
|
383 | |
public void addAttachment(String name, DataHandler dataHandler) throws Exception |
384 | |
{ |
385 | 0 | adapter.addAttachment(name, dataHandler); |
386 | 0 | } |
387 | |
|
388 | |
public void removeAttachment(String name) throws Exception |
389 | |
{ |
390 | 0 | adapter.removeAttachment(name); |
391 | 0 | } |
392 | |
|
393 | |
public DataHandler getAttachment(String name) |
394 | |
{ |
395 | 0 | return adapter.getAttachment(name); |
396 | |
} |
397 | |
|
398 | |
public Set getAttachmentNames() |
399 | |
{ |
400 | 324 | return adapter.getAttachmentNames(); |
401 | |
} |
402 | |
|
403 | |
|
404 | |
|
405 | |
|
406 | |
|
407 | |
|
408 | |
|
409 | |
|
410 | |
|
411 | |
public String getEncoding() |
412 | |
{ |
413 | 364 | return adapter.getEncoding(); |
414 | |
} |
415 | |
|
416 | |
|
417 | |
|
418 | |
|
419 | |
|
420 | |
|
421 | |
public void setEncoding(String encoding) |
422 | |
{ |
423 | 272 | adapter.setEncoding(encoding); |
424 | 272 | } |
425 | |
|
426 | |
|
427 | |
|
428 | |
|
429 | |
|
430 | |
|
431 | |
|
432 | |
|
433 | |
public String getStringProperty(String name, String defaultValue) |
434 | |
{ |
435 | 8 | return adapter.getStringProperty(name, defaultValue); |
436 | |
} |
437 | |
|
438 | |
|
439 | |
|
440 | |
|
441 | |
|
442 | |
|
443 | |
|
444 | |
public void setStringProperty(String name, String value) |
445 | |
{ |
446 | 0 | adapter.setStringProperty(name, value); |
447 | 0 | } |
448 | |
|
449 | |
public ThreadSafeAccess newThreadCopy() |
450 | |
{ |
451 | 214 | if (adapter instanceof ThreadSafeAccess) |
452 | |
{ |
453 | 214 | logger.debug("new copy of message for " + Thread.currentThread()); |
454 | 214 | return new MuleMessage(((ThreadSafeAccess) adapter).newThreadCopy(), this); |
455 | |
} |
456 | |
else |
457 | |
{ |
458 | |
|
459 | 0 | return this; |
460 | |
} |
461 | |
} |
462 | |
|
463 | |
public void resetAccessControl() |
464 | |
{ |
465 | 998 | if (adapter instanceof AbstractMessageAdapter) |
466 | |
{ |
467 | 980 | ((AbstractMessageAdapter) adapter).resetAccessControl(); |
468 | |
} |
469 | 998 | } |
470 | |
|
471 | |
public void assertAccess(boolean write) |
472 | |
{ |
473 | 84 | if (adapter instanceof AbstractMessageAdapter) |
474 | |
{ |
475 | 84 | ((AbstractMessageAdapter) adapter).assertAccess(write); |
476 | |
} |
477 | 68 | } |
478 | |
|
479 | |
} |