1
2
3
4
5
6
7
8
9
10
11 package org.mule.routing;
12
13 import org.mule.config.MuleProperties;
14 import org.mule.umo.UMOMessage;
15 import org.mule.util.properties.MessagePropertyExtractor;
16
17
18
19
20
21
22
23
24
25 public class CorrelationPropertiesExtractor extends MessagePropertyExtractor
26 {
27 public final Object getProperty(String name, Object message)
28 {
29 Object result;
30 UMOMessage msg = null;
31 if (message instanceof UMOMessage)
32 {
33 msg = (UMOMessage) message;
34 }
35 if (msg != null)
36 {
37 if (MuleProperties.MULE_CORRELATION_ID_PROPERTY.equals(name))
38 {
39 result = getCorrelationId(msg);
40 }
41 else if (MuleProperties.MULE_MESSAGE_ID_PROPERTY.equals(name))
42 {
43 result = getMessageId(msg);
44 }
45 else
46 {
47 throw new IllegalArgumentException("Property name: " + name
48 + " not recognised by the Correlation Property Extractor");
49 }
50 if (result == null)
51 {
52 throw new IllegalArgumentException(
53 "Property Extractor cannot return a null value. Extractor is: " + getClass().getName());
54 }
55 }
56 else
57 {
58 return super.getProperty(name, message);
59 }
60 return result;
61 }
62
63 public String getMessageId(UMOMessage message)
64 {
65 return message.getUniqueId();
66 }
67
68 public String getCorrelationId(UMOMessage message)
69 {
70 String id = message.getCorrelationId();
71 if (id == null)
72 {
73 id = message.getUniqueId();
74 }
75 return id;
76 }
77 }