1
2
3
4
5
6
7 package org.mule.routing.outbound;
8
9 import org.mule.api.DefaultMuleException;
10 import org.mule.api.MuleContext;
11 import org.mule.api.MuleEvent;
12 import org.mule.api.MuleException;
13 import org.mule.api.MuleMessage;
14 import org.mule.api.MuleSession;
15 import org.mule.api.construct.FlowConstruct;
16 import org.mule.api.endpoint.ImmutableEndpoint;
17 import org.mule.api.security.Credentials;
18 import org.mule.api.transformer.DataType;
19 import org.mule.api.transformer.TransformerException;
20 import org.mule.api.transport.ReplyToHandler;
21 import org.mule.management.stats.ProcessingTime;
22 import org.mule.tck.MuleTestUtils;
23 import org.mule.transformer.types.DataTypeFactory;
24 import org.mule.util.UUID;
25
26 import java.io.OutputStream;
27 import java.io.UnsupportedEncodingException;
28
29
30
31
32 public class OutboundRoutingTestEvent implements MuleEvent
33 {
34 private MuleMessage message;
35 private MuleSession session;
36 private String id = UUID.getUUID();
37 private boolean stopFurtherProcessing;
38 private ImmutableEndpoint endpoint;
39 int timeout = -1;
40
41 public OutboundRoutingTestEvent(MuleMessage message, MuleSession session)
42 {
43 this.message = message;
44 this.session = session;
45 }
46
47 public OutboundRoutingTestEvent(MuleMessage message, MuleSession session, ImmutableEndpoint endpoint)
48 {
49 this.message = message;
50 this.session = session;
51 this.endpoint = endpoint;
52 }
53
54 public MuleMessage getMessage()
55 {
56 return message;
57 }
58
59 public MuleSession getSession()
60 {
61 return session;
62 }
63
64 public Credentials getCredentials()
65 {
66 return null;
67 }
68
69 public byte[] getMessageAsBytes() throws MuleException
70 {
71 try
72 {
73 return message.getPayloadAsBytes();
74 }
75 catch (Exception e)
76 {
77 throw new DefaultMuleException(e);
78 }
79 }
80
81 public String getMessageAsString() throws MuleException
82 {
83 try
84 {
85 return message.getPayloadAsString();
86 }
87 catch (Exception e)
88 {
89 throw new DefaultMuleException(e);
90 }
91 }
92
93 public String getMessageAsString(String encoding) throws MuleException
94 {
95 try
96 {
97 return message.getPayloadAsString(encoding);
98 }
99 catch (Exception e)
100 {
101 throw new DefaultMuleException(e);
102 }
103 }
104
105 public Object transformMessage() throws TransformerException
106 {
107 throw new UnsupportedOperationException();
108 }
109
110 public <T> T transformMessage(Class<T> outputType) throws TransformerException
111 {
112 return (T)transformMessage(DataTypeFactory.create(outputType));
113 }
114
115 public <T> T transformMessage(DataType<T> outputType) throws TransformerException
116 {
117 throw new UnsupportedOperationException();
118 }
119
120 @Deprecated
121 public byte[] transformMessageToBytes() throws TransformerException
122 {
123 return transformMessage(DataType.BYTE_ARRAY_DATA_TYPE);
124 }
125
126 public String transformMessageToString() throws TransformerException
127 {
128 try
129 {
130 return new String(transformMessageToBytes(), getEncoding());
131 }
132 catch (UnsupportedEncodingException e)
133 {
134 return "Unsupported Encoding";
135 }
136 }
137
138 public String getId()
139 {
140 return id;
141 }
142
143 public Object getProperty(String name)
144 {
145 return null;
146 }
147
148 public Object getProperty(String name, Object defaultValue)
149 {
150 return defaultValue;
151 }
152
153 public ImmutableEndpoint getEndpoint()
154 {
155 return endpoint;
156 }
157
158 public FlowConstruct getService()
159 {
160 return null;
161 }
162
163 public boolean isStopFurtherProcessing()
164 {
165 return stopFurtherProcessing;
166 }
167
168 public void setStopFurtherProcessing(boolean stopFurtherProcessing)
169 {
170 this.stopFurtherProcessing = stopFurtherProcessing;
171 }
172
173 public boolean isSynchronous()
174 {
175 return false;
176 }
177
178 public int getTimeout()
179 {
180 return timeout;
181 }
182
183 public void setTimeout(int timeout)
184 {
185 this.timeout = timeout;
186 }
187
188 public OutputStream getOutputStream()
189 {
190 return null;
191 }
192
193 public String getEncoding()
194 {
195 return message.getEncoding();
196 }
197
198 public MuleContext getMuleContext()
199 {
200 return null;
201 }
202
203 public FlowConstruct getFlowConstruct()
204 {
205 try
206 {
207 return session == null
208 ? MuleTestUtils.getTestService(message.getMuleContext())
209 : session.getFlowConstruct();
210 }
211 catch (Exception e)
212 {
213 throw new RuntimeException(e);
214 }
215 }
216
217 public ProcessingTime getProcessingTime()
218 {
219 return null;
220 }
221
222 public ReplyToHandler getReplyToHandler() {
223 return null;
224 }
225
226 public Object getReplyToDestination() {
227 return null;
228 }
229
230 public void captureReplyToDestination() {}
231 }