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