Nav
You are viewing an older version of this section. Click here to navigate to the latest version.

Property Transformer Reference

Use a property transformer to set, remove, or copy properties on the outbound scope of a message. This transformer "transforms" only outbound properties. Note that you cannot manipulate inbound scope properties, as those are automatically generated by the message source. To learn more about message scopes, refer to Mule Concepts.

The property transformer differs from the variable transformer and the session variable transformer. Refer to the table below for a comparison of these three transformers.

Property Transformer Variable Transformer Session Variable Transformer

Use

Use to set, remove, or copy properties on the outbound scope of a message.

Use to set or remove a variable on the message, tied to the current flow.

Use to set or remove a variable that is tied to the current message for its entire lifecycle, across multiple flows, applications, and even servers.

Persistence

Once a message hits an outbound-endpoint, all properties in the outbound scope are sent with the message, in the form of transport-specific metadata (HTTP headers for an HTTP outbound-endpoint, for example).

Variables set with a variable transformer persist only for the current flow and cannot cross the transport barrier.

Session variables set with a session variable transformer persist for the entire message lifecycle, regardless of transport barriers.

Configuration

Studio_PropertiesTransformerPPP

Field Value Description XML

Display Name

Property

Customize to display a unique name for the transformer in your application.


         
                 
              
1
doc:name="Property"

Operation

Set Property

Select to set a new property on the outbound scope of your message (as shown in example above).


         
                 
              
1
<set-property>

Remove Property

Select to delete an existing property from your message to remove it from the outbound scope.


         
                 
              
1
<remove-property> 

Copy Property

Select to copy an existing property from the inbound scope onto the outbound scope of your message.


         
                 
              
1
<copy-properties> 

Name

String or Mule Expression

Specify the name for the property that you are creating, or identify the name of the property that you are copying or removing. If you are copying or removing properties, this field accepts a wildcard "*" character.


         
                 
              
1
propertyName="MyNewPropertyName"

Value

String or Mule Expression

This field displays only if you are setting a new property. Specify the value using either a string or a Mule expression, as shown in the example screenshot above.


         
                 
              
1
value="MyNewPropertyValue"

    
            
         
1
2
3
4
5
6
7
8
9
10
11
12
13
#Set property
     
<set-property propertyName="Authorization"  doc:name="Set Authentication Header" value="#["Basic " + Base64.encodeBase64String("username:password")]"/>
     
     
# Remove property
 
<remove-property propertyName="PropertyForRemoval" doc:name="Delete Property"/>
     
   
# Copy property
    
<copy-properties propertyName="http.*" doc:name="Copy All HTTP Headers"/>
Element Description

set-property

Set a new property on the outbound scope of your message (as shown in example below).

remove-property

Delete an existing property from your message to remove it from the outbound scope.

copy-properties

Copy an existing property from the inbound scope onto the outbound scope of your message

Example

In the example below, we want to connect to a web service protected by an HTTP basic authentication mechanism. In order to do that, our HTTP request needs to include a header, Authorization, which contains the username and password that allows the request go through. The properties transformer shown below sets an outbound property named Authorization and applies the value that is required to authenticate the message. The HTTP transport turns this outbound property into an HTTP header.

Studio_PropertyTransformer


    
            
         
1
2
3
4
5
<flow name="PropertyTransformingFlow" doc:name="PropertyTransformingFlow">
   <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
      <set-property propertyName="Authorization"  doc:name="Set Authentication Header" value="#["Basic " + Base64.encodeBase64String("username:password")]"/>
   <http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" method="POST" doc:name="HTTP"/>
</flow>

Complete Code Example


         
      
1
2
3
4
5
6
7
<flow name="PropertyTransformingFlow" doc:name="PropertyTransformingFlow">
   <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
      <set-property propertyName="Authorization"  doc:name="Set Authentication Header" value="#[&quot;Basic &quot; + Base64.encodeBase64String(&quot;username:password&quot;)]"/>
      <remove-property propertyName="PropertyForRemoval" doc:name="Delete Property"/>
      <copy-properties propertyName="http.*" doc:name="Copy All HTTP Headers"/>
   <http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" method="POST" doc:name="HTTP"/>
</flow>

See Also