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

Set Payload Transformer Reference

This transformer sets the payload to whatever you define. The payload can be a literal string or a Mule Expression.

Configuration

set_payload

Field Description

Display Name

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

Value: Set Payload
XML: doc:name="Set Payload"

Value

Enter a literal string or a Mule expression that defines how Mule should set the payload.

Value: String or Mule Expression
XML: value="#['Hello, ' + message.payload]"


    
            
         
1
2
3
4
5
6
7
# Example setting a payload to a literal string.
 
<set-payload value="MyNewPayload" doc:name="Set Payload"/>
 
# Example setting a payload using a Mule expression. This takes the current payload and transforms it by adding the string "Hello " in front of it. Thus, if your payload was "Charlie", this set-payload transformer changes it to "Hello, Charlie".
 
<set-payload value="#['Hello, ' + message.payload]" doc:name="Set Payload"/>
Element Description

set-payload

Set a payload on your message (as shown in examples above).

Element Attribute Description

value

The literal string or Mule expression that defines how Mule should set the payload.

doc:name

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

Note: Attribute not required in Mule Standalone configuration.

Example

In this example, the Set Payload transformer sets the payload to a "Hello, World" message that includes today’s date (retrieved using a Mule expression.)

set+payload+flow

The following example sets the Set Payload to:
#['Hello World!' + ' Today is ' + server.dateTime.format('dd/MM/yy')]

This displays: "Hello World! Today is <today’s date>"


    
            
         
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
        xmlns:spring="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking
http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd"&gt;
    &lt;http:listener-config name="HTTP_Listener_Configuration"
    host="localhost" port="8081" doc:name="HTTP Listener Configuration"/&gt;
    &lt;flow name="test"&gt;
        &lt;http:listener config-ref="HTTP_Listener_Configuration"
        path="/" doc:name="HTTP"/&gt;
        &lt;set-payload
        value="#['Hello World!' + ' Today is ' + server.dateTime.format('dd/MM/yy')]"
        doc:name="Set Payload"/&gt;
    &lt;/flow&gt;
&lt;/mule&gt;