Coverage Report - org.mule.endpoint.DefaultOutboundEndpoint
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultOutboundEndpoint
0%
0/27
0%
0/14
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.endpoint;
 8  
 
 9  
 import org.mule.DefaultMuleEvent;
 10  
 import org.mule.MessageExchangePattern;
 11  
 import org.mule.api.MuleContext;
 12  
 import org.mule.api.MuleEvent;
 13  
 import org.mule.api.MuleException;
 14  
 import org.mule.api.config.MuleProperties;
 15  
 import org.mule.api.construct.FlowConstruct;
 16  
 import org.mule.api.construct.FlowConstructAware;
 17  
 import org.mule.api.context.MuleContextAware;
 18  
 import org.mule.api.endpoint.EndpointMessageProcessorChainFactory;
 19  
 import org.mule.api.endpoint.EndpointURI;
 20  
 import org.mule.api.endpoint.OutboundEndpoint;
 21  
 import org.mule.api.lifecycle.Initialisable;
 22  
 import org.mule.api.processor.MessageProcessor;
 23  
 import org.mule.api.retry.RetryPolicyTemplate;
 24  
 import org.mule.api.transaction.TransactionConfig;
 25  
 import org.mule.api.transport.Connector;
 26  
 import org.mule.transport.AbstractConnector;
 27  
 import org.mule.util.StringUtils;
 28  
 
 29  
 import java.util.ArrayList;
 30  
 import java.util.Arrays;
 31  
 import java.util.List;
 32  
 import java.util.Map;
 33  
 
 34  
 public class DefaultOutboundEndpoint extends AbstractEndpoint implements OutboundEndpoint
 35  
 {
 36  
     private static final long serialVersionUID = 8860985949279708638L;
 37  
 
 38  
     private List<String> responseProperties;
 39  
 
 40  
     public DefaultOutboundEndpoint(Connector connector,
 41  
                                    EndpointURI endpointUri,
 42  
                                    String name,
 43  
                                    Map properties,
 44  
                                    TransactionConfig transactionConfig,
 45  
                                    boolean deleteUnacceptedMessage,
 46  
                                    MessageExchangePattern messageExchangePattern,
 47  
                                    int responseTimeout,
 48  
                                    String initialState,
 49  
                                    String endpointEncoding,
 50  
                                    String endpointBuilderName,
 51  
                                    MuleContext muleContext,
 52  
                                    RetryPolicyTemplate retryPolicyTemplate,
 53  
                                    String responsePropertiesList,
 54  
                                    EndpointMessageProcessorChainFactory messageProcessorsFactory,
 55  
                                    List <MessageProcessor> messageProcessors,
 56  
                                    List <MessageProcessor> responseMessageProcessors,
 57  
                                    boolean disableTransportTransformer,
 58  
                                    String endpointMimeType)
 59  
     {
 60  0
         super(connector, endpointUri, name, properties, transactionConfig, 
 61  
                 deleteUnacceptedMessage, messageExchangePattern, responseTimeout, initialState,
 62  
                 endpointEncoding, endpointBuilderName, muleContext, retryPolicyTemplate, 
 63  
                 messageProcessorsFactory, messageProcessors, responseMessageProcessors, disableTransportTransformer, endpointMimeType);
 64  
 
 65  0
         responseProperties = new ArrayList<String>();
 66  
         // Propagate the Correlation-related properties from the previous message by default (see EE-1613).
 67  0
         responseProperties.add(MuleProperties.MULE_CORRELATION_ID_PROPERTY);
 68  0
         responseProperties.add(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY);
 69  0
         responseProperties.add(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY);
 70  0
         responseProperties.add(MuleProperties.MULE_SESSION_PROPERTY);
 71  
         // Add any additional properties specified by the user.
 72  0
         String[] props = StringUtils.splitAndTrim(responsePropertiesList, ",");
 73  0
         if (props != null)
 74  
         {
 75  0
             responseProperties.addAll(Arrays.asList(props));
 76  
         }
 77  0
     }
 78  
 
 79  
     public List<String> getResponseProperties()
 80  
     {
 81  0
         return responseProperties;
 82  
     }
 83  
 
 84  
     public MuleEvent process(MuleEvent event) throws MuleException
 85  
     {
 86  
         // Update event endpoint for outbound endpoint
 87  0
         MuleEvent outboundEvent = event;
 88  0
         if ((event.getEndpoint() == null || !event.getEndpoint().equals(this)))
 89  
         {
 90  0
             outboundEvent = new DefaultMuleEvent(event.getMessage(), this, event.getSession(), null, event.getProcessingTime(), null);
 91  
         }
 92  0
         MuleEvent resultEvent = getMessageProcessorChain(event.getFlowConstruct()).process(outboundEvent);
 93  
         // Avoid loss replyHandler, replyToDestination
 94  0
         if (resultEvent != null)
 95  
         {
 96  0
             resultEvent = new DefaultMuleEvent(resultEvent.getMessage(),event);
 97  
         }
 98  0
         return resultEvent;
 99  
     }
 100  
 
 101  
     @Override
 102  
     protected MessageProcessor createMessageProcessorChain(FlowConstruct flowContruct) throws MuleException
 103  
     {
 104  0
         EndpointMessageProcessorChainFactory factory = getMessageProcessorsFactory();
 105  0
         MessageProcessor chain = factory.createOutboundMessageProcessorChain(this, flowContruct,
 106  
             ((AbstractConnector) getConnector()).createDispatcherMessageProcessor(this));
 107  
 
 108  0
         if (chain instanceof MuleContextAware)
 109  
         {
 110  0
             ((MuleContextAware) chain).setMuleContext(getMuleContext());
 111  
         }
 112  0
         if (chain instanceof FlowConstructAware)
 113  
         {
 114  0
             ((FlowConstructAware) chain).setFlowConstruct(flowContruct);
 115  
         }
 116  0
         if (chain instanceof Initialisable)
 117  
         {
 118  0
             ((Initialisable) chain).initialise();
 119  
         }
 120  
         
 121  0
         return chain;
 122  
     }
 123  
 }