Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DefaultMuleEventContext |
|
| 0.0;0 | ||||
DefaultMuleEventContext$1 |
|
| 0.0;0 | ||||
DefaultMuleEventContext$2 |
|
| 0.0;0 | ||||
DefaultMuleEventContext$3 |
|
| 0.0;0 | ||||
DefaultMuleEventContext$4 |
|
| 0.0;0 |
1 | /* | |
2 | * $Id: DefaultMuleEventContext.java 19191 2010-08-25 21:05:23Z tcarlson $ | |
3 | * -------------------------------------------------------------------------------------- | |
4 | * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com | |
5 | * | |
6 | * The software in this package is published under the terms of the CPAL v1.0 | |
7 | * license, a copy of which has been included with this distribution in the | |
8 | * LICENSE.txt file. | |
9 | */ | |
10 | ||
11 | package org.mule; | |
12 | ||
13 | import org.mule.api.FutureMessageResult; | |
14 | import org.mule.api.MessagingException; | |
15 | import org.mule.api.MuleContext; | |
16 | import org.mule.api.MuleEvent; | |
17 | import org.mule.api.MuleEventContext; | |
18 | import org.mule.api.MuleException; | |
19 | import org.mule.api.MuleMessage; | |
20 | import org.mule.api.MuleSession; | |
21 | import org.mule.api.client.LocalMuleClient; | |
22 | import org.mule.api.config.MuleProperties; | |
23 | import org.mule.api.construct.FlowConstruct; | |
24 | import org.mule.api.endpoint.EndpointBuilder; | |
25 | import org.mule.api.endpoint.EndpointNotFoundException; | |
26 | import org.mule.api.endpoint.EndpointURI; | |
27 | import org.mule.api.endpoint.InboundEndpoint; | |
28 | import org.mule.api.endpoint.OutboundEndpoint; | |
29 | import org.mule.api.processor.MessageProcessor; | |
30 | import org.mule.api.service.Service; | |
31 | import org.mule.api.transaction.Transaction; | |
32 | import org.mule.api.transaction.TransactionException; | |
33 | import org.mule.api.transformer.DataType; | |
34 | import org.mule.api.transformer.TransformerException; | |
35 | import org.mule.config.i18n.CoreMessages; | |
36 | import org.mule.endpoint.EndpointURIEndpointBuilder; | |
37 | import org.mule.endpoint.URIBuilder; | |
38 | import org.mule.transaction.TransactionCoordination; | |
39 | import org.mule.transformer.types.DataTypeFactory; | |
40 | ||
41 | import java.io.OutputStream; | |
42 | ||
43 | import edu.emory.mathcs.backport.java.util.concurrent.Callable; | |
44 | ||
45 | import org.apache.commons.logging.Log; | |
46 | import org.apache.commons.logging.LogFactory; | |
47 | ||
48 | /** | |
49 | * <code>DefaultMuleEventContext</code> is the context object for the current | |
50 | * request. Using the context, developers can send/dispatch/receive events | |
51 | * programmatically as well as manage transactions. | |
52 | */ | |
53 | 0 | public class DefaultMuleEventContext implements MuleEventContext |
54 | { | |
55 | /** | |
56 | * logger used by this class | |
57 | */ | |
58 | 0 | protected static final Log logger = LogFactory.getLog(DefaultMuleEventContext.class); |
59 | ||
60 | private final MuleEvent event; | |
61 | private final MuleSession session; | |
62 | private final MuleContext muleContext; | |
63 | private final LocalMuleClient clientInterface; | |
64 | ||
65 | public DefaultMuleEventContext(MuleEvent event) | |
66 | 0 | { |
67 | 0 | this.event = event; |
68 | 0 | this.session = event.getSession(); |
69 | 0 | this.muleContext = event.getMuleContext(); |
70 | 0 | this.clientInterface = muleContext.getClient(); |
71 | 0 | } |
72 | ||
73 | /** | |
74 | * Returns the message payload for this event | |
75 | * | |
76 | * @return the message payload for this event | |
77 | */ | |
78 | public MuleMessage getMessage() | |
79 | { | |
80 | 0 | return event.getMessage(); |
81 | } | |
82 | ||
83 | /** | |
84 | * Reterns the conents of the message as a byte array. | |
85 | * | |
86 | * @return the conents of the message as a byte array | |
87 | * @throws org.mule.api.MuleException if the message cannot be converted into an | |
88 | * array of bytes | |
89 | */ | |
90 | public byte[] getMessageAsBytes() throws MuleException | |
91 | { | |
92 | 0 | return event.getMessageAsBytes(); |
93 | } | |
94 | ||
95 | /** | |
96 | * Returns the message transformed into its recognised or expected format. The | |
97 | * transformer used is the one configured on the endpoint through which this | |
98 | * event was received. | |
99 | * | |
100 | * @param dataType The dataType required for the return object. This param | |
101 | * just provides a convienient way to manage type casting of | |
102 | * transformed objects | |
103 | * @return the message transformed into it's recognised or expected format. | |
104 | * @throws org.mule.api.transformer.TransformerException if a failure occurs or | |
105 | * if the return type is not the same as the expected type in the | |
106 | * transformer | |
107 | * @see org.mule.api.transformer.Transformer | |
108 | */ | |
109 | public Object transformMessage(DataType dataType) throws TransformerException | |
110 | { | |
111 | 0 | return event.transformMessage(dataType); |
112 | } | |
113 | ||
114 | /** | |
115 | * Returns the message transformed into its recognised or expected format. The | |
116 | * transformer used is the one configured on the endpoint through which this | |
117 | * event was received. | |
118 | * | |
119 | * @param expectedType The class type required for the return object. This param | |
120 | * just provides a convienient way to manage type casting of | |
121 | * transformed objects | |
122 | * @return the message transformed into it's recognised or expected format. | |
123 | * @throws org.mule.api.transformer.TransformerException if a failure occurs or | |
124 | * if the return type is not the same as the expected type in the | |
125 | * transformer | |
126 | * @see org.mule.api.transformer.Transformer | |
127 | */ | |
128 | public Object transformMessage(Class expectedType) throws TransformerException | |
129 | { | |
130 | 0 | return event.transformMessage(DataTypeFactory.create(expectedType)); |
131 | } | |
132 | ||
133 | /** | |
134 | * Returns the message transformed into it's recognised or expected format and | |
135 | * then into an array of bytes. The transformer used is the one configured on the | |
136 | * endpoint through which this event was received. | |
137 | * | |
138 | * @return the message transformed into it's recognised or expected format as an | |
139 | * array of bytes. | |
140 | * @throws org.mule.api.transformer.TransformerException if a failure occurs in | |
141 | * the transformer | |
142 | * @see org.mule.api.transformer.Transformer | |
143 | * @deprecated use {@link #transformMessage(org.mule.api.transformer.DataType)} instead | |
144 | */ | |
145 | @Deprecated | |
146 | public byte[] transformMessageToBytes() throws TransformerException | |
147 | { | |
148 | 0 | return event.transformMessage(DataType.BYTE_ARRAY_DATA_TYPE); |
149 | } | |
150 | ||
151 | /** | |
152 | * Returns the message contents as a string | |
153 | * | |
154 | * @return the message contents as a string | |
155 | * @throws org.mule.api.MuleException if the message cannot be converted into a | |
156 | * string | |
157 | */ | |
158 | public String getMessageAsString(String encoding) throws MuleException | |
159 | { | |
160 | 0 | return event.getMessageAsString(encoding); |
161 | } | |
162 | ||
163 | /** | |
164 | * Returns the message transformed into it's recognised or expected format and | |
165 | * then into a String. The transformer used is the one configured on the endpoint | |
166 | * through which this event was received. This method will use the default | |
167 | * encoding on the event | |
168 | * | |
169 | * @return the message transformed into it's recognised or expected format as a | |
170 | * Strings. | |
171 | * @throws org.mule.api.transformer.TransformerException if a failure occurs in | |
172 | * the transformer | |
173 | * @see org.mule.api.transformer.Transformer | |
174 | */ | |
175 | public String transformMessageToString() throws TransformerException | |
176 | { | |
177 | 0 | return event.transformMessageToString(); |
178 | } | |
179 | ||
180 | /** | |
181 | * Returns the message contents as a string This method will use the default | |
182 | * encoding on the event | |
183 | * | |
184 | * @return the message contents as a string | |
185 | * @throws org.mule.api.MuleException if the message cannot be converted into a | |
186 | * string | |
187 | */ | |
188 | public String getMessageAsString() throws MuleException | |
189 | { | |
190 | 0 | return event.getMessageAsString(); |
191 | } | |
192 | ||
193 | /** | |
194 | * Returns the current transaction (if any) for the session | |
195 | * | |
196 | * @return the current transaction for the session or null if there is no | |
197 | * transaction in progress | |
198 | */ | |
199 | public Transaction getCurrentTransaction() | |
200 | { | |
201 | 0 | return TransactionCoordination.getInstance().getTransaction(); |
202 | } | |
203 | ||
204 | public void markTransactionForRollback() throws TransactionException | |
205 | { | |
206 | 0 | if (getCurrentTransaction() != null) |
207 | { | |
208 | 0 | getCurrentTransaction().setRollbackOnly(); |
209 | } | |
210 | 0 | } |
211 | ||
212 | /** | |
213 | * This will send an event via the configured outbound router on the service | |
214 | * | |
215 | * @param message the message to send | |
216 | * @return the result of the send if any | |
217 | * @throws org.mule.api.MuleException if there is no outbound endpoint configured | |
218 | * on the service or the events fails during dispatch | |
219 | */ | |
220 | public MuleMessage sendEvent(Object message) throws MuleException | |
221 | { | |
222 | 0 | return sendEvent(new DefaultMuleMessage(message, event.getMessage(), event.getMuleContext())); |
223 | } | |
224 | ||
225 | /** | |
226 | * Depending on the session state this methods either Passes an event | |
227 | * synchronously to the next available Mule component in the pool or via the | |
228 | * endpoint configured for the event | |
229 | * | |
230 | * @param message the event message payload to send | |
231 | * @param endpoint The endpoint to disptch the event through. | |
232 | * @return the return Message from the call or null if there was no result | |
233 | * @throws org.mule.api.MuleException if the event fails to be processed by the | |
234 | * service or the transport for the endpoint | |
235 | */ | |
236 | public MuleMessage sendEvent(MuleMessage message, OutboundEndpoint endpoint) throws MuleException | |
237 | { | |
238 | 0 | return clientInterface.process(endpoint, message); |
239 | } | |
240 | ||
241 | /** | |
242 | * Depending on the session state this methods either Passes an event | |
243 | * synchronously to the next available Mule component in the pool or via the | |
244 | * endpoint configured for the event | |
245 | * | |
246 | * @param message the message payload to send | |
247 | * @return the return Message from the call or null if there was no result | |
248 | * @throws org.mule.api.MuleException if the event fails to be processed by the | |
249 | * service or the transport for the endpoint | |
250 | */ | |
251 | public MuleMessage sendEvent(MuleMessage message) throws MuleException | |
252 | { | |
253 | 0 | if (event.getEndpoint() instanceof OutboundEndpoint) |
254 | { | |
255 | 0 | return clientInterface.process((OutboundEndpoint) event.getEndpoint(), message); |
256 | } | |
257 | 0 | else if (session.getFlowConstruct() instanceof Service) |
258 | { | |
259 | 0 | Service service = (Service) session.getFlowConstruct(); |
260 | 0 | DefaultMuleEvent eventToSend = new DefaultMuleEvent(message, event.getEndpoint(), session); |
261 | 0 | MuleEvent event = service.sendEvent(eventToSend); |
262 | 0 | return event == null ? null : event.getMessage(); |
263 | } | |
264 | else | |
265 | { | |
266 | 0 | throw new MessagingException( |
267 | CoreMessages.createStaticMessage("Current event has 'inbound' endpoint and FlowConstuct is not a 'Service', MuleEventContext cannot this message"), | |
268 | event); | |
269 | } | |
270 | } | |
271 | ||
272 | /** | |
273 | * Depending on the session state this methods either Passes an event | |
274 | * synchronously to the next available Mule component in the pool or via the | |
275 | * endpointUri configured for the event | |
276 | * | |
277 | * @param message the event message payload to send | |
278 | * @param endpointUri The endpointUri to disptch the event through | |
279 | * @return the return Message from the call or null if there was no result | |
280 | * @throws org.mule.api.MuleException if the event fails to be processed by the | |
281 | * service or the transport for the endpointUri | |
282 | */ | |
283 | public MuleMessage sendEvent(MuleMessage message, EndpointURI endpointUri) throws MuleException | |
284 | { | |
285 | 0 | EndpointBuilder builder = null; |
286 | 0 | if (endpointUri.getEndpointName() != null) |
287 | { | |
288 | 0 | builder = muleContext.getRegistry().lookupEndpointBuilder(endpointUri.getEndpointName()); |
289 | } | |
290 | 0 | if (builder == null) |
291 | { | |
292 | 0 | builder = new EndpointURIEndpointBuilder(new URIBuilder(endpointUri)); |
293 | } | |
294 | ||
295 | 0 | builder.setExchangePattern(MessageExchangePattern.REQUEST_RESPONSE); |
296 | ||
297 | 0 | OutboundEndpoint endpoint = getMuleContext().getRegistry() |
298 | .lookupEndpointFactory() | |
299 | .getOutboundEndpoint(builder); | |
300 | ||
301 | 0 | return clientInterface.process(endpoint, message); |
302 | } | |
303 | ||
304 | /** | |
305 | * sends an event request via the configured outbound router for this service. | |
306 | * This method return immediately, but the result of the event invocation | |
307 | * available from the returned a Future result that can be accessed later by the | |
308 | * the returned FutureMessageResult. the Future messageResult can be queried at | |
309 | * any time to check that the invocation has completed. A timeout is associated | |
310 | * with the invocation, which is the maximum time in milli-seconds that the | |
311 | * invocation should take to complete | |
312 | * | |
313 | * @param message the object that is the payload of the event | |
314 | * @param timeout how long to block in milliseconds waiting for a result | |
315 | * @return the result message if any of the invocation | |
316 | * @throws org.mule.api.MuleException if the dispatch fails or the components or | |
317 | * transfromers cannot be found | |
318 | * @see org.mule.api.FutureMessageResult | |
319 | */ | |
320 | public FutureMessageResult sendEventAsync(final Object message, final int timeout) throws MuleException | |
321 | { | |
322 | 0 | Callable callable = new Callable() |
323 | 0 | { |
324 | public Object call() throws Exception | |
325 | { | |
326 | 0 | MuleMessage muleMessage = new DefaultMuleMessage(message, event.getMessage(), |
327 | event.getMuleContext()); | |
328 | 0 | muleMessage.setOutboundProperty(MuleProperties.MULE_EVENT_TIMEOUT_PROPERTY, timeout); |
329 | 0 | return sendEvent(muleMessage); |
330 | } | |
331 | }; | |
332 | ||
333 | 0 | FutureMessageResult result = new FutureMessageResult(callable, event.getMuleContext()); |
334 | 0 | result.execute(); |
335 | 0 | return result; |
336 | } | |
337 | ||
338 | /** | |
339 | * sends an event request via the configured outbound router for this service. | |
340 | * This method return immediately, but the result of the event invocation | |
341 | * available from the returned a Future result that can be accessed later by the | |
342 | * the returned FutureMessageResult. the Future messageResult can be queried at | |
343 | * any time to check that the invocation has completed. A timeout is associated | |
344 | * with the invocation, which is the maximum time in milli-seconds that the | |
345 | * invocation should take to complete | |
346 | * | |
347 | * @param message the MuleMessage of the event | |
348 | * @param timeout how long to block in milliseconds waiting for a result | |
349 | * @return the result message if any of the invocation | |
350 | * @throws org.mule.api.MuleException if the dispatch fails or the components or | |
351 | * transfromers cannot be found | |
352 | * @see org.mule.api.FutureMessageResult | |
353 | */ | |
354 | public FutureMessageResult sendEventAsync(final MuleMessage message, final int timeout) | |
355 | throws MuleException | |
356 | { | |
357 | 0 | Callable callable = new Callable() |
358 | 0 | { |
359 | public Object call() throws Exception | |
360 | { | |
361 | 0 | message.setOutboundProperty(MuleProperties.MULE_EVENT_TIMEOUT_PROPERTY, timeout); |
362 | 0 | return sendEvent(message); |
363 | } | |
364 | }; | |
365 | ||
366 | 0 | FutureMessageResult result = new FutureMessageResult(callable, event.getMuleContext()); |
367 | 0 | result.execute(); |
368 | 0 | return result; |
369 | } | |
370 | ||
371 | /** | |
372 | * sends an event request via the configured outbound router for this service. | |
373 | * This method return immediately, but the result of the event invocation | |
374 | * available from the returned a Future result that can be accessed later by the | |
375 | * the returned FutureMessageResult. the Future messageResult can be queried at | |
376 | * any time to check that the invocation has completed. A timeout is associated | |
377 | * with the invocation, which is the maximum time in milli-seconds that the | |
378 | * invocation should take to complete | |
379 | * | |
380 | * @param message the MuleMessage of the event | |
381 | * @param endpointUri the endpointUri to dispatch to | |
382 | * @param timeout how long to block in milliseconds waiting for a result | |
383 | * @return the result message if any of the invocation | |
384 | * @throws org.mule.api.MuleException if the dispatch fails or the components or | |
385 | * transfromers cannot be found | |
386 | * @see org.mule.api.FutureMessageResult | |
387 | */ | |
388 | public FutureMessageResult sendEventAsync(final MuleMessage message, | |
389 | final EndpointURI endpointUri, | |
390 | final int timeout) throws MuleException | |
391 | { | |
392 | 0 | Callable callable = new Callable() |
393 | 0 | { |
394 | public Object call() throws Exception | |
395 | { | |
396 | 0 | message.setOutboundProperty(MuleProperties.MULE_EVENT_TIMEOUT_PROPERTY, timeout); |
397 | 0 | return sendEvent(message, endpointUri); |
398 | } | |
399 | }; | |
400 | ||
401 | 0 | FutureMessageResult result = new FutureMessageResult(callable, event.getMuleContext()); |
402 | 0 | result.execute(); |
403 | 0 | return result; |
404 | } | |
405 | ||
406 | /** | |
407 | * sends an event request via the configured outbound router for this service. | |
408 | * This method return immediately, but the result of the event invocation | |
409 | * available from the returned a Future result that can be accessed later by the | |
410 | * the returned FutureMessageResult. the Future messageResult can be queried at | |
411 | * any time to check that the invocation has completed. A timeout is associated | |
412 | * with the invocation, which is the maximum time in milli-seconds that the | |
413 | * invocation should take to complete | |
414 | * | |
415 | * @param message the MuleMessage of the event | |
416 | * @param endpointName The endpoint name to disptch the event through. This will | |
417 | * be looked up first on the service configuration and then on the | |
418 | * mule manager configuration | |
419 | * @param timeout how long to block in milliseconds waiting for a result | |
420 | * @return the result message if any of the invocation | |
421 | * @throws org.mule.api.MuleException if the dispatch fails or the components or | |
422 | * transfromers cannot be found | |
423 | * @see org.mule.api.FutureMessageResult | |
424 | */ | |
425 | public FutureMessageResult sendEventAsync(final MuleMessage message, | |
426 | final String endpointName, | |
427 | final int timeout) throws MuleException | |
428 | { | |
429 | 0 | Callable callable = new Callable() |
430 | 0 | { |
431 | public Object call() throws Exception | |
432 | { | |
433 | 0 | message.setOutboundProperty(MuleProperties.MULE_EVENT_TIMEOUT_PROPERTY, timeout); |
434 | 0 | return sendEvent(message, endpointName); |
435 | } | |
436 | }; | |
437 | ||
438 | 0 | FutureMessageResult result = new FutureMessageResult(callable, event.getMuleContext()); |
439 | 0 | result.execute(); |
440 | 0 | return result; |
441 | } | |
442 | ||
443 | /** | |
444 | * Depending on the session state this methods either Passes an event | |
445 | * synchronously to the next available Mule component in the pool or via the | |
446 | * endpoint configured for the event | |
447 | * | |
448 | * @param message the event message payload to send | |
449 | * @param endpointName The endpoint name to disptch the event through. This will | |
450 | * be looked up first on the service configuration and then on the | |
451 | * mule manager configuration | |
452 | * @return the return Message from the call or null if there was no result | |
453 | * @throws org.mule.api.MuleException if the event fails to be processed by the | |
454 | * service or the transport for the endpoint | |
455 | */ | |
456 | public MuleMessage sendEvent(MuleMessage message, String endpointName) throws MuleException | |
457 | { | |
458 | 0 | return clientInterface.send(endpointName, message); |
459 | } | |
460 | ||
461 | /** | |
462 | * This will dispatch an event asynchronously via the configured outbound | |
463 | * endpoint on the service for this session | |
464 | * | |
465 | * @param message payload to dispatch | |
466 | * @throws org.mule.api.MuleException if there is no outbound endpoint configured | |
467 | * on the service or the events fails during dispatch | |
468 | */ | |
469 | public void dispatchEvent(Object message) throws MuleException | |
470 | { | |
471 | 0 | dispatchEvent(new DefaultMuleMessage(message, muleContext)); |
472 | 0 | } |
473 | ||
474 | /** | |
475 | * This will dispatch an event asynchronously via the configured outbound | |
476 | * endpoint on the service for this session | |
477 | * | |
478 | * @param message the message to send | |
479 | * @throws org.mule.api.MuleException if there is no outbound endpoint configured | |
480 | * on the service or the events fails during dispatch | |
481 | */ | |
482 | public void dispatchEvent(MuleMessage message) throws MuleException | |
483 | { | |
484 | 0 | FlowConstruct flowConstruct = session.getFlowConstruct(); |
485 | 0 | if (flowConstruct == null) |
486 | { | |
487 | 0 | throw new IllegalStateException(CoreMessages.objectIsNull("flowConstruct").getMessage()); |
488 | } | |
489 | 0 | else if (!(flowConstruct instanceof Service)) |
490 | { | |
491 | 0 | throw new UnsupportedOperationException( |
492 | "EventContext.dispatchEvent is only supported when flow constuct is a Service"); | |
493 | } | |
494 | else | |
495 | { | |
496 | 0 | MessageProcessor processor = ((Service) flowConstruct).getOutboundMessageProcessor(); |
497 | 0 | if (processor == null) |
498 | { | |
499 | 0 | throw new EndpointNotFoundException( |
500 | CoreMessages.noOutboundRouterSetOn(flowConstruct.getName())); | |
501 | } | |
502 | 0 | processor.process(new DefaultMuleEvent(message, RequestContext.getEvent())); |
503 | } | |
504 | 0 | } |
505 | ||
506 | /** | |
507 | * Depending on the session state this methods either Passes an event | |
508 | * asynchronously to the next available Mule component in the pool or via the | |
509 | * endpointUri configured for the event | |
510 | * | |
511 | * @param message the event message payload to send | |
512 | * @param endpointUri the endpointUri to dispatc the event to first on the | |
513 | * service configuration and then on the mule manager configuration | |
514 | * @throws org.mule.api.MuleException if the event fails to be processed by the | |
515 | * service or the transport for the endpointUri | |
516 | */ | |
517 | public void dispatchEvent(MuleMessage message, EndpointURI endpointUri) throws MuleException | |
518 | { | |
519 | 0 | EndpointBuilder builder = null; |
520 | 0 | if (endpointUri.getEndpointName() != null) |
521 | { | |
522 | 0 | builder = muleContext.getRegistry().lookupEndpointBuilder(endpointUri.getEndpointName()); |
523 | } | |
524 | 0 | if (builder == null) |
525 | { | |
526 | 0 | builder = new EndpointURIEndpointBuilder(new URIBuilder(endpointUri)); |
527 | } | |
528 | ||
529 | 0 | builder.setExchangePattern(MessageExchangePattern.ONE_WAY); |
530 | ||
531 | 0 | OutboundEndpoint endpoint = getMuleContext().getRegistry() |
532 | .lookupEndpointFactory() | |
533 | .getOutboundEndpoint(builder); | |
534 | ||
535 | 0 | clientInterface.process(endpoint, message); } |
536 | ||
537 | /** | |
538 | * Depending on the session state this methods either Passes an event | |
539 | * asynchronously to the next available Mule component in the pool or via the | |
540 | * endpoint configured for the event | |
541 | * | |
542 | * @param message the event message payload to send | |
543 | * @param endpointName The endpoint name to disptch the event through. This will | |
544 | * be looked up first on the service configuration and then on the | |
545 | * mule manager configuration | |
546 | * @throws org.mule.api.MuleException if the event fails to be processed by the | |
547 | * service or the transport for the endpoint | |
548 | */ | |
549 | public void dispatchEvent(MuleMessage message, String endpointName) throws MuleException | |
550 | { | |
551 | 0 | EndpointBuilder builder = muleContext.getRegistry().lookupEndpointBuilder(endpointName); |
552 | ||
553 | 0 | if (builder == null) |
554 | { | |
555 | 0 | builder = new EndpointURIEndpointBuilder(new URIBuilder(endpointName, muleContext)); |
556 | } | |
557 | ||
558 | 0 | builder.setExchangePattern(MessageExchangePattern.ONE_WAY); |
559 | ||
560 | 0 | OutboundEndpoint endpoint = getMuleContext().getRegistry() |
561 | .lookupEndpointFactory() | |
562 | .getOutboundEndpoint(builder); | |
563 | ||
564 | 0 | clientInterface.process(endpoint, message); |
565 | 0 | } |
566 | ||
567 | /** | |
568 | * Depending on the session state this methods either Passes an event | |
569 | * asynchronously to the next available Mule component in the pool or via the | |
570 | * endpoint configured for the event | |
571 | * | |
572 | * @param message the event message payload to send | |
573 | * @param endpoint The endpoint name to disptch the event through. | |
574 | * @throws org.mule.api.MuleException if the event fails to be processed by the | |
575 | * service or the transport for the endpoint | |
576 | */ | |
577 | public void dispatchEvent(MuleMessage message, OutboundEndpoint endpoint) throws MuleException | |
578 | { | |
579 | 0 | clientInterface.process(endpoint, message); |
580 | 0 | } |
581 | ||
582 | /** | |
583 | * Requests a synchronous receive of an event on the service | |
584 | * | |
585 | * @param endpoint the endpoint identifing the endpointUri on ewhich the event | |
586 | * will be received | |
587 | * @param timeout time in milliseconds before the request timesout | |
588 | * @return The requested event or null if the request times out | |
589 | * @throws org.mule.api.MuleException if the request operation fails | |
590 | */ | |
591 | public MuleMessage requestEvent(InboundEndpoint endpoint, long timeout) throws MuleException | |
592 | { | |
593 | 0 | return clientInterface.request(endpoint, timeout); |
594 | } | |
595 | ||
596 | /** | |
597 | * Requests a synchronous receive of an event on the service | |
598 | * | |
599 | * @param endpointName the endpoint identifing the endpointUri on ewhich the | |
600 | * event will be received | |
601 | * @param timeout time in milliseconds before the request timesout | |
602 | * @return The requested event or null if the request times out | |
603 | * @throws org.mule.api.MuleException if the request operation fails | |
604 | */ | |
605 | public MuleMessage requestEvent(String endpointName, long timeout) throws MuleException | |
606 | { | |
607 | 0 | return clientInterface.request(endpointName, timeout); |
608 | } | |
609 | ||
610 | /** | |
611 | * Requests a synchronous receive of an event on the service | |
612 | * | |
613 | * @param endpointUri the endpointUri on which the event will be received | |
614 | * @param timeout time in milliseconds before the request timesout | |
615 | * @return The requested event or null if the request times out | |
616 | * @throws org.mule.api.MuleException if the request operation fails | |
617 | */ | |
618 | public MuleMessage requestEvent(EndpointURI endpointUri, long timeout) throws MuleException | |
619 | { | |
620 | 0 | InboundEndpoint endpoint = getMuleContext().getRegistry().lookupEndpointFactory().getInboundEndpoint( |
621 | endpointUri); | |
622 | 0 | return requestEvent(endpoint, timeout); |
623 | } | |
624 | ||
625 | /** | |
626 | * @return the service descriptor of the service that received this event | |
627 | */ | |
628 | public FlowConstruct getFlowConstruct() | |
629 | { | |
630 | 0 | return event.getFlowConstruct(); |
631 | } | |
632 | ||
633 | /** | |
634 | * Determines whether the default processing for this event will be executed. By | |
635 | * default, the Mule server will route events according to a components | |
636 | * configuration. The user can override this behaviour by obtaining a reference | |
637 | * to the MuleEvent context, either by implementing | |
638 | * <code>org.mule.api.lifecycle.Callable</code> or calling | |
639 | * <code>RequestContext.getEventContext</code> to obtain the MuleEventContext for | |
640 | * the current thread. The user can programmatically control how events are | |
641 | * dispatched. | |
642 | * | |
643 | * @return Returns true is the user has set stopFurtherProcessing. | |
644 | * @see org.mule.api.MuleEventContext | |
645 | * @see org.mule.api.lifecycle.Callable | |
646 | */ | |
647 | public boolean isStopFurtherProcessing() | |
648 | { | |
649 | 0 | return RequestContext.getEvent().isStopFurtherProcessing(); |
650 | } | |
651 | ||
652 | /** | |
653 | * Determines whether the default processing for this event will be executed. By | |
654 | * default, the Mule server will route events according to a components | |
655 | * configuration. The user can override this behaviour by obtaining a reference | |
656 | * to the MuleEvent context, either by implementing | |
657 | * <code>org.mule.api.lifecycle.Callable</code> or calling | |
658 | * <code>RequestContext.getEventContext</code> to obtain the MuleEventContext for | |
659 | * the current thread. The user can programmatically control how events are | |
660 | * dispached. | |
661 | * | |
662 | * @param stopFurtherProcessing the value to set. | |
663 | */ | |
664 | public void setStopFurtherProcessing(boolean stopFurtherProcessing) | |
665 | { | |
666 | 0 | event.setStopFurtherProcessing(stopFurtherProcessing); |
667 | 0 | } |
668 | ||
669 | /** | |
670 | * An outputstream the can optionally be used write response data to an incoming | |
671 | * message. | |
672 | * | |
673 | * @return an output stream if one has been made available by the message | |
674 | * receiver that received the message | |
675 | */ | |
676 | public OutputStream getOutputStream() | |
677 | { | |
678 | 0 | return event.getOutputStream(); |
679 | } | |
680 | ||
681 | public EndpointURI getEndpointURI() | |
682 | { | |
683 | 0 | return event.getEndpoint().getEndpointURI(); |
684 | } | |
685 | ||
686 | public MessageExchangePattern getExchangePattern() | |
687 | { | |
688 | 0 | return event.getEndpoint().getExchangePattern(); |
689 | } | |
690 | ||
691 | /** | |
692 | * Returns the transaction for the current event or null if there is no | |
693 | * transaction in progresss | |
694 | * | |
695 | * @return the transaction for the current event or null if there is no | |
696 | * transaction in progresss | |
697 | */ | |
698 | public Transaction getTransaction() | |
699 | { | |
700 | 0 | return TransactionCoordination.getInstance().getTransaction(); |
701 | } | |
702 | ||
703 | /** | |
704 | * Get the timeout value associated with the event | |
705 | * | |
706 | * @return the timeout for the event | |
707 | */ | |
708 | public int getTimeout() | |
709 | { | |
710 | 0 | return event.getTimeout(); |
711 | } | |
712 | ||
713 | /** | |
714 | * Gets the encoding for the current message. For potocols that send encoding | |
715 | * Information with the message, this method should be overriden to expose the | |
716 | * transport encoding, otherwise the default encoding in the Mule configuration | |
717 | * will be used | |
718 | * | |
719 | * @return the encoding for this message. This method must never return null | |
720 | */ | |
721 | public String getEncoding() | |
722 | { | |
723 | 0 | return event.getEncoding(); |
724 | } | |
725 | ||
726 | public MuleSession getSession() | |
727 | { | |
728 | 0 | return event.getSession(); |
729 | } | |
730 | ||
731 | @Override | |
732 | public String toString() | |
733 | { | |
734 | 0 | return event.toString(); |
735 | } | |
736 | ||
737 | public MuleContext getMuleContext() | |
738 | { | |
739 | 0 | return event.getMuleContext(); |
740 | } | |
741 | ||
742 | } |