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  
  * $Id: ForwardingCatchAllStrategy.java 20343 2010-11-24 21:02:10Z mike.schilling $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.endpoint.OutboundEndpoint;
 16  
 import org.mule.api.processor.MessageProcessor;
 17  
 import org.mule.api.routing.RoutingException;
 18  
 import org.mule.config.i18n.CoreMessages;
 19  
 
 20  
 /**
 21  
  * <code>ForwardingCatchAllStrategy</code> acts as a catch and forward router for
 22  
  * any events not caught by the router this strategy is associated with. Users can
 23  
  * assign an endpoint to this strategy to forward all events to. This can be used as
 24  
  * a dead letter/error queue.
 25  
  *
 26  
  */
 27  0
 public class ForwardingCatchAllStrategy extends AbstractCatchAllStrategy
 28  
 {
 29  0
     private boolean sendTransformed = false;
 30  
 
 31  
     protected OutboundEndpoint endpoint;
 32  
 
 33  
     public void setEndpoint(OutboundEndpoint endpoint)
 34  
     {
 35  0
         this.endpoint = endpoint;
 36  0
     }
 37  
     
 38  
     public void setMessageProcessor(MessageProcessor processor)
 39  
     {
 40  0
         this.endpoint = (OutboundEndpoint) processor;
 41  0
     }
 42  
 
 43  
     public OutboundEndpoint getEndpoint()
 44  
     {
 45  0
         return endpoint;
 46  
     }
 47  
 
 48  
     @Override
 49  
     public MuleEvent doCatchMessage(MuleEvent event) throws RoutingException
 50  
     {
 51  0
         if (getEndpoint() == null)
 52  
         {
 53  0
             throw new RoutingException(CoreMessages.noCatchAllEndpointSet(), event, getEndpoint());
 54  
         }
 55  
         try
 56  
         {
 57  0
             OutboundEndpoint endpoint = getEndpoint();
 58  0
             if (sendTransformed && endpoint.getTransformers() != null)
 59  
             {
 60  0
                 event.getMessage().applyTransformers(event, endpoint.getTransformers());
 61  
             }
 62  
 
 63  
             // Recreate event with outbound endpoint incase anything uses event
 64  
             // endpoint down the line
 65  0
             event = new DefaultMuleEvent(event.getMessage(), endpoint, event.getFlowConstruct(), event);
 66  0
             MuleEvent result = endpoint.process(event);
 67  0
             if (statistics != null && statistics.isEnabled())
 68  
             {
 69  0
                 statistics.incrementRoutedMessage(getEndpoint());
 70  
             }
 71  0
             return result;
 72  
         }
 73  0
         catch (Exception e)
 74  
         {
 75  0
             throw new RoutingException(event, getEndpoint(), e);
 76  
 
 77  
         }
 78  
     }
 79  
 
 80  
     public boolean isSendTransformed()
 81  
     {
 82  0
         return sendTransformed;
 83  
     }
 84  
 
 85  
     public void setSendTransformed(boolean sendTransformed)
 86  
     {
 87  0
         this.sendTransformed = sendTransformed;
 88  0
     }
 89  
 }