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