Coverage Report - org.mule.routing.WireTap
 
Classes in this File Line Coverage Branch Coverage Complexity
WireTap
0%
0/22
0%
0/2
0
WireTap$1
N/A
N/A
0
WireTap$WireTapFilter
0%
0/8
0%
0/4
0
 
 1  
 /*
 2  
  * $Id: WireTap.java 20555 2010-12-09 17:54:31Z aperepel $
 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.AbstractMessageProcessorOwner;
 20  
 import org.mule.util.ObjectUtils;
 21  
 
 22  
 import org.apache.commons.logging.Log;
 23  
 import org.apache.commons.logging.LogFactory;
 24  
 
 25  
 import java.util.Collections;
 26  
 import java.util.List;
 27  
 
 28  
 /**
 29  
  * The <code>WireTap</code> MessageProcessor allows inspection of messages in a flow.
 30  
  * <p>
 31  
  * The incoming message is is sent to both the primary and wiretap outputs. The flow
 32  
  * of the primary output will be unmodified and a copy of the message used for the
 33  
  * wiretap output.
 34  
  * <p>
 35  
  * An optional filter can be used to filter which message are sent to the wiretap
 36  
  * output, this filter does not affect the flow to the primary output. If there is an
 37  
  * error sending to the wiretap output no exception will be thrown but rather an
 38  
  * error logged.
 39  
  * <p>
 40  
  * <b>EIP Reference:</b> <a href="http://www.eaipatterns.com/WireTap.html">http://www.eaipatterns.com/WireTap.html<a/>
 41  
  */
 42  0
 public class WireTap extends AbstractMessageProcessorOwner implements MessageProcessor
 43  
 {
 44  0
     protected final transient Log logger = LogFactory.getLog(getClass());
 45  
     protected volatile MessageProcessor tap;
 46  
     protected volatile Filter filter;
 47  
 
 48  0
     protected MessageProcessor filteredTap = new WireTapFilter();
 49  
 
 50  
     public MuleEvent process(MuleEvent event) throws MuleException
 51  
     {
 52  0
         if (tap == null)
 53  
         {
 54  0
             return event;
 55  
         }
 56  
 
 57  
         try
 58  
         {
 59  
             // Do we need this?
 60  0
             RequestContext.setEvent(null);
 61  0
             filteredTap.process(RequestContext.cloneAndUpdateEventEndpoint(event, tap));
 62  
         }
 63  0
         catch (MuleException e)
 64  
         {
 65  0
             logger.error("Exception sending to wiretap output " + tap, e);
 66  0
         }
 67  
 
 68  0
         return event;
 69  
     }
 70  
 
 71  
     public MessageProcessor getTap()
 72  
     {
 73  0
         return tap;
 74  
     }
 75  
 
 76  
     public void setTap(MessageProcessor tap)
 77  
     {
 78  0
         this.tap = tap;
 79  0
     }
 80  
 
 81  
     @Deprecated
 82  
     public void setMessageProcessor(MessageProcessor tap)
 83  
     {
 84  0
         setTap(tap);
 85  0
     }
 86  
     
 87  
     public Filter getFilter()
 88  
     {
 89  0
         return filter;
 90  
     }
 91  
 
 92  
     public void setFilter(Filter filter)
 93  
     {
 94  0
         this.filter = filter;
 95  0
     }
 96  
 
 97  0
     private class WireTapFilter extends AbstractFilteringMessageProcessor
 98  
     {
 99  
         @Override
 100  
         protected boolean accept(MuleEvent event)
 101  
         {
 102  0
             if (filter == null)
 103  
             {
 104  0
                 return true;
 105  
             }
 106  
             else
 107  
             {
 108  0
                 return filter.accept(event.getMessage());
 109  
             }
 110  
         }
 111  
 
 112  
         @Override
 113  
         protected MuleEvent processNext(MuleEvent event) throws MuleException
 114  
         {
 115  0
             if (tap != null)
 116  
             {
 117  0
                 tap.process(event);
 118  
             }
 119  0
             return null;
 120  
         }
 121  
 
 122  
         @Override
 123  
         public String toString()
 124  
         {
 125  0
             return ObjectUtils.toString(this);
 126  
         }
 127  
     }
 128  
 
 129  
     @Override
 130  
     public String toString()
 131  
     {
 132  0
         return ObjectUtils.toString(this);
 133  
     }
 134  
 
 135  
         @Override
 136  
     protected List<MessageProcessor> getOwnedMessageProcessors()
 137  
     {
 138  0
         return Collections.singletonList(tap);
 139  
     }
 140  
 
 141  
 }