Coverage Report - org.mule.routing.WireTap
 
Classes in this File Line Coverage Branch Coverage Complexity
WireTap
0%
0/19
0%
0/2
0
WireTap$1
N/A
N/A
0
WireTap$WireTapFilter
0%
0/7
0%
0/4
0
 
 1  
 /*
 2  
  * $Id$
 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.RequestContext;
 14  
 import org.mule.api.MuleEvent;
 15  
 import org.mule.api.MuleException;
 16  
 import org.mule.api.processor.MessageProcessor;
 17  
 import org.mule.api.routing.filter.Filter;
 18  
 import org.mule.processor.AbstractFilteringMessageProcessor;
 19  
 import org.mule.processor.AbstractMessageObserver;
 20  
 
 21  
 /**
 22  
  * The <code>WireTap</code> MessageProcessor allows inspection of messages in a flow.
 23  
  * <p>
 24  
  * The incoming message is is sent to both the primary and wiretap outputs. The flow
 25  
  * of the primary output will be unmodified and a copy of the message used for the
 26  
  * wiretap output.
 27  
  * <p>
 28  
  * An optional filter can be used to filter which message are sent to the wiretap
 29  
  * output, this filter does not affect the flow to the primary output. If there is an
 30  
  * error sending to the wiretap output no exception will be thrown but rather an
 31  
  * error logged.
 32  
  * <p>
 33  
  * <b>EIP Reference:</b> <a href="http://www.eaipatterns.com/WireTap.html">http://www.eaipatterns.com/WireTap.html<a/>
 34  
  */
 35  0
 public class WireTap extends AbstractMessageObserver
 36  
 
 37  
 {
 38  
     protected volatile MessageProcessor tap;
 39  
     protected volatile Filter filter;
 40  
 
 41  0
     protected MessageProcessor filteredTap = new WireTapFilter();
 42  
 
 43  
     @Override
 44  
     public void observe(MuleEvent event)
 45  
     {
 46  0
         if (tap == null)
 47  
         {
 48  0
             return;
 49  
         }
 50  
 
 51  
         try
 52  
         {
 53  
             // Do we need this?
 54  0
             RequestContext.setEvent(null);
 55  0
             filteredTap.process(RequestContext.cloneAndUpdateEventEndpoint(event, tap));
 56  
         }
 57  0
         catch (MuleException e)
 58  
         {
 59  0
             logger.error("Exception sending to wiretap output " + tap, e);
 60  0
         }
 61  0
     }
 62  
 
 63  
     public MessageProcessor getTap()
 64  
     {
 65  0
         return tap;
 66  
     }
 67  
 
 68  
     public void setTap(MessageProcessor tap)
 69  
     {
 70  0
         this.tap = tap;
 71  0
     }
 72  
 
 73  
     @Deprecated
 74  
     public void setMessageProcessor(MessageProcessor tap)
 75  
     {
 76  0
         setTap(tap);
 77  0
     }
 78  
     
 79  
     public Filter getFilter()
 80  
     {
 81  0
         return filter;
 82  
     }
 83  
 
 84  
     public void setFilter(Filter filter)
 85  
     {
 86  0
         this.filter = filter;
 87  0
     }
 88  
 
 89  0
     private class WireTapFilter extends AbstractFilteringMessageProcessor
 90  
     {
 91  
         @Override
 92  
         protected boolean accept(MuleEvent event)
 93  
         {
 94  0
             if (filter == null)
 95  
             {
 96  0
                 return true;
 97  
             }
 98  
             else
 99  
             {
 100  0
                 return filter.accept(event.getMessage());
 101  
             }
 102  
         }
 103  
 
 104  
         @Override
 105  
         protected MuleEvent processNext(MuleEvent event) throws MuleException
 106  
         {
 107  0
             if (tap != null)
 108  
             {
 109  0
                 tap.process(event);
 110  
             }
 111  0
             return null;
 112  
         }
 113  
     }
 114  
 
 115  
 }