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