Reputation: 5
I am trying to set the header values for the outbound message. I can see the values in the http.headers in the debugging mode. However it is not displaying the postman's header.
And below is the snippet As you can see I have tried to set up header using two different ways
{code}
**<set-property propertyName="http.headers.code" value="C01" doc:name="headerCode"/>**
<set-payload value="{
 "coord": {
 "lon": -0.13,
 "lat": 51.51
 },
 "main": {
 "temp": 290.24,
 "pressure": 1016,
 "humidity": 77,
 "temp_min": 288.15,
 "temp_max": 292.15
 },
 "id": 2643743,
 "name": "London",
 "cod": 200
 }" doc:name="Set Payload"/>
**<message-properties-transformer doc:name="Message Properties">
<add-message-property key="http.headers.id" value="ID01" />
</message-properties-transformer>**
<logger message="header-property logger" level="INFO" doc:name="Logger"/>
</flow>
{code}
Attached debugging screenshot Debugging screenshot
postman collection screenshot I have expected to see the values in the headers. But it is not displaying Could anyone shed light on this please. Thank you and regards Nivi
Upvotes: 0
Views: 2702
Reputation: 461
When setting outbound properties in Mule (my experience being with 3.8 onwards) they will default to the HTTP header, so you do not need to include 'http.headers.' in your property element, only the name of the header you wish to add.
E.g. if your set-property element is:
<set-property propertyName="id" value="ID01" doc:name="Add ID Header" />
Then when calling the service this will add "id" as an HTTP response header.
My whole flow is:
<flow name="testFlow">
<http:listener config-ref="HTTP_Listener_Configuration"
path="/test" doc:name="HTTP" />
<set-payload
value="{
 "coord": {
 "lon": -0.13,
 "lat": 51.51
 },
 "main": {
 "temp": 290.24,
 "pressure": 1016,
 "humidity": 77,
 "temp_min": 288.15,
 "temp_max": 292.15
 },
 "id": 2643743,
 "name": "London",
 "cod": 200
 }"
doc:name="Set Payload" />
<set-property propertyName="id" value="ID01" doc:name="Add ID Header" />
</flow>
When I send a request to this flow I receive the HTTP header as expected:
curl -v http://localhost:8091/test
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8091 (#0)
> GET /test HTTP/1.1
> Host: localhost:8091
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200
< id: ID01 <=============
< Content-Length: 244
< Date: Tue, 10 Jul 2018 22:44:51 GMT
<
{
"coord": {
"lon": -0.13,
"lat": 51.51
},
"main": {
"temp": 290.24,
"pressure": 1016,
"humidity": 77,
"temp_min": 288.15,
"temp_max": 292.15
},
"id": 2643743,
"name": "London",
"cod": 200
}
Hope that helps!
Johnson.
Upvotes: 3