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.inbound;
8   
9   import org.mule.api.MuleEvent;
10  import org.mule.api.MuleException;
11  import org.mule.api.config.MuleProperties;
12  import org.mule.api.endpoint.InboundEndpoint;
13  import org.mule.api.processor.MessageProcessor;
14  import org.mule.api.transport.PropertyScope;
15  import org.mule.util.ObjectUtils;
16  import org.mule.util.StringUtils;
17  
18  
19  /**
20   * Sets the inbound endpoint uri on as a property of the message using the following
21   * key: {@link MuleProperties#MULE_ORIGINATING_ENDPOINT_PROPERTY}.
22   */
23  public class InboundEndpointPropertyMessageProcessor implements MessageProcessor
24  {
25      private InboundEndpoint endpoint;
26  
27      public InboundEndpointPropertyMessageProcessor(InboundEndpoint endpoint)
28      {
29          this.endpoint = endpoint;
30      }
31  
32      public MuleEvent process(MuleEvent event) throws MuleException
33      {
34          // If the endpoint has a logical name, use it, otherwise use the URI.
35          String inboundEndpoint = endpoint.getName();
36  
37          if (StringUtils.isBlank(inboundEndpoint))
38          {
39              // URI
40              inboundEndpoint = endpoint.getEndpointURI().getUri().toString();
41          }
42          event.getMessage().setProperty(MuleProperties.MULE_ORIGINATING_ENDPOINT_PROPERTY, inboundEndpoint, PropertyScope.INBOUND);
43          return event;
44      }
45  
46      @Override
47      public String toString()
48      {
49          return ObjectUtils.toString(this);
50      }
51  }