Coverage Report - org.mule.routing.ForwardingCatchAllStrategy
 
Classes in this File Line Coverage Branch Coverage Complexity
ForwardingCatchAllStrategy
0%
0/22
0%
0/10
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.routing;
 8  
 
 9  
 import org.mule.DefaultMuleEvent;
 10  
 import org.mule.api.MuleEvent;
 11  
 import org.mule.api.endpoint.OutboundEndpoint;
 12  
 import org.mule.api.processor.MessageProcessor;
 13  
 import org.mule.api.routing.RoutingException;
 14  
 import org.mule.config.i18n.CoreMessages;
 15  
 
 16  
 /**
 17  
  * <code>ForwardingCatchAllStrategy</code> acts as a catch and forward router for
 18  
  * any events not caught by the router this strategy is associated with. Users can
 19  
  * assign an endpoint to this strategy to forward all events to. This can be used as
 20  
  * a dead letter/error queue.
 21  
  *
 22  
  */
 23  0
 public class ForwardingCatchAllStrategy extends AbstractCatchAllStrategy
 24  
 {
 25  0
     private boolean sendTransformed = false;
 26  
 
 27  
     protected OutboundEndpoint endpoint;
 28  
 
 29  
     public void setEndpoint(OutboundEndpoint endpoint)
 30  
     {
 31  0
         this.endpoint = endpoint;
 32  0
     }
 33  
     
 34  
     public void setMessageProcessor(MessageProcessor processor)
 35  
     {
 36  0
         this.endpoint = (OutboundEndpoint) processor;
 37  0
     }
 38  
 
 39  
     public OutboundEndpoint getEndpoint()
 40  
     {
 41  0
         return endpoint;
 42  
     }
 43  
 
 44  
     @Override
 45  
     public MuleEvent doCatchMessage(MuleEvent event) throws RoutingException
 46  
     {
 47  0
         if (getEndpoint() == null)
 48  
         {
 49  0
             throw new RoutingException(CoreMessages.noCatchAllEndpointSet(), event, getEndpoint());
 50  
         }
 51  
         try
 52  
         {
 53  0
             OutboundEndpoint endpoint = getEndpoint();
 54  0
             if (sendTransformed && endpoint.getTransformers() != null)
 55  
             {
 56  0
                 event.getMessage().applyTransformers(event, endpoint.getTransformers());
 57  
             }
 58  
 
 59  
             // Recreate event with outbound endpoint incase anything uses event
 60  
             // endpoint down the line
 61  0
             event = new DefaultMuleEvent(event.getMessage(), endpoint, event.getFlowConstruct(), event);
 62  0
             MuleEvent result = endpoint.process(event);
 63  0
             if (statistics != null && statistics.isEnabled())
 64  
             {
 65  0
                 statistics.incrementRoutedMessage(getEndpoint());
 66  
             }
 67  0
             return result;
 68  
         }
 69  0
         catch (Exception e)
 70  
         {
 71  0
             throw new RoutingException(event, getEndpoint(), e);
 72  
 
 73  
         }
 74  
     }
 75  
 
 76  
     public boolean isSendTransformed()
 77  
     {
 78  0
         return sendTransformed;
 79  
     }
 80  
 
 81  
     public void setSendTransformed(boolean sendTransformed)
 82  
     {
 83  0
         this.sendTransformed = sendTransformed;
 84  0
     }
 85  
 }