* @throws ApplicationEventException if the event cannot be dispatched i.e. if
* the underlying transport throws an exception
*/
protected void dispatchEvent(MuleApplicationEvent applicationEvent) throws ApplicationEventException
{
OutboundEndpoint endpoint;
try
{
endpoint = muleContext.getEndpointFactory().getOutboundEndpoint(
applicationEvent.getEndpoint());
}
catch (MuleException e)
{
throw new ApplicationEventException("Failed to get endpoint for endpointUri: "
+ applicationEvent.getEndpoint(), e);
}
if (endpoint != null)
{
try
{
// if (applicationEvent.getEndpoint() != null) {
// endpoint.setEndpointURI(applicationEvent.getEndpoint());
// }
DefaultMuleMessage message = new DefaultMuleMessage(applicationEvent.getSource(),
applicationEvent.getProperties(), muleContext);
// has dispatch been triggered using beanFactory.publish()
// without a current event
if (applicationEvent.getMuleEventContext() != null)
{
// tell mule not to try and route this event itself
applicationEvent.getMuleEventContext().setStopFurtherProcessing(true);
applicationEvent.getMuleEventContext().dispatchEvent(message, endpoint);
}
else
{
MuleSession session = new DefaultMuleSession(service, muleContext);
DefaultMuleEvent event = new DefaultMuleEvent(message, endpoint.getExchangePattern(),
session);
RequestContext.setEvent(event);
// transform if necessary
if (endpoint.getTransformers() != null)
{
message = new DefaultMuleMessage(applicationEvent.getSource(),
applicationEvent.getProperties(), muleContext);
message.applyTransformers(event, endpoint.getTransformers());
}
endpoint.process(new DefaultMuleEvent(message, endpoint.getExchangePattern(), session));
}
}
catch (Exception e1)
{
throw new ApplicationEventException("Failed to dispatch event: " + e1.getMessage(), e1);