Coverage Report - org.mule.routing.requestreply.ReplyToPropertyRequestReplyReplier
 
Classes in this File Line Coverage Branch Coverage Complexity
ReplyToPropertyRequestReplyReplier
0%
0/22
0%
0/18
2.25
 
 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.requestreply;
 12  
 
 13  
 import org.mule.api.MuleEvent;
 14  
 import org.mule.api.MuleException;
 15  
 import org.mule.api.MuleMessage;
 16  
 import org.mule.api.config.MuleProperties;
 17  
 import org.mule.api.endpoint.InboundEndpoint;
 18  
 import org.mule.api.processor.MessageProcessor;
 19  
 import org.mule.api.processor.RequestReplyReplierMessageProcessor;
 20  
 import org.mule.api.transport.ReplyToHandler;
 21  
 import org.mule.processor.AbstractInterceptingMessageProcessor;
 22  
 import org.mule.transport.AbstractConnector;
 23  
 
 24  
 import org.apache.commons.lang.BooleanUtils;
 25  
 
 26  0
 public class ReplyToPropertyRequestReplyReplier extends AbstractInterceptingMessageProcessor
 27  
     implements RequestReplyReplierMessageProcessor
 28  
 {
 29  
 
 30  
     public MuleEvent process(MuleEvent event) throws MuleException
 31  
     {
 32  0
         Object replyTo = event.getMessage().getReplyTo();
 33  0
         ReplyToHandler replyToHandler = getReplyToHandler(event.getMessage(),
 34  
             (InboundEndpoint) event.getEndpoint());
 35  
         // Do not propagate REPLY_TO
 36  0
         event.getMessage().setReplyTo(null);
 37  
 
 38  0
         MuleEvent resultEvent = processNext(event);
 39  
 
 40  
         // Allow components to stop processing of the ReplyTo property (e.g. CXF)
 41  0
         final String replyToStop = resultEvent.getMessage().getInvocationProperty(
 42  
             MuleProperties.MULE_REPLY_TO_STOP_PROPERTY);
 43  0
         if (resultEvent != null && !BooleanUtils.toBoolean(replyToStop))
 44  
         {
 45  0
             processReplyTo(event, resultEvent, replyToHandler, replyTo);
 46  
         }
 47  
 
 48  0
         return resultEvent;
 49  
     }
 50  
 
 51  
     protected ReplyToHandler getReplyToHandler(MuleMessage message, InboundEndpoint endpoint)
 52  
     {
 53  0
         Object replyTo = message.getReplyTo();
 54  0
         ReplyToHandler replyToHandler = null;
 55  0
         if (replyTo != null)
 56  
         {
 57  0
             replyToHandler = ((AbstractConnector) endpoint.getConnector()).getReplyToHandler(endpoint);
 58  
             // Use the response transformer for the event if one is set
 59  0
             if (endpoint.getResponseTransformers() != null)
 60  
             {
 61  0
                 replyToHandler.setTransformers(endpoint.getResponseTransformers());
 62  
             }
 63  
         }
 64  0
         return replyToHandler;
 65  
     }
 66  
 
 67  
     protected void processReplyTo(MuleEvent event,
 68  
                                   MuleEvent result,
 69  
                                   ReplyToHandler replyToHandler,
 70  
                                   Object replyTo) throws MuleException
 71  
     {
 72  0
         if (result != null && replyToHandler != null)
 73  
         {
 74  0
             String requestor = result.getMessage().getOutboundProperty(
 75  
                 MuleProperties.MULE_REPLY_TO_REQUESTOR_PROPERTY);
 76  0
             if ((requestor != null && !requestor.equals(event.getFlowConstruct().getName()))
 77  
                 || requestor == null)
 78  
             {
 79  0
                 replyToHandler.processReplyTo(event, result.getMessage(), replyTo);
 80  
             }
 81  
         }
 82  0
     }
 83  
 
 84  
     public void setReplyProcessor(MessageProcessor replyMessageProcessor)
 85  
     {
 86  
         // Not used
 87  0
     }
 88  
 
 89  
 }