View Javadoc
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.outbound;
8   
9   import org.mule.api.MuleEvent;
10  import org.mule.api.MuleException;
11  import org.mule.api.endpoint.OutboundEndpoint;
12  import org.mule.processor.AbstractInterceptingMessageProcessor;
13  
14  import java.util.List;
15  
16  /**
17   * Propagates properties from request message to response message as defined by
18   * {@link OutboundEndpoint#getResponseProperties()}.
19   * <p>
20   * //TODO This can became a standard MessageProcessor in the response chain if/when
21   * event has a (immutable) reference to request message.
22   */
23  public class OutboundResponsePropertiesMessageProcessor extends AbstractInterceptingMessageProcessor
24  {
25  
26      private OutboundEndpoint endpoint;
27  
28      public OutboundResponsePropertiesMessageProcessor(OutboundEndpoint endpoint)
29      {
30          this.endpoint = endpoint;
31      }
32  
33      public MuleEvent process(MuleEvent event) throws MuleException
34      {
35          MuleEvent responseEvent = processNext(event);
36  
37          if (responseEvent != null)
38          {
39              // Properties which should be carried over from the request message
40              // to the response message
41              List<String> responseProperties = endpoint.getResponseProperties();
42              for (String propertyName : responseProperties)
43              {
44                  Object propertyValue = event.getMessage().getOutboundProperty(propertyName);
45                  if (propertyValue != null)
46                  {
47                      responseEvent.getMessage().setOutboundProperty(propertyName, propertyValue);
48                  }
49              }
50          }
51          return responseEvent;
52      }
53  }