Coverage Report - org.mule.routing.requestreply.SimpleAsyncRequestReplyRequester
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleAsyncRequestReplyRequester
0%
0/32
0%
0/16
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.requestreply;
 12  
 
 13  
 import org.mule.DefaultMuleEvent;
 14  
 import org.mule.api.MuleEvent;
 15  
 import org.mule.api.MuleException;
 16  
 import org.mule.api.config.MuleProperties;
 17  
 import org.mule.api.construct.FlowConstruct;
 18  
 import org.mule.api.construct.FlowConstructAware;
 19  
 import org.mule.api.endpoint.InboundEndpoint;
 20  
 import org.mule.api.endpoint.OutboundEndpoint;
 21  
 import org.mule.api.lifecycle.Initialisable;
 22  
 import org.mule.api.lifecycle.Startable;
 23  
 import org.mule.api.lifecycle.Stoppable;
 24  
 import org.mule.api.processor.MessageProcessor;
 25  
 import org.mule.api.source.MessageSource;
 26  
 
 27  0
 public class SimpleAsyncRequestReplyRequester extends AbstractAsyncRequestReplyRequester
 28  
     implements Startable, Stoppable, FlowConstructAware
 29  
 {
 30  
 
 31  
     private MessageProcessor requestMessageProcessor;
 32  
 
 33  
     @Override
 34  
     protected void sendAsyncRequest(MuleEvent event) throws MuleException
 35  
     {
 36  0
         setAsyncReplyProperties(event);
 37  0
         if (requestMessageProcessor instanceof OutboundEndpoint)
 38  
         {
 39  0
             event = new DefaultMuleEvent(event.getMessage(), (OutboundEndpoint) requestMessageProcessor,
 40  
                 event.getSession());
 41  
         }
 42  0
         requestMessageProcessor.process(event);
 43  0
     }
 44  
 
 45  
     protected void setAsyncReplyProperties(MuleEvent event) throws MuleException
 46  
     {
 47  0
         event.getMessage().setReplyTo(getReplyTo());
 48  0
         event.getMessage().setOutboundProperty(MuleProperties.MULE_REPLY_TO_REQUESTOR_PROPERTY,
 49  
             event.getFlowConstruct().getName());
 50  0
         String correlation = event.getFlowConstruct().getMessageInfoMapping().getCorrelationId(
 51  
             event.getMessage());
 52  0
         event.getMessage().setCorrelationId(correlation);
 53  0
     }
 54  
 
 55  
     private String getReplyTo()
 56  
     {
 57  0
         return ((InboundEndpoint) replyMessageSource).getEndpointURI().getAddress();
 58  
     }
 59  
 
 60  
     @Override
 61  
     protected void verifyReplyMessageSource(MessageSource messageSource)
 62  
     {
 63  0
         if (!(messageSource instanceof InboundEndpoint))
 64  
         {
 65  0
             throw new IllegalArgumentException(
 66  
                 "Only an InboundEndpoint reply MessageSource is supported with SimpleAsyncRequestReplyRequester");
 67  
         }
 68  0
     }
 69  
 
 70  
     public void setMessageProcessor(MessageProcessor processor)
 71  
     {
 72  0
         requestMessageProcessor = processor;
 73  0
     }
 74  
 
 75  
     @Deprecated
 76  
     public void setMessageSource(MessageSource source)
 77  
     {
 78  0
         setReplySource(source);
 79  0
     }
 80  
 
 81  
     public void start() throws MuleException
 82  
     {
 83  0
         if (replyMessageSource != null)
 84  
         {
 85  0
             if (replyMessageSource instanceof FlowConstructAware)
 86  
             {
 87  0
                 ((FlowConstructAware) replyMessageSource).setFlowConstruct(this.flowConstruct);
 88  
             }
 89  0
             if (replyMessageSource instanceof Initialisable)
 90  
             {
 91  0
                 ((Initialisable) replyMessageSource).initialise();
 92  
             }
 93  0
             if (replyMessageSource instanceof Startable)
 94  
             {
 95  0
                 ((Startable) replyMessageSource).start();
 96  
             }
 97  
         }
 98  0
     }
 99  
 
 100  
     public void stop() throws MuleException
 101  
     {
 102  0
         if (replyMessageSource != null && replyMessageSource instanceof Stoppable)
 103  
         {
 104  0
             ((Stoppable) replyMessageSource).stop();
 105  
         }
 106  0
     }
 107  
 
 108  
     public void setFlowConstruct(FlowConstruct flowConstruct)
 109  
     {
 110  0
         this.flowConstruct = flowConstruct;
 111  0
     }
 112  
 
 113  
 }