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