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
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.
Related
Software: Openproject,Gogs(internal Github clone)
Description: I send push notification from Gogs to openproject/webhooks/github, and getting 403 empty body.
Redacted information: apikey=42, "user.user", "user.user.com"
Send Headers:
Request URL: http://192.168.100.100/openproject/webhooks/github?apikey=42 Request method: POST Content-Type: application/json X-Github-Delivery: 92b7ff07-79b4-4334-b0b5-59122bedc9e7 X-Github-Event: pull_request X-Gogs-Delivery: 92b7ff07-79b4-4334-b0b5-59122bedc9e7 X-Gogs-Event: pull_request X-Gogs-Signature:
Send Body:
{ "action": "opened", "number": 4, "pull_request": { "id": 8, "number": 4, "user": { "id": 1, "username": "user.user", "login": "user.user", "full_name": "", "email": "user#user.com", "avatar_url": "http://192.168.100.100:3000/avatars/1" }, "title": "OP#48", "body": "[#48] [MFK5] [FuSa] [X120] SAF-4.2 :: SDD update\r\n\r\nhttp://192.168.100.100/openproject/work_packages/48\r\n", "labels": [], "milestone": null, "assignee": null, "state": "open", "comments": 0, "head_branch": "task/48-mfk5-fusa-x120-saf-42-sdd-update", "head_repo": { "id": 5, "owner": { "id": 13, "username": "DevTeam", "login": "DevTeam", "full_name": "", "email": "", "avatar_url": "http://192.168.100.100:3000/avatars/13" }, "name": "testpublic", "full_name": "DevTeam/testpublic", "description": "", "private": false, "fork": false, "parent": null, "empty": false, "mirror": false, "size": 49152, "html_url": "http://192.168.100.100:3000/DevTeam/testpublic", "ssh_url": "git#localhost:DevTeam/testpublic.git", "clone_url": "http://192.168.100.100:3000/DevTeam/testpublic.git", "website": "", "stars_count": 0, "forks_count": 0, "watchers_count": 4, "open_issues_count": 0, "default_branch": "master", "created_at": "2022-12-21T16:42:20+01:00", "updated_at": "2023-01-25T12:00:47+01:00" }, "base_branch": "master", "base_repo": { "id": 5, "owner": { "id": 13, "username": "DevTeam", "login": "DevTeam", "full_name": "", "email": "", "avatar_url": "http://192.168.100.100:3000/avatars/13" }, "name": "testpublic", "full_name": "DevTeam/testpublic", "description": "", "private": false, "fork": false, "parent": null, "empty": false, "mirror": false, "size": 49152, "html_url": "http://192.168.100.100:3000/DevTeam/testpublic", "ssh_url": "git#localhost:DevTeam/testpublic.git", "clone_url": "http://192.168.100.100:3000/DevTeam/testpublic.git", "website": "", "stars_count": 0, "forks_count": 0, "watchers_count": 4, "open_issues_count": 0, "default_branch": "master", "created_at": "2022-12-21T16:42:20+01:00", "updated_at": "2023-01-25T12:00:47+01:00" }, "html_url": "http://192.168.100.100:3000/DevTeam/testpublic/pulls/4", "mergeable": true, "merged": false, "merged_at": null, "merge_commit_sha": null, "merged_by": null }, "repository": { "id": 5, "owner": { "id": 13, "username": "DevTeam", "login": "DevTeam", "full_name": "", "email": "", "avatar_url": "http://192.168.100.100:3000/avatars/13" }, "name": "testpublic", "full_name": "DevTeam/testpublic", "description": "", "private": false, "fork": false, "parent": null, "empty": false, "mirror": false, "size": 49152, "html_url": "http://192.168.100.100:3000/DevTeam/testpublic", "ssh_url": "git#localhost:DevTeam/testpublic.git", "clone_url": "http://192.168.100.100:3000/DevTeam/testpublic.git", "website": "", "stars_count": 0, "forks_count": 0, "watchers_count": 4, "open_issues_count": 0, "default_branch": "master", "created_at": "2022-12-21T16:42:20+01:00", "updated_at": "2023-01-25T12:00:47+01:00" }, "sender": { "id": 1, "username": "user.user", "login": "user.user", "full_name": "", "email": "user#user.com", "avatar_url": "http://192.168.100.100:3000/avatars/1" } }
Response Headers: "403"
Cache-Control: max-age=0, private, must-revalidate Content-Security-Policy: default-src 'self'; base-uri 'self'; connect-src 'self' https://augur.openproject.com; font-src 'self' data:; form-action 'self'; frame-ancestors 'self'; frame-src 'self' https://player.vimeo.com https://releases.openproject.com/v1/check.svg; img-src * data: blob:; media-src 'self'; object-src https://releases.openproject.com/v1/check.svg; script-src 'self'; style-src 'self' 'unsafe-inline' Content-Type: text/html Date: Wed, 25 Jan 2023 11:02:22 GMT Referrer-Policy: origin-when-cross-origin Server: Apache/2.4.52 (Ubuntu) Set-Cookie: _open_project_session=c989eaa3af4d5d6b19c75b52899fa9ae; path=/openproject; HttpOnly; SameSite=Lax Vary: Accept-Encoding X-Content-Type-Options: nosniff X-Download-Options: noopen X-Frame-Options: SAMEORIGIN X-Permitted-Cross-Domain-Policies: none X-Request-Id: f1905295-06d6-4770-b046-2fd51147fadf X-Runtime: 0.008078 X-Xss-Protection: 1; mode=block
Response Body:
Api Key is valid, tested on API section using Postman. I can understand that some settings in Gogs can be an issue, like:
X-Gogs-Delivery: X-Gogs-Event: X-Gogs-Signature:
But i have no return information to proceed.
I am trying to get button's link from message of gmail (ex. verify account button). Is there any way to make it via Google API?
I used Api to get all messages first: https://www.googleapis.com/gmail/v1/users/me/messages
Then used this api to get the message details: https://www.googleapis.com/gmail/v1/users/me/messages/{message_id}
but can't find the link inside the email body, here is the response!!
{
"id": "1785a64978e454be",
"threadId": "1785a528dc1e905c",
"labelIds": [
"IMPORTANT",
"CATEGORY_PERSONAL",
"INBOX"
],
"snippet": "Invesna Logo Hello Turki Thank you for joining our community Best wishes INVESNA Team Verify Now This is an automated email. If you've received this email by mistake, please",
"payload": {
"partId": "",
"mimeType": "multipart/alternative",
"filename": "",
"headers": [
{
"name": "Delivered-To",
"value": "areeb.*****#gmail.com"
},
{
"name": "Received",
"value": "by 2002:a6b:916:0:0:0:0:0 with SMTP id t22csp3887526ioi; Mon, 22 Mar 2021 07:44:05 -0700 (PDT)"
},
{
"name": "X-Google-Smtp-Source",
"value": "ABdhPJyvgEKiYNby+5oLp9d6ZLU4ujfWHmppkGFvw2POAHup5hfkbaexaDRj9bwjk1zLmhyuIfsq"
},
{
"name": "X-Received",
"value": "by 2002:ac8:4752:: with SMTP id k18mr234477qtp.158.1616424245098; Mon, 22 Mar 2021 07:44:05 -0700 (PDT)"
},
{
"name": "ARC-Seal",
"value": "i=1; a=rsa-sha256; t=1616424245; cv=none; d=google.com; s=arc-20160816; b=cTBJJWs+fBO2mU4nAKoz+VzfvNI7RrAW3PKApijZ0LI4v6Ma1XAQxKilc+IEiwcmFE D6cTkU9CVAS9f+IOaE3bb8NCnQVz7mFvFkD72vvDeWaMsW2V2jbKZoFPdFKDGZ6b70fq WUXxy5uCHkafF9gAtmPFU2eTfMRRk5uv3ZA8XGcO87JWSYngzz/DoOdD6cQOVfIiv4HF YGAITJGHTYL2kgwdRVlSJCKQBpQZIJqM3pUHaYJ3+uXs2rg1XkaLyFudF3brG7tKUOMN gCXsyINhAfuTw2bIrWmSX+8B3AHG+h+aQfTbl9GNr3oBLYYM7BRMSfG2S8jldm6XnEpM ZUEg=="
},
{
"name": "ARC-Message-Signature",
"value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=feedback-id:mime-version:to:from:subject:date:message-id :dkim-signature:dkim-signature; bh=RToLBuWpZqa2f+3AtVt2tvS0pNeSTnAA4DQnGQ8mMWU=; b=prTkhBY/VOg77E8LDGE3HZD7rGb2vQuG2uln53Jh3ee4fXIKZtB6RwVUjBrodFyb6S FXUbY0Iox/TWv+Maqr0p89waYhGYy/aQD4g6G3/8BwLSCqAOc65JsKMGwGor/t2ZdsOZ w97c2w3eswYEfu9FuhXyCLV9Jbg/4bw32JWb59mKuAQSKx6aeiipXShmPmAmI5FWxlmu y/dbft5H4weUd3jXQjbAqXnfzyEso+nbl2iexfobZ4vqRPzarwk9tSZEC73mgqbsA5ZF zx9xPOYxJbMVin5Wrsit0p8xVv3DD1UlPGqNCItAviqUkHqtUDkznPmiWpFXtXLxoyk2 3SyA=="
},
{
"name": "ARC-Authentication-Results",
"value": "i=1; mx.google.com; dkim=pass header.i=#areebgroup.com header.s=ly5fxy3f4dncdbipp3gron65eulkyt3p header.b=XztlZ3Jb; dkim=pass header.i=#amazonses.com header.s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug header.b=FtocR6ro; spf=pass (google.com: domain of 010001785a649518-d06bf9df-a011-4cee-81ed-9328a70eaa39-000000#amazonses.com designates 54.240.48.108 as permitted sender) smtp.mailfrom=010001785a649518-d06bf9df-a011-4cee-81ed-9328a70eaa39-000000#amazonses.com"
},
{
"name": "Return-Path",
"value": "<010001785a649518-d06bf9df-a011-4cee-81ed-9328a70eaa39-000000#amazonses.com>"
},
{
"name": "Received",
"value": "from a48-108.smtp-out.amazonses.com (a48-108.smtp-out.amazonses.com. [54.240.48.108]) by mx.google.com with ESMTPS id cj6si7995790qvb.74.2021.03.22.07.44.04 for <areeb.testing2#gmail.com> (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Mon, 22 Mar 2021 07:44:05 -0700 (PDT)"
},
{
"name": "Received-SPF",
"value": "pass (google.com: domain of 010001785a649518-d06bf9df-a011-4cee-81ed-9328a70eaa39-000000#amazonses.com designates 54.240.48.108 as permitted sender) client-ip=54.240.48.108;"
},
{
"name": "Authentication-Results",
"value": "mx.google.com; dkim=pass header.i=#areebgroup.com header.s=ly5fxy3f4dncdbipp3gron65eulkyt3p header.b=XztlZ3Jb; 18-d06bf9df-a011-4cee-81ed-9328a70eaa39-000000#amazonses.com"
},
{
"name": "DKIM-Signature",
"value": "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=ly5fxy3f4dncdbipp3gron65eulkyt3p; d=areebgroup.com; t=1616424244; h=Message-ID:Date:Subjec"
},
{
"name": "DKIM-Signature",
"value": "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug; d=amazonses.com; t=1616424244; h=Message-ID:Date:Subject:Fro"
},
{
"name": "Message-ID",
"value": "<010001785>
},
{
"name": "Date",
"value": "Mon, 22 Mar 2021 14:44:04 +0000"
},
{
"name": "Subject",
"value": "Verify Your Account"
},
{
"name": "From",
"value": "Invesna <account#aree>"
},
{
"name": "To",
"value": "areeb.**#gmail.com"
},
{
"name": "MIME-Version",
"value": "1.0"
},
{
"name": "Content-Type",
"value": "multipart/alternative; boundary=\"_=_swift_1616424243_8452744c94a6060ff23d75c5b712dcb6_=_\""
},
{
"name": "X-SES-Outgoing",
"value": "2021.03.22-54.240.48.108"
},
{
"name": "Feedback-ID",
"value": "1.us-ea"
}
],
"body": {
"size": 0
},
"parts": [
{
"partId": "0",
"mimeType": "text/plain",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/plain; charset=utf-8"
},
{
"name": "Content-Transfer-Encoding",
"value": "quoted-printable"
}
],
"body": {
"size": 5094,
"data": "PCFET0NUWVBFIGh0bWw-DQo8aHRtbCBsYW5nPSJlbiI-DQo8Ym9keT4NCjxkaXYgc3R5bGU9ImJhY2tncm91bmQtY29sb3I6ICNmN2Y5ZmM7IHBhZGRpbmctYm90dG9tOiAzcmVtIj4NCiAgICA8aW1nIHNyYz0iaHR0cDovL2FwaS10ZXN0LmludmVzbmEud9JbnZlc25hX2FwcCIgdGFyZ2V0PSJfYmxhbmsiPg0KICAgICAgICAgICAgICAgICAgICAgICAgPGltZw0KICAgICAgICAgICAgPg0KPC9ib2R5Pg0KPC9odG1sPg0K"
}
},
{
"partId": "1",
"mimeType": "text/html",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/html; charset=utf-8"
},
{
"name": "Content-Transfer-Encoding",
"value": "quoted-printable"
}
],
"body": {
"size": 10026,
"data": "PCFkb2N0eXBlIGh0bWw-DQo8aHRtbCBsYW5nPSJlbiI-PGJvZHkgc3R5bGU9ImZvbnQtZmFtaWx5OiAtYXBwbGUtc3lzdGVtLCBCbGlua01hY1N5c3RlbUZvbnQsICdTZWdvZSBVSScsIFJvYm90bywgSGVsdmV0aWNhLCBBcmlhbCwgc2Fucy1zZXJpZiwgJ0FwcGxlIENvbG9yIEVtb2ppgYWx0PSJQYXR0ZXJuIiBzdHlsZT0iZm9udC1mYW1pbHk6IC1hcHBsZS1zeXN0ZW0sICAgICAgPC91bD4NCjwvZGl2Pg0KICAgIDwvZGl2Pg0KPC9kaXY-DQo8L2JvZHk-PC9odG1sPg0K"
}
}
]
},
"sizeEstimate": 20887,
"historyId": "79",
"internalDate": "16164240"
}
Resolved, my email body was encoded by base64 encoder, i decode it first then i found the link i need
Reference:
Resource: MessagePartBody
incoming payload:
{
"Categories": [
{
"ID": "5a873ca3",
"Code": "CTY"
}, {
"ID": "89k873c8",
"Code": "CTY"
}
]
}
flowVar value is an ArrayList: ([84hkj569],[6j93hl9])
desired output payload:
{
"Categories": [
{
"ID": "5a873ca3",
"Code": "CTY"
}, {
"ID": "89k873c8",
"Code": "CTY"
}, {
"ID": "84hkj569",
"Code": "CTY"
}, {
"ID": "6j93hl9",
"Code": "CTY"
}
]
}
I couldn't find a way to do in dataweave,
Would you please help
The following dataweave code should give you what you want:
%dw 1.0
%output application/json
---
{
Categories: payload.Categories ++ (flowVars.value map {
"ID": $,
"Code": "CTY"
})
}
Here's the configuration from a sample flow which I have used, and the output:
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
"Categories": [
{
"ID": "5a873ca3",
"Code": "CTY"
}, {
"ID": "89k873c8",
"Code": "CTY"
}
]
}]]></dw:set-payload>
</dw:transform-message>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[
flowVars.value = new java.util.ArrayList();
flowVars.value.add("84hkj569");
flowVars.value.add("6j93hl9");
return payload;
]]></scripting:script>
</scripting:component>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
Categories: payload.Categories ++ (flowVars.value map {
"ID": $,
"Code": "CTY"
})
}]]></dw:set-payload>
</dw:transform-message>
Output:
{
"Categories": [
{
"ID": "5a873ca3",
"Code": "CTY"
},
{
"ID": "89k873c8",
"Code": "CTY"
},
{
"ID": "84hkj569",
"Code": "CTY"
},
{
"ID": "6j93hl9",
"Code": "CTY"
}
]
}
Brad Cooper's dataweave code to concatenate JSON payload and flowVars.value works without any issues. Here is the complete example that works with 3.8.1.
Complete Code:
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" 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/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="sample-dataweaveFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/sample" doc:name="HTTP"/>
<logger message="Request Received" level="INFO" doc:name="Logger"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-variable variableName="value"><![CDATA[%dw 1.0
%output application/java
---
['84hkj569', '6j93hl9']]]></dw:set-variable>
</dw:transform-message>
<logger message="Flow Variable: #[flowVars.value]" level="INFO" doc:name="Logger"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
Categories: [
{
"ID": "5a873ca3",
"Code": "CTY"
}, {
"ID": "89k873c8",
"Code": "CTY"
}
]
}]]></dw:set-payload>
</dw:transform-message>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<logger message="Payload: #[payload]" level="INFO" doc:name="Logger"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
Categories: payload.Categories ++ (flowVars.value map {
ID: $,
Code: 'CTY'
})
}]]></dw:set-payload>
</dw:transform-message>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<logger message="Final Response: #[payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
TEST URL:
http://localhost:8081/sample
Console Output:
INFO 2018-05-09 01:08:51,575 [[sample-dataweave].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: Request Received
INFO 2018-05-09 01:08:51,576 [[sample-dataweave].HTTP_Listener_Configuration.worker.01] com.mulesoft.weave.mule.utils.MuleWeaveFactory$: MimeType was not resolved '*/*' delegating to Java.
INFO 2018-05-09 01:08:51,595 [[sample-dataweave].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: Flow Variable: [84hkj569, 6j93hl9]
INFO 2018-05-09 01:08:51,596 [[sample-dataweave].HTTP_Listener_Configuration.worker.01] com.mulesoft.weave.mule.utils.MuleWeaveFactory$: MimeType was not resolved '*/*' delegating to Java.
INFO 2018-05-09 01:08:51,620 [[sample-dataweave].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: Payload: {
"Categories": [
{
"ID": "5a873ca3",
"Code": "CTY"
},
{
"ID": "89k873c8",
"Code": "CTY"
}
]
}
INFO 2018-05-09 01:08:51,635 [[sample-dataweave].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: Final Response: {
"Categories": [
{
"ID": "5a873ca3",
"Code": "CTY"
},
{
"ID": "89k873c8",
"Code": "CTY"
},
{
"ID": "84hkj569",
"Code": "CTY"
},
{
"ID": "6j93hl9",
"Code": "CTY"
}
]
}
I have an json output which looks like,
"details": [
{
"id": "",
"name": "",
"status": "",
},
{
"id": "",
"name": "",
"status": "",
},
{
"id": "",
"name": "",
"status": "",
},
{
"id": "",
"name": "",
"status": "",
}
From this output I can iterate values like //jsonObject/details and fetching individual item like
json-eval('$.details.id'), but I want to store all Id's and Name's into a Array in wso2 ESB, from the output I get, Can anyone help me.
Not sure if that helps, I think the following pseydo code might do it but I haven't tried it.
//create an empty var
<property name="newArray" value=""/>
//iterate over the json
<iterate xmlns:ns="http://org.apache.synapse/xsd" continueParent="true" expression="//jsonObjects/object" id="MyIterator">
....
<property name="newArray" expression="fn:concat(get-property('newArray'),//jsonObjects/object/value)" scope="operation"/>
....
</iterate>
<log>
<property name="afterIterate" expression="get-property('operation','newArray')"/>
</log>
I had json input like below
"products": {
"p0": {
"productId": "110",
"productName": "bag"
},
"p1": {
"productId": "160",
"productName": "shoe"
},
"p2": {
"productId": "140",
productName": "watch"
}
}
From mule I want the output like the one below
[
{
"productId": "110",
"productName": "bag"
},
{
"productId": "160",
"productName": "shoe"
},
{
"productId": "140",
"productName": "watch"
}
]
Because I need to pass the above output format to other inbound.
Anyone help how to convert my input json into above output json.
Thanks in advance for all
You can achieve what you want using some MEL and json transformers:
<json:json-to-object-transformer
returnClass="java.util.HashMap" />
<set-payload value="#[($.value in payload.products.entrySet())]" />
<json:object-to-json-transformer />
If you're going to have more complex transformation, I would write a custom transformer, or script transformer using Groovys JsonBuilder and JsonSlurper or potentially Datamapper.
If you are using Mule 3.7 and above, you can do it simply and easily with the dataweave component :-
<flow name="Testlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
payload.products map (
$
)
]]></dw:set-payload>
</dw:transform-message>
</flow>