Coverage Report - org.mule.processor.ResponseMessageProcessorAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
ResponseMessageProcessorAdapter
0%
0/32
0%
0/18
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.processor;
 8  
 
 9  
 import org.mule.api.MuleEvent;
 10  
 import org.mule.api.MuleException;
 11  
 import org.mule.api.ThreadSafeAccess;
 12  
 import org.mule.api.construct.FlowConstruct;
 13  
 import org.mule.api.construct.FlowConstructAware;
 14  
 import org.mule.api.context.MuleContextAware;
 15  
 import org.mule.api.lifecycle.Disposable;
 16  
 import org.mule.api.lifecycle.Initialisable;
 17  
 import org.mule.api.lifecycle.InitialisationException;
 18  
 import org.mule.api.lifecycle.Lifecycle;
 19  
 import org.mule.api.lifecycle.Startable;
 20  
 import org.mule.api.lifecycle.Stoppable;
 21  
 import org.mule.api.processor.MessageProcessor;
 22  
 
 23  
 public class ResponseMessageProcessorAdapter extends AbstractResponseMessageProcessor implements Lifecycle, FlowConstructAware
 24  
 {
 25  
 
 26  
     protected MessageProcessor responseProcessor;
 27  
     protected FlowConstruct flowConstruct;
 28  
 
 29  
     public ResponseMessageProcessorAdapter()
 30  
     {
 31  0
         super();
 32  0
     }
 33  
 
 34  
     public ResponseMessageProcessorAdapter(MessageProcessor responseProcessor)
 35  
     {
 36  0
         super();
 37  0
         this.responseProcessor = responseProcessor;
 38  0
     }
 39  
 
 40  
     public void setProcessor(MessageProcessor processor)
 41  
     {
 42  0
         this.responseProcessor = processor;
 43  0
     }
 44  
 
 45  
     @Override
 46  
     protected MuleEvent processResponse(MuleEvent event) throws MuleException
 47  
     {
 48  0
         if (responseProcessor == null || event == null)
 49  
         {
 50  0
             return event;
 51  
         }
 52  
         else
 53  
         {
 54  0
             MuleEvent copy = (MuleEvent) ((ThreadSafeAccess) event).newThreadCopy();
 55  0
             MuleEvent result = responseProcessor.process(event);
 56  0
             if (result == null)
 57  
             {
 58  
                 // If <response> returns null then it acts as an implicit branch like in flows, the different
 59  
                 // here is that what's next, it's not another message processor that follows this one in the
 60  
                 // configuration file but rather the response phase of the inbound endpoint, or optionally
 61  
                 // other response processing on the way back to the inbound endpoint.
 62  0
                 return copy;
 63  
             }
 64  
             else
 65  
             {
 66  0
                 return result;
 67  
             }
 68  
         }
 69  
     }
 70  
 
 71  
     public void initialise() throws InitialisationException
 72  
     {
 73  0
         if (responseProcessor instanceof MuleContextAware)
 74  
         {
 75  0
             ((MuleContextAware) responseProcessor).setMuleContext(muleContext);
 76  
         }
 77  0
         if (responseProcessor instanceof FlowConstructAware)
 78  
         {
 79  0
             ((FlowConstructAware) responseProcessor).setFlowConstruct(flowConstruct);
 80  
         }
 81  0
         if (responseProcessor instanceof Initialisable)
 82  
         {
 83  0
             ((Initialisable) responseProcessor).initialise();
 84  
         }
 85  0
     }
 86  
 
 87  
     public void start() throws MuleException
 88  
     {
 89  0
         if (responseProcessor instanceof Startable)
 90  
         {
 91  0
             ((Startable) responseProcessor).start();
 92  
         }
 93  0
     }
 94  
 
 95  
     public void stop() throws MuleException
 96  
     {
 97  0
         if (responseProcessor instanceof Stoppable)
 98  
         {
 99  0
             ((Stoppable) responseProcessor).stop();
 100  
         }
 101  0
     }
 102  
 
 103  
     public void dispose()
 104  
     {
 105  0
         if (responseProcessor instanceof Disposable)
 106  
         {
 107  0
             ((Disposable) responseProcessor).dispose();
 108  
         }
 109  0
     }
 110  
 
 111  
     public void setFlowConstruct(FlowConstruct flowConstruct)
 112  
     {
 113  0
         this.flowConstruct = flowConstruct;
 114  0
     }
 115  
 
 116  
 }