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