Coverage Report - org.mule.service.processor.ServiceOutboundMessageProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
ServiceOutboundMessageProcessor
0%
0/20
0%
0/22
4.5
 
 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.service.processor;
 12  
 
 13  
 import org.mule.DefaultMuleEvent;
 14  
 import org.mule.DefaultMuleMessage;
 15  
 import org.mule.api.MuleEvent;
 16  
 import org.mule.api.MuleException;
 17  
 import org.mule.api.routing.OutboundRouterCollection;
 18  
 import org.mule.api.service.Service;
 19  
 import org.mule.component.simple.PassThroughComponent;
 20  
 import org.mule.processor.AbstractInterceptingMessageProcessor;
 21  
 import org.mule.transport.NullPayload;
 22  
 
 23  
 /**
 24  
  * Responsible for determining if the Service outbound phase should be used and
 25  
  * making a copy of the event to use.
 26  
  * <p>
 27  
  * If the service component is a {@link PassThroughComponent} a null from the
 28  
  * outbound phase will result in a {@link NullPayload} being returned, otherwise when
 29  
  * the outbound phase returns null this MessageProcessor will return the request
 30  
  * event.
 31  
  */
 32  
 public class ServiceOutboundMessageProcessor extends AbstractInterceptingMessageProcessor
 33  
 {
 34  
 
 35  
     protected Service service;
 36  
 
 37  
     public ServiceOutboundMessageProcessor(Service service)
 38  0
     {
 39  0
         this.service = service;
 40  0
     }
 41  
 
 42  
     public MuleEvent process(MuleEvent event) throws MuleException
 43  
     {
 44  
         // Skip outbound phase is inbound is sync and payload is NullPayload
 45  0
         boolean syncNullPayload = event.getEndpoint().getExchangePattern().hasResponse()
 46  
                                   && (event.getMessage().getPayload() instanceof NullPayload);
 47  
 
 48  0
         if (event.isStopFurtherProcessing())
 49  
         {
 50  0
             logger.debug("MuleEvent stop further processing has been set, no outbound routing will be performed.");
 51  0
             return event;
 52  
         }
 53  
 
 54  0
         else if (event != null && !syncNullPayload)
 55  
         {
 56  0
             if (!(service.getOutboundMessageProcessor() instanceof OutboundRouterCollection)
 57  
                 || (service.getOutboundMessageProcessor() instanceof OutboundRouterCollection && ((OutboundRouterCollection) service.getOutboundMessageProcessor()).hasEndpoints()))
 58  
             {
 59  
                 MuleEvent outboundEvent;
 60  0
                 if (event.getEndpoint().getExchangePattern().hasResponse())
 61  
                 {
 62  
                     // Copy of the inbound event for outbound phase
 63  0
                     outboundEvent = new DefaultMuleEvent(new DefaultMuleMessage(event.getMessage()
 64  
                         .getPayload(), event.getMessage(), service.getMuleContext()), event);
 65  
                 }
 66  
                 else
 67  
                 {
 68  0
                     outboundEvent = event;
 69  
                 }
 70  
 
 71  0
                 MuleEvent outboundResult = processNext(outboundEvent);
 72  
 
 73  0
                 if (outboundResult != null)
 74  
                 {
 75  0
                     event = outboundResult;
 76  
                 }
 77  0
                 else if (service.getComponent() instanceof PassThroughComponent)
 78  
                 {
 79  
                     // If there was no component, then we really want to return
 80  
                     // the response from the outbound router as the actual
 81  
                     // payload - even if it's null.
 82  0
                     event = new DefaultMuleEvent(new DefaultMuleMessage(NullPayload.getInstance(),
 83  
                         event.getMessage(), service.getMuleContext()), event);
 84  
                 }
 85  0
             }
 86  
             else
 87  
             {
 88  0
                 logger.debug("Outbound router on service '" + service.getName()
 89  
                              + "' doesn't have any targets configured.");
 90  
             }
 91  
         }
 92  0
         return event;
 93  
     }
 94  
 }