protected MessageProcessor defaultRoute;
public MuleEvent process(MuleEvent event) throws MuleException
{
MuleMessage message = event.getMessage();
MuleSession session = event.getSession();
MuleEvent result;
boolean matchfound = false;
for (Iterator iterator = matchableRoutes.iterator(); iterator.hasNext();)
{
MatchableMessageProcessor outboundRouter = (MatchableMessageProcessor) iterator.next();
final MuleEvent eventToRoute;
boolean copyEvent = false;
// Create copy of message for router 1..n-1 if matchAll="true" or if
// routers require copy because it may mutate payload before match is
// chosen
if (iterator.hasNext())
{
if (isMatchAll())
{
copyEvent = true;
}
else if (outboundRouter instanceof TransformingMatchable)
{
copyEvent = ((TransformingMatchable) outboundRouter).isTransformBeforeMatch();
}
}
if (copyEvent)
{
if (((DefaultMuleMessage) message).isConsumable())
{
throw new MessagingException(CoreMessages.cannotCopyStreamPayload(message.getPayload().getClass().getName()), event);
}
eventToRoute = OptimizedRequestContext.criticalSetEvent(event);
}
else
{
eventToRoute = event;
}
if (outboundRouter.isMatch(eventToRoute.getMessage()))
{
matchfound = true;
result = outboundRouter.process(event);
if (!isMatchAll())
{
return result;
}
}
}
if (!matchfound && defaultRoute != null)
{
if (logger.isDebugEnabled())
{
logger.debug("Message did not match any routers on: " + session.getFlowConstruct().getName()
+ " invoking catch all strategy");
}
return processDefaultRoute(event);
}
else if (!matchfound)
{
logger.warn("Message did not match any routers on: "
+ session.getFlowConstruct().getName()
+ " and there is no catch all strategy configured on this router. Disposing message "
+ message);
}
return event;
}