Coverage Report - org.mule.routing.requestreply.SimpleAsyncRequestReplyRequester
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleAsyncRequestReplyRequester
0%
0/48
0%
0/36
0
 
 1  
 /*
 2  
  * $Id: SimpleAsyncRequestReplyRequester.java 20637 2010-12-11 02:32:12Z dfeist $
 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.MuleContext;
 15  
 import org.mule.api.MuleEvent;
 16  
 import org.mule.api.MuleException;
 17  
 import org.mule.api.config.MuleProperties;
 18  
 import org.mule.api.construct.FlowConstructAware;
 19  
 import org.mule.api.context.MuleContextAware;
 20  
 import org.mule.api.endpoint.InboundEndpoint;
 21  
 import org.mule.api.endpoint.OutboundEndpoint;
 22  
 import org.mule.api.lifecycle.Disposable;
 23  
 import org.mule.api.lifecycle.Initialisable;
 24  
 import org.mule.api.lifecycle.Startable;
 25  
 import org.mule.api.lifecycle.Stoppable;
 26  
 import org.mule.api.processor.MessageProcessor;
 27  
 import org.mule.api.source.MessageSource;
 28  
 
 29  0
 public class SimpleAsyncRequestReplyRequester extends AbstractAsyncRequestReplyRequester
 30  
     implements Startable, Stoppable
 31  
 {
 32  
 
 33  
     protected MessageProcessor requestMessageProcessor;
 34  
 
 35  
     @Override
 36  
     protected void sendAsyncRequest(MuleEvent event) throws MuleException
 37  
     {
 38  0
         setAsyncReplyProperties(event);
 39  0
         if (requestMessageProcessor instanceof OutboundEndpoint)
 40  
         {
 41  0
             event = new DefaultMuleEvent(event.getMessage(), (OutboundEndpoint) requestMessageProcessor,
 42  
                 event.getSession());
 43  
         }
 44  0
         requestMessageProcessor.process(event);
 45  0
     }
 46  
 
 47  
     protected void setAsyncReplyProperties(MuleEvent event) throws MuleException
 48  
     {
 49  0
         event.getMessage().setReplyTo(getReplyTo());
 50  0
         event.getMessage().setOutboundProperty(MuleProperties.MULE_REPLY_TO_REQUESTOR_PROPERTY,
 51  
             event.getFlowConstruct().getName());
 52  0
         String correlation = event.getFlowConstruct().getMessageInfoMapping().getCorrelationId(
 53  
             event.getMessage());
 54  0
         event.getMessage().setCorrelationId(correlation);
 55  0
     }
 56  
 
 57  
     private String getReplyTo()
 58  
     {
 59  0
         return ((InboundEndpoint) replyMessageSource).getEndpointURI().getAddress();
 60  
     }
 61  
 
 62  
     @Override
 63  
     protected void verifyReplyMessageSource(MessageSource messageSource)
 64  
     {
 65  0
         if (!(messageSource instanceof InboundEndpoint))
 66  
         {
 67  0
             throw new IllegalArgumentException(
 68  
                 "Only an InboundEndpoint reply MessageSource is supported with SimpleAsyncRequestReplyRequester");
 69  
         }
 70  0
     }
 71  
 
 72  
     public void setMessageProcessor(MessageProcessor processor)
 73  
     {
 74  0
         requestMessageProcessor = processor;
 75  0
     }
 76  
 
 77  
     @Deprecated
 78  
     public void setMessageSource(MessageSource source)
 79  
     {
 80  0
         setReplySource(source);
 81  0
     }
 82  
 
 83  
     public void start() throws MuleException
 84  
     {
 85  0
         if (replyMessageSource != null)
 86  
         {
 87  0
             if (replyMessageSource instanceof FlowConstructAware)
 88  
             {
 89  0
                 ((FlowConstructAware) replyMessageSource).setFlowConstruct(this.flowConstruct);
 90  
             }
 91  0
             if (replyMessageSource instanceof Initialisable)
 92  
             {
 93  0
                 ((Initialisable) replyMessageSource).initialise();
 94  
             }
 95  0
             if (replyMessageSource instanceof Startable)
 96  
             {
 97  0
                 ((Startable) replyMessageSource).start();
 98  
             }
 99  
         }
 100  0
         if (requestMessageProcessor != null)
 101  
         {
 102  0
             if (requestMessageProcessor instanceof FlowConstructAware)
 103  
             {
 104  0
                 ((FlowConstructAware) requestMessageProcessor).setFlowConstruct(this.flowConstruct);
 105  
             }
 106  0
             if (requestMessageProcessor instanceof Initialisable)
 107  
             {
 108  0
                 ((Initialisable) requestMessageProcessor).initialise();
 109  
             }
 110  0
             if (requestMessageProcessor instanceof Startable)
 111  
             {
 112  0
                 ((Startable) requestMessageProcessor).start();
 113  
             }
 114  
         }
 115  0
     }
 116  
 
 117  
     public void stop() throws MuleException
 118  
     {
 119  0
         if (replyMessageSource != null && replyMessageSource instanceof Stoppable)
 120  
         {
 121  0
             ((Stoppable) replyMessageSource).stop();
 122  
 
 123  0
             if (requestMessageProcessor != null && requestMessageProcessor instanceof Stoppable)
 124  
             {
 125  0
                 ((Stoppable) requestMessageProcessor).stop();
 126  
             }
 127  
         }
 128  0
         if (requestMessageProcessor != null)
 129  
         {
 130  0
             if (requestMessageProcessor instanceof Stoppable)
 131  
             {
 132  0
                 ((Stoppable) requestMessageProcessor).stop();
 133  
             }
 134  0
             if (requestMessageProcessor instanceof Disposable)
 135  
             {
 136  0
                 ((Disposable) requestMessageProcessor).dispose();
 137  
             }
 138  
         }
 139  0
     }
 140  
 
 141  
     @Override
 142  
     public void setMuleContext(MuleContext context)
 143  
     {
 144  0
         super.setMuleContext(context);
 145  0
         if (requestMessageProcessor instanceof MuleContextAware)
 146  
         {
 147  0
             ((MuleContextAware)requestMessageProcessor).setMuleContext(context);
 148  
         }
 149  0
     }
 150  
 
 151  
 }