Coverage Report - org.mule.routing.inbound.ForwardingConsumer
 
Classes in this File Line Coverage Branch Coverage Complexity
ForwardingConsumer
0%
0/26
0%
0/24
13
 
 1  
 /*
 2  
  * $Id: ForwardingConsumer.java 10498 2008-01-24 10:19:31Z 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.inbound;
 12  
 
 13  
 import org.mule.MuleManager;
 14  
 import org.mule.impl.MuleEvent;
 15  
 import org.mule.impl.MuleMessage;
 16  
 import org.mule.impl.model.seda.SedaComponent;
 17  
 import org.mule.umo.MessagingException;
 18  
 import org.mule.umo.UMOComponent;
 19  
 import org.mule.umo.UMOEvent;
 20  
 import org.mule.umo.UMOException;
 21  
 import org.mule.umo.UMOMessage;
 22  
 import org.mule.umo.routing.RoutingException;
 23  
 import org.mule.umo.routing.UMOInboundRouterCollection;
 24  
 import org.mule.umo.routing.UMOOutboundRouterCollection;
 25  
 
 26  
 /**
 27  
  * <code>ForwardingConsumer</code> is used to forward an incoming event over
 28  
  * another transport without invoking a component. This can be used to implement a
 29  
  * bridge accross defferent transports.
 30  
  */
 31  0
 public class ForwardingConsumer extends SelectiveConsumer
 32  
 {
 33  
 
 34  
     public UMOEvent[] process(UMOEvent event) throws MessagingException
 35  
     {
 36  0
         if (super.process(event) != null)
 37  
         {
 38  0
             UMOOutboundRouterCollection router = event.getComponent().getDescriptor().getOutboundRouter();
 39  
 
 40  
             // Set the stopFurtherProcessing flag to true to inform the
 41  
             // InboundRouterCollection not to route these events to the component
 42  0
             event.setStopFurtherProcessing(true);
 43  
 
 44  0
             UMOComponent component = event.getComponent();
 45  
 
 46  
             //MULE-2599
 47  0
             if (component != null && component instanceof SedaComponent &&
 48  
                 ((MuleManager) MuleManager.getInstance()).getStatistics() != null &&
 49  
                 ((MuleManager) MuleManager.getInstance()).getStatistics().isEnabled())
 50  
             {
 51  0
                 if (((SedaComponent) component).getStatistics().isEnabled())
 52  
                 {
 53  0
                     if (event.isSynchronous())
 54  
                     {
 55  0
                         ((SedaComponent) component).getStatistics().incReceivedEventSync();
 56  0
                         ((SedaComponent) component).getStatistics().incSentEventSync();
 57  
                     }
 58  
                     else
 59  
                     {
 60  0
                         ((SedaComponent) component).getStatistics().incReceivedEventASync();
 61  0
                         ((SedaComponent) component).getStatistics().incSentEventASync();
 62  
                     }
 63  0
                     UMOInboundRouterCollection inboundRouter = event.getComponent().getDescriptor().getInboundRouter();
 64  0
                     if (inboundRouter != null && inboundRouter.getStatistics() != null && inboundRouter.getStatistics().isEnabled())
 65  
                     {
 66  0
                         inboundRouter.getStatistics().incrementRoutedMessage(event.getEndpoint());
 67  
                     }
 68  
 
 69  
                 }
 70  
             }
 71  
 
 72  
 
 73  0
             if (router == null)
 74  
             {
 75  0
                 logger.debug("Descriptor has no outbound router configured to forward to, continuing with normal processing");
 76  0
                 return new UMOEvent[]{event};
 77  
             }
 78  
             else
 79  
             {
 80  
                 try
 81  
                 {
 82  0
                     UMOMessage message = new MuleMessage(event.getTransformedMessage(), event.getMessage());
 83  
 
 84  0
                     UMOMessage response = router.route(message, event.getSession(), event.isSynchronous());
 85  
                     // TODO What's the correct behaviour for async endpoints?
 86  
                     // maybe let router.route() return a Future for the returned msg?
 87  0
                     if (response != null)
 88  
                     {
 89  0
                         return new UMOEvent[]{new MuleEvent(response, event)};
 90  
                     }
 91  
                     else
 92  
                     {
 93  0
                         return null;
 94  
                     }
 95  
 
 96  
                 }
 97  0
                 catch (UMOException e)
 98  
                 {
 99  0
                     throw new RoutingException(event.getMessage(), event.getEndpoint(), e);
 100  
                 }
 101  
             }
 102  
         }
 103  0
         return null;
 104  
     }
 105  
 }