Coverage Report - org.mule.routing.FirstSuccessful
 
Classes in this File Line Coverage Branch Coverage Complexity
FirstSuccessful
0%
0/21
0%
0/14
0
 
 1  
 /*
 2  
  * $Id$
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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  
 /**
 12  
  * FirstSuccessful is a message processor that has a list of target MPs.  Each reveiced event is routed to each
 13  
  * target, in order,  until one succeeds by not throwing an exception.
 14  
  */
 15  
 package org.mule.routing;
 16  
 
 17  
 import org.mule.DefaultMuleEvent;
 18  
 import org.mule.api.MessagingException;
 19  
 import org.mule.api.MuleEvent;
 20  
 import org.mule.api.MuleException;
 21  
 import org.mule.api.MuleMessage;
 22  
 import org.mule.api.endpoint.OutboundEndpoint;
 23  
 import org.mule.api.processor.MessageProcessor;
 24  
 import org.mule.api.routing.CouldNotRouteOutboundMessageException;
 25  
 import org.mule.routing.outbound.AbstractOutboundRouter;
 26  
 
 27  
 
 28  
 /**
 29  
  *  FirstSuccessful routes an event to the first target route that can accept it without throwing or returning an 
 30  
  * exception.  If no such route can be found, an exception is thrown. Note that this works more reliable with
 31  
  * synchronous targets, but no such restriction is imposed.
 32  
  */
 33  0
 public class FirstSuccessful extends AbstractOutboundRouter implements MessageProcessor
 34  
 {
 35  
     /**
 36  
      * Route the given event to one of our targets
 37  
      */
 38  
     @Override
 39  
     public MuleEvent route(MuleEvent event) throws MessagingException
 40  
     {
 41  0
         MuleEvent retval = null;
 42  
 
 43  0
         boolean failed = true;
 44  0
         for (MessageProcessor mp : routes)
 45  
         {
 46  
             try
 47  
             {
 48  0
                 MuleEvent toProcess = event;
 49  0
                 if (mp instanceof OutboundEndpoint)
 50  
                 {
 51  0
                     toProcess = new DefaultMuleEvent(event.getMessage(), (OutboundEndpoint)mp, event.getSession());
 52  
                 }
 53  0
                 retval = mp.process(toProcess);
 54  0
                 if (retval == null)
 55  
                 {
 56  0
                     failed = false;
 57  
                 }
 58  
                 else
 59  
                 {
 60  0
                     MuleMessage msg = retval.getMessage();
 61  0
                     failed = msg != null && msg.getExceptionPayload() != null;
 62  
                 }
 63  
             }
 64  0
             catch (Exception ex)
 65  
             {
 66  0
                 failed = true;
 67  0
             }
 68  0
             if (!failed)
 69  0
                 break;
 70  
         }
 71  
 
 72  0
         if (failed)
 73  
         {
 74  0
             throw new CouldNotRouteOutboundMessageException(event, this);
 75  
         }
 76  
 
 77  0
         return retval;
 78  
     }
 79  
 
 80  
     public boolean isMatch(MuleMessage message) throws MuleException
 81  
     {
 82  0
         return true;
 83  
     }
 84  
 }