Coverage Report - org.mule.routing.ForwardingCatchAllStrategy
 
Classes in this File Line Coverage Branch Coverage Complexity
ForwardingCatchAllStrategy
77%
17/22
75%
9/12
4.333
 
 1  
 /*
 2  
  * $Id: ForwardingCatchAllStrategy.java 10961 2008-02-22 19:01:02Z dfeist $
 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  
 package org.mule.routing;
 12  
 
 13  
 import org.mule.DefaultMuleEvent;
 14  
 import org.mule.api.MuleEvent;
 15  
 import org.mule.api.MuleMessage;
 16  
 import org.mule.api.MuleSession;
 17  
 import org.mule.api.endpoint.OutboundEndpoint;
 18  
 import org.mule.api.routing.RoutingException;
 19  
 import org.mule.api.routing.ServiceRoutingException;
 20  
 import org.mule.config.i18n.CoreMessages;
 21  
 
 22  
 /**
 23  
  * <code>ForwardingCatchAllStrategy</code> acts as a catch and forward router for
 24  
  * any events not caught by the router this strategy is associated with. Users can
 25  
  * assign an endpoint to this strategy to forward all events to. This can be used as
 26  
  * a dead letter/error queue.
 27  
  */
 28  
 
 29  6
 public class ForwardingCatchAllStrategy extends AbstractCatchAllStrategy
 30  
 {
 31  6
     private boolean sendTransformed = false;
 32  
 
 33  
     public MuleMessage catchMessage(MuleMessage message, MuleSession session, boolean synchronous)
 34  
         throws RoutingException
 35  
     {
 36  6
         if (getEndpoint() == null)
 37  
         {
 38  2
             throw new ServiceRoutingException(CoreMessages.noCatchAllEndpointSet(), message,
 39  
                 getEndpoint(), session.getService());
 40  
         }
 41  
         try
 42  
         {
 43  4
             OutboundEndpoint endpoint = getEndpoint();
 44  4
             if (sendTransformed && endpoint.getTransformers() != null)
 45  
             {
 46  2
                 message.applyTransformers(endpoint.getTransformers());
 47  
             }
 48  
 
 49  4
             MuleEvent newEvent = new DefaultMuleEvent(message, endpoint, session, synchronous);
 50  
 
 51  4
             if (synchronous)
 52  
             {
 53  2
                 MuleMessage result = endpoint.send(newEvent);
 54  2
                 if (statistics != null)
 55  
                 {
 56  0
                     statistics.incrementRoutedMessage(getEndpoint());
 57  
                 }
 58  2
                 return result;
 59  
             }
 60  
             else
 61  
             {
 62  2
                 endpoint.dispatch(newEvent);
 63  2
                 if (statistics != null)
 64  
                 {
 65  0
                     statistics.incrementRoutedMessage(getEndpoint());
 66  
                 }
 67  2
                 return null;
 68  
             }
 69  
         }
 70  0
         catch (Exception e)
 71  
         {
 72  0
             throw new RoutingException(message, getEndpoint(), e);
 73  
 
 74  
         }
 75  
     }
 76  
 
 77  
     public boolean isSendTransformed()
 78  
     {
 79  0
         return sendTransformed;
 80  
     }
 81  
 
 82  
     public void setSendTransformed(boolean sendTransformed)
 83  
     {
 84  2
         this.sendTransformed = sendTransformed;
 85  2
     }
 86  
 }