1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.tck.functional; |
12 | |
|
13 | |
import org.mule.MuleException; |
14 | |
import org.mule.MuleManager; |
15 | |
import org.mule.config.i18n.MessageFactory; |
16 | |
import org.mule.impl.RequestContext; |
17 | |
import org.mule.umo.UMOEventContext; |
18 | |
import org.mule.umo.lifecycle.Callable; |
19 | |
import org.mule.util.StringMessageUtils; |
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 | 0 | public class FunctionalTestComponent implements Callable |
33 | |
{ |
34 | 0 | protected transient Log logger = LogFactory.getLog(getClass()); |
35 | |
|
36 | |
public static final int STREAM_SAMPLE_SIZE = 4; |
37 | |
public static final int STREAM_BUFFER_SIZE = 4096; |
38 | |
private EventCallback eventCallback; |
39 | 0 | private Object returnMessage = null; |
40 | 0 | private boolean appendComponentName = false; |
41 | 0 | private boolean throwException = false; |
42 | |
|
43 | |
public Object onCall(UMOEventContext context) throws Exception |
44 | |
{ |
45 | 0 | String contents = context.getTransformedMessageAsString(); |
46 | 0 | String msg = StringMessageUtils.getBoilerPlate("Message Received in component: " |
47 | |
+ context.getComponentDescriptor().getName() + ". Content is: " |
48 | |
+ StringMessageUtils.truncate(contents, 100, true), '*', 80); |
49 | |
|
50 | 0 | logger.info(msg); |
51 | |
|
52 | 0 | if (eventCallback != null) |
53 | |
{ |
54 | 0 | eventCallback.eventReceived(context, this); |
55 | |
} |
56 | |
|
57 | |
Object replyMessage; |
58 | 0 | if (returnMessage != null) |
59 | |
{ |
60 | 0 | replyMessage = returnMessage; |
61 | |
} |
62 | |
else |
63 | |
{ |
64 | 0 | replyMessage = contents + " Received" + (appendComponentName ? " " + context.getComponentDescriptor().getName() : ""); |
65 | |
} |
66 | |
|
67 | 0 | MuleManager.getInstance().fireNotification( |
68 | |
new FunctionalTestNotification(context, replyMessage, FunctionalTestNotification.EVENT_RECEIVED)); |
69 | |
|
70 | 0 | if (throwException) |
71 | |
{ |
72 | 0 | throw new MuleException(MessageFactory.createStaticMessage("Functional Test Component Exception")); |
73 | |
} |
74 | |
|
75 | 0 | return replyMessage; |
76 | |
} |
77 | |
|
78 | |
public Object onReceive(Object data) throws Exception |
79 | |
{ |
80 | 0 | UMOEventContext context = RequestContext.getEventContext(); |
81 | |
|
82 | 0 | String contents = data.toString(); |
83 | 0 | String msg = StringMessageUtils.getBoilerPlate("Message Received in component: " |
84 | |
+ context.getComponentDescriptor().getName() + ". Content is: " |
85 | |
+ StringMessageUtils.truncate(contents, 100, true), '*', 80); |
86 | |
|
87 | 0 | logger.info(msg); |
88 | |
|
89 | 0 | if (eventCallback != null) |
90 | |
{ |
91 | 0 | eventCallback.eventReceived(context, this); |
92 | |
} |
93 | |
|
94 | |
Object replyMessage; |
95 | 0 | if (returnMessage != null) |
96 | |
{ |
97 | 0 | replyMessage = returnMessage; |
98 | |
} |
99 | |
else |
100 | |
{ |
101 | 0 | replyMessage = contents + " Received"; |
102 | |
} |
103 | |
|
104 | 0 | MuleManager.getInstance().fireNotification( |
105 | |
new FunctionalTestNotification(context, replyMessage, FunctionalTestNotification.EVENT_RECEIVED)); |
106 | |
|
107 | 0 | if (throwException) |
108 | |
{ |
109 | 0 | throw new MuleException(MessageFactory.createStaticMessage("Functional Test Component Exception")); |
110 | |
} |
111 | |
|
112 | 0 | return replyMessage; |
113 | |
} |
114 | |
|
115 | |
public EventCallback getEventCallback() |
116 | |
{ |
117 | 0 | return eventCallback; |
118 | |
} |
119 | |
|
120 | |
public void setEventCallback(EventCallback eventCallback) |
121 | |
{ |
122 | 0 | this.eventCallback = eventCallback; |
123 | 0 | } |
124 | |
|
125 | |
public Object getReturnMessage() |
126 | |
{ |
127 | 0 | return returnMessage; |
128 | |
} |
129 | |
|
130 | |
public void setReturnMessage(Object returnMessage) |
131 | |
{ |
132 | 0 | this.returnMessage = returnMessage; |
133 | 0 | } |
134 | |
|
135 | |
public boolean isThrowException() |
136 | |
{ |
137 | 0 | return throwException; |
138 | |
} |
139 | |
|
140 | |
public void setThrowException(boolean throwException) |
141 | |
{ |
142 | 0 | this.throwException = throwException; |
143 | 0 | } |
144 | |
|
145 | |
public boolean isAppendComponentName() |
146 | |
{ |
147 | 0 | return appendComponentName; |
148 | |
} |
149 | |
|
150 | |
public void setAppendComponentName(boolean appendComponentName) |
151 | |
{ |
152 | 0 | this.appendComponentName = appendComponentName; |
153 | 0 | } |
154 | |
|
155 | |
} |
156 | |
|