1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.routing; |
12 | |
|
13 | |
import org.mule.RequestContext; |
14 | |
import org.mule.api.MuleEvent; |
15 | |
import org.mule.api.MuleException; |
16 | |
import org.mule.api.processor.MessageProcessor; |
17 | |
import org.mule.api.routing.filter.Filter; |
18 | |
import org.mule.processor.AbstractFilteringMessageProcessor; |
19 | |
import org.mule.processor.AbstractMessageProcessorOwner; |
20 | |
import org.mule.util.ObjectUtils; |
21 | |
|
22 | |
import org.apache.commons.logging.Log; |
23 | |
import org.apache.commons.logging.LogFactory; |
24 | |
|
25 | |
import java.util.Collections; |
26 | |
import java.util.List; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 0 | public class WireTap extends AbstractMessageProcessorOwner implements MessageProcessor |
43 | |
{ |
44 | 0 | protected final transient Log logger = LogFactory.getLog(getClass()); |
45 | |
protected volatile MessageProcessor tap; |
46 | |
protected volatile Filter filter; |
47 | |
|
48 | 0 | protected MessageProcessor filteredTap = new WireTapFilter(); |
49 | |
|
50 | |
public MuleEvent process(MuleEvent event) throws MuleException |
51 | |
{ |
52 | 0 | if (tap == null) |
53 | |
{ |
54 | 0 | return event; |
55 | |
} |
56 | |
|
57 | |
try |
58 | |
{ |
59 | |
|
60 | 0 | RequestContext.setEvent(null); |
61 | 0 | filteredTap.process(RequestContext.cloneAndUpdateEventEndpoint(event, tap)); |
62 | |
} |
63 | 0 | catch (MuleException e) |
64 | |
{ |
65 | 0 | logger.error("Exception sending to wiretap output " + tap, e); |
66 | 0 | } |
67 | |
|
68 | 0 | return event; |
69 | |
} |
70 | |
|
71 | |
public MessageProcessor getTap() |
72 | |
{ |
73 | 0 | return tap; |
74 | |
} |
75 | |
|
76 | |
public void setTap(MessageProcessor tap) |
77 | |
{ |
78 | 0 | this.tap = tap; |
79 | 0 | } |
80 | |
|
81 | |
@Deprecated |
82 | |
public void setMessageProcessor(MessageProcessor tap) |
83 | |
{ |
84 | 0 | setTap(tap); |
85 | 0 | } |
86 | |
|
87 | |
public Filter getFilter() |
88 | |
{ |
89 | 0 | return filter; |
90 | |
} |
91 | |
|
92 | |
public void setFilter(Filter filter) |
93 | |
{ |
94 | 0 | this.filter = filter; |
95 | 0 | } |
96 | |
|
97 | 0 | private class WireTapFilter extends AbstractFilteringMessageProcessor |
98 | |
{ |
99 | |
@Override |
100 | |
protected boolean accept(MuleEvent event) |
101 | |
{ |
102 | 0 | if (filter == null) |
103 | |
{ |
104 | 0 | return true; |
105 | |
} |
106 | |
else |
107 | |
{ |
108 | 0 | return filter.accept(event.getMessage()); |
109 | |
} |
110 | |
} |
111 | |
|
112 | |
@Override |
113 | |
protected MuleEvent processNext(MuleEvent event) throws MuleException |
114 | |
{ |
115 | 0 | if (tap != null) |
116 | |
{ |
117 | 0 | tap.process(event); |
118 | |
} |
119 | 0 | return null; |
120 | |
} |
121 | |
|
122 | |
@Override |
123 | |
public String toString() |
124 | |
{ |
125 | 0 | return ObjectUtils.toString(this); |
126 | |
} |
127 | |
} |
128 | |
|
129 | |
@Override |
130 | |
public String toString() |
131 | |
{ |
132 | 0 | return ObjectUtils.toString(this); |
133 | |
} |
134 | |
|
135 | |
@Override |
136 | |
protected List<MessageProcessor> getOwnedMessageProcessors() |
137 | |
{ |
138 | 0 | return Collections.singletonList(tap); |
139 | |
} |
140 | |
|
141 | |
} |