Facing below runtime error after upgrading from Mule Runtime 4.2.0 to 4.2.1.
Below detailed my codebase, and quick error message, and detailed error logs for review. Please suggest, if anyone faced the same problem?
I referred to other similar question and answer in StackOverflow Mule ESB : Cannot copy message with a stream payload, this doesn't solve mine below error.
Runitime Error on Mule 4.2.1:
Cannot copy message with a stream payload. Payload can be transformed by using an <object-to-byte-array-transformer> in order to be able to copy the message. Payload type is "org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider"
Detailed Error Log
INFO 2019-08-05 11:29:15,388 [[MuleRuntime].cpuLight.11: [jda-demand-adapter].Get_BY_Status_n_Update_Part_Flow.CPU_LITE #7ed56bee] [event: 20e0d4f1-b746-11e9-afb2-0a0027000005] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: BY status: <?xml version='1.0' encoding='UTF-8'?>
<DeliveryStatus>
<DeliveryID>46658</DeliveryID>
<Username>user_di_test</Username>
<StartDelivery>2019-08-05T05:24:34.886502+00:00</StartDelivery>
<LastProcessed>2019-08-05T05:46:16.508861+00:00</LastProcessed>
<Status>LOADED</Status>
<ParameterInfo>
<Category>Events</Category>
<Version>1.14.17</Version>
<File>Events.gz</File>
</ParameterInfo>
<Statistics>
<DeliveredRecords>323</DeliveredRecords>
<PendingRecords>323</PendingRecords>
<ProcessedRecords>0</ProcessedRecords>
<ErroneousRecords>0</ErroneousRecords>
</Statistics>
</DeliveryStatus>
INFO 2019-08-05 11:29:15,397 [[MuleRuntime].cpuIntensive.09: [jda-demand-adapter].Get_BY_Status_n_Update_Part_Flow.CPU_INTENSIVE #6b417a92] [event: 20e0d4f1-b746-11e9-afb2-0a0027000005] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: payload : {
"DeliveryStatus": {
"DeliveryID": "46658",
"Username": "user_di_test",
"StartDelivery": "2019-08-05T05:24:34.886502+00:00",
"LastProcessed": "2019-08-05T05:46:16.508861+00:00",
"Status": "LOADED",
"ParameterInfo": {
"Category": "Events",
"Version": "1.14.17",
"File": "Events.gz"
},
"Statistics": {
"DeliveredRecords": "323",
"PendingRecords": "323",
"ProcessedRecords": "0",
"ErroneousRecords": "0"
}
}
}
INFO 2019-08-05 11:29:15,410 [[MuleRuntime].cpuIntensive.09: [jda-demand-adapter].Get_BY_Status_n_Update_Part_Flow.CPU_INTENSIVE #6b417a92] [event: 20e0d4f1-b746-11e9-afb2-0a0027000005] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: Delivery Status summary: "46658","LOADED", {
"DeliveredRecords": "323",
"PendingRecords": "323",
"ProcessedRecords": "0",
"ErroneousRecords": "0"
}
INFO 2019-08-05 11:29:17,030 [[MuleRuntime].io.110: [jda-demand-adapter].Update_Part_Status_Recordcount_Flow.BLOCKING #502d3ddf] [event: 20e0d4f1-b746-11e9-afb2-0a0027000005] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: Final response for Job without Errors, jobDetails: null
INFO 2019-08-05 11:29:17,032 [[MuleRuntime].io.110: [jda-demand-adapter].Update_Part_Status_Recordcount_Flow.BLOCKING #502d3ddf] [event: 20e0d4f1-b746-11e9-afb2-0a0027000005] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: Inside Aggregation complete - For loop payload:[org.mule.runtime.api.metadata.TypedValue#fc4ba33d]
INFO 2019-08-05 11:29:17,052 [[MuleRuntime].io.110: [jda-demand-adapter].Update_Part_Status_Recordcount_Flow.BLOCKING #502d3ddf] [event: 20e0d4f1-b746-11e9-afb2-0a0027000005] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: After Reporting Transformation: {
"Summary": {
"DataPostingStatus": "",
"DataPostingDetailedStatus": "",
"JobCreatedDate": "",
"JobRestartDate": "",
"JobLastModifiedTime": "",
"JobExecutionDuration": "",
"JobExecutionDuration_in_Secs": "",
"RecordsProcessed": "",
"DeliveredRecords": "323",
"PendingRecords": "323",
"ProcessedRecords": "0",
"ErrorRecords": "0",
"Categories": [
"Events"
]
},
"CategorySummary": [
{
"Category": "Events",
"DeliveredRecords": "323",
"PendingRecords": "323",
"ProcessedRecords": "0",
"ErrorRecords": "0",
"DeliveryId": [
"46658"
]
}
],
"Errors": {
},
"Details": [
{
"DeliveryStatus": {
"DeliveryID": "46658",
"Username": "user_di_test",
"StartDelivery": "2019-08-05T05:24:34.886502+00:00",
"LastProcessed": "2019-08-05T05:46:16.508861+00:00",
"Status": "LOADED",
"ParameterInfo": {
"Category": "Events",
"Version": "1.14.17",
"File": "Events.gz"
},
"Statistics": {
"DeliveredRecords": "323",
"PendingRecords": "323",
"ProcessedRecords": "0",
"ErroneousRecords": "0"
}
}
}
]
}
ERROR 2019-08-05 11:29:17,076 [[MuleRuntime].cpuLight.11: [jda-demand-adapter].Ingestion_Status_Main_Flow.CPU_LITE #7132a277] [event: 20e0d4f1-b746-11e9-afb2-0a0027000005] org.mule.runtime.core.internal.exception.OnErrorContinueHandler:
********************************************************************************
Message : Cannot copy message with a stream payload. Payload can be transformed by using an <object-to-byte-array-transformer> in order to be able to copy the message. Payload type is "org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider".
Element : Get_Job_Status_Details_Flow/processors/1 # jda-demand-adapter:com/jda/cd/common/flow/ingestion-status.xml:257 (Scatter-Gather)
Element XML : <scatter-gather doc:name="Scatter-Gather">
<route>
<logger level="INFO" doc:name="Logger" message="Calculating the Job Satus ..."></logger>
<flow-ref name="GetDetailedJobStatus_SubFlow" doc:name="GetDetailedJobStatus_SubFlow"></flow-ref>
<set-payload value="#[{
"detailedStatus": vars.detailedStatus
}]" mimeType="application/java" doc:name="Set Payload" doc:id="5ea3c7bf-b1b1-4231-9af3-c8e39f241866"></set-payload>
</route>
<route>
<flow-ref name="Get_Job_Details_Flow_Enricher_0" doc:name="Get_Job_Details_Flow_Enricher_0"></flow-ref>
<set-payload value="#[{
"jobStatus": vars.jobStatus
}]" mimeType="application/java" doc:name="Set Payload" doc:id="e0a78803-a93c-4523-9551-4cf9218f059b"></set-payload>
<logger level="INFO" doc:name="Logger Job Details" doc:id="8b31e869-5630-4e01-902d-3e259ba2734e" message="Scatter-Gather Get_Job_Details_Flow_Enricher_0 payload:#[payload], jobStatus:#[vars.jobStatus]"></logger>
<choice doc:name="CalcJobStatus_IfNeeded-Choice">
<when expression="#[vars.jobStatus == 'IN_PROGRESS']">
<async doc:name="Async">
<flow-ref name="CalcBatchStatus_Flow" doc:name="CalcBatchStatus_Flow"></flow-ref>
</async>
</when>
<otherwise>
<logger message="job status is final" level="INFO" doc:name="Logger"></logger>
</otherwise>
</choice>
</route>
<route>
<flow-ref name="Get_Records_By_Status_SubFlow_Enricher_1" doc:name="Get_Records_By_Status_SubFlow_Enricher_1"></flow-ref>
<set-payload value="#[{
"recordsByStatus": vars.recordsByStatus
}]" mimeType="application/java" doc:name="Set Payload"></set-payload>
</route>
<route>
<logger message="#["jobExecution Duration : "]" level="INFO" doc:name="Logger"></logger>
<flow-ref name="Get_Job_Status_Details_Flow_Enricher_2" doc:name="Get_Job_Status_Details_Flow_Enricher_2"></flow-ref>
<logger message="payload last_mod_date #[vars] #[vars.lastModDate]" level="INFO" doc:name="Logger"></logger>
<flow-ref name="Get_Job_Status_Details_Flow_Enricher_6" target="jobCreatedDate" targetValue="#[payload[0].CREATED_DATE]" doc:name="Get_Job_Status_Details_Flow_Enricher_6"></flow-ref>
<set-variable value="#[now()]" doc:name="Current time" doc:id="547a11d2-b9dc-479e-a0c4-36e5b367bcee" variableName="currentTime"></set-variable>
<set-variable value="#[%dw 2.0 import * from dw::util::Timer output application/java --- ((toMilliseconds(vars.lastModDate) - toMilliseconds(vars.jobCreatedDate))/1000) as Number as String {format: ".##"}]" doc:name="Set Variable jobExecutionDurationSeconds" doc:id="499b7eda-f565-4a7c-94bd-9aeaf7306941" variableName="jobExecutionDurationSeconds"></set-variable>
<set-variable value="#[%dw 2.0 import * from dw::util::Timer output application/java --- ((toMilliseconds(vars.currentTime) - toMilliseconds(vars.lastModDate))/1000) as Number as String {format: ".##"}]" doc:name="TimeSinceLastMod" doc:id="0f30996f-1c89-4d45-90e9-915f3d2440bb" variableName="timeSinceLastMod"></set-variable>
<set-variable value="#[%dw 2.0 output application/json --- (((vars.jobExecutionDurationSeconds / 3600) as Number) as String {format: ".##"}) ++ ":" ++ ((((vars.jobExecutionDurationSeconds mod 3600) as Number) / 60 as Number) as String)as String {format: ".##"} ++ ":" ++((((vars.jobExecutionDurationSeconds mod 60) as Number))as String) as String {format: ".##"}]" doc:name="Set Variable jobExecutionDuration" doc:id="eaa22fce-6085-4290-8a31-46fc0bdd90c0" variableName="jobExecutionDuration"></set-variable>
<set-variable value="#[%dw 2.0 output application/json --- (((vars.timeSinceLastMod / 3600) as Number) as String) as String {format: ".##"} ++ ":" ++ ((((vars.timeSinceLastMod mod 3600) as Number) / 60 as Number) as String) as String {format: ".##"} ++ ":" ++((((vars.timeSinceLastMod mod 60) as Number))as String) as String {format: ".##"}]" doc:name="Set Variable TimeSinceLastModString" doc:id="15942ccf-d219-40f1-a783-3e4466bdfbbf" variableName="timeSinceLastModString"></set-variable>
<logger message="job_create date #[vars]" level="INFO" doc:name="Logger"></logger>
<set-payload value="#[%dw 2.0 output application/json --- {"jobExecutionDuration": vars.jobExecutionDuration, "jobExecutionDurationSeconds": vars.jobExecutionDurationSeconds, "jobCreatedDate":vars.jobCreatedDate,"lastModDate": vars.lastModDate,"currentTime": vars.currentTime,"timeSinceLastMod": vars.timeSinceLastMod}]" doc:name="Set Payload" doc:id="a97e5020-9d64-411e-87bf-ab325f29cd7f" mimeType="application/json"></set-payload>
</route>
</scatter-gather>
Error type : MULE:UNKNOWN
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.runtime.api.exception.MuleRuntimeException: Cannot copy message with a stream payload. Payload can be transformed by using an <object-to-byte-array-transformer> in order to be able to copy the message. Payload type is "org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider"
********************************************************************************
Below Codebase works fine in Mule 4.2.0, after upgrading Mule runtime to 4.2.1 and trying to use Anypoint 7.3.4, getting above runtime error. I am not getting the clue to fix it.
Below same code works on Mule 4.2.0:
<flow name="Ingestion_Status_Main_Flow" doc:description="Ingestion_Status_Main_Flow will read BY_delivery_IDs and try to read the status of the delivery from BY. If BY service is not available, then it provides the status of the status tables. In addition to the BY response details, it shows the job's current status, Number of records as per the status. ">
<http:listener path="${secure::ingestion.status.resource}/{jobId}" allowedMethods="GET" doc:name="/status" config-ref="HTTP_Listener_Config">
<http:response statusCode="#[migration::HttpListener::httpListenerResponseSuccessStatusCode(vars)]"/>
<http:error-response statusCode="#[vars.statusCode default migration::HttpListener::httpListenerResponseErrorStatusCode(vars)]"/>
</http:listener>
<logger message='#[attributes.uriParams.jobId]' level="INFO" doc:name="Job ID from input" />
<set-variable variableName="jobId" value="#[attributes.uriParams.jobId]" doc:name="jobId" />
<set-variable value="#[attributes.queryParams.notify]" doc:name="notifyFlag" doc:id="c2c8a869-4941-4f72-9cd3-3c9ea7441e65" variableName="notify"/>
<flow-ref name="Validate_Input_JobID_Sub_Flow" doc:name="Validate_Input_JobID_Sub_Flow" />
<set-variable variableName="correlationId" value="#[vars.jobId]" doc:name="Session Variable"/>
<flow-ref name="Fetch_Parts_for_Job_SubFlow" doc:name="Fetch_Parts_for_Job_SubFlow" />
<set-variable value="#[sizeOf(payload)]" doc:name="sizeOfPayload" doc:id="0ab10eae-0b50-4b37-bd89-0ac614f548db" variableName="sizeOfPayload" />
<logger message='Delivery ID for Job: #[payload.BY_DELIVERY_ID]' level="INFO" doc:name="Deliver IDs" />
<choice doc:name="Choice">
<when expression="#[sizeOf(payload) > 0]">
<foreach doc:name="For Each" doc:id="742d1496-9be5-409a-a42c-e0da8a1a696d" >
<logger level="INFO" doc:name="Logger For Each" doc:id="e9aeff5c-e00c-4fd4-ada3-09b22f4161cd" message="inside for each #[payload] "/>
<flow-ref doc:name="Get_BY_Status_n_Update_Part_Flow" doc:id="6e00a6b0-8d83-4df6-b22a-ce6666fed36a" name="Get_BY_Status_n_Update_Part_Flow"/>
<aggregators:group-based-aggregator doc:name="groupByDeliveryId" doc:id="b4b76fac-3f35-4812-9c1d-81b23ddd1eb9" name="groupByDeliveryId" groupSize="#[vars.sizeOfPayload]" >
<aggregators:incremental-aggregation >
<logger level="INFO" doc:name="Logger" doc:id="f3e2bdd1-d660-4074-92b0-4c04ea421706" message="Incremental size #[sizeOf(payload)]" />
</aggregators:incremental-aggregation>
<aggregators:aggregation-complete >
<logger message="Final response for Job without Errors, jobDetails: #[vars.detailedStatus]" level="INFO" doc:name="Response without Errors included" />
<logger level="INFO" doc:name="Logger" doc:id="eb7c7626-7091-481a-939c-926f938d84ae" message="Inside Aggregation complete - For loop payload:#[payload]" />
<ee:transform doc:name="Reporting Transformation" doc:id="421fb819-c58f-4f46-8d6d-e5dfa43df133">
<ee:message>
<ee:set-payload resource="ingestion\ingestion-status-resp.dwl" />
</ee:message>
</ee:transform>
<logger level="INFO" doc:name="Logger" doc:id="f6acf89c-5b84-4cbc-9cab-bf4b9e48da4f" message="After Reporting Transformation: #[payload]"/>
<set-variable variableName="aggregatedPayload" value="#[payload]" doc:name="Set Variable" doc:id="eded53f3-18ac-4a84-8fcf-916e89d7a185"/>
</aggregators:aggregation-complete>
</aggregators:group-based-aggregator>
</foreach>
</when>
<otherwise>
<logger message="No Delivery IDs found." level="INFO" doc:name="Logger" />
<set-payload value="#[{
"Summary": {
"DataPostingStatus": '',
"DataPostingDetailedStatus": '',
"JobCreatedDate": '',
"JobRestartDate": '',
"JobLastModifiedTime": '',
"JobExecutionDuration": '',
"JobExecutionDuration_in_Secs": '',
"RecordsProcessed": ''
}
}]" mimeType="application/json" doc:name="Set Payload" doc:id="066c7871-dd4b-4bde-8663-e0558a5847df"/>
</otherwise>
</choice>
<set-payload value="#[vars.aggregatedPayload]" doc:name="Set Payload" doc:id="337a0771-458c-4511-920c-ca38fcb8c6d9" />
<logger message='getting db details #[payload]' level="INFO" doc:name="Logger"/>
<flow-ref name="Ingestion_Status_Main_Flow_Enricher_22" doc:name="Ingestion_Status_Main_Flow_Enricher_22"/>
<set-payload value="#[vars.aggregatedPayload]" doc:name="Set Payload" doc:id="7ef033ba-17d6-4597-9b4c-96fb73212e63" />
<ee:transform doc:name="Transform Message" doc:id="794cfad2-e368-4b44-9c7e-746e0e692338" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
Summary: {
DataPostingStatus: vars.jobStatus,
DataPostingDetailedStatus: vars.detailedStatus,
JobCreatedDate: vars.jobCreatedDate,
JobRestartDate: "",
JobLastModifiedTime: vars.lastModDate,
JobExecutionDuration: vars.jobExecutionDuration,
JobExecutionDuration_in_Secs: vars.jobExecutionDurationSeconds,
RecordsProcessed: "",
DeliveredRecords: payload.Summary.DeliveredRecords,
PendingRecords: payload.Summary.PendingRecords,
ProcessedRecords: payload.Summary.ProcessedRecords,
ErrorRecords: payload.Summary.ErrorRecords,
Categories: payload.Summary.Categories,
},
Errors:{},
CategorySummary: payload.CategorySummary,
Details: payload.Details
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<logger message='Getting errors details...' level="INFO" doc:name="Logger"/>
<flow-ref name="Add_Errors_to_Payload_Sub_Flow_Enricher_0" doc:name="Add_Errors_to_Payload_Sub_Flow_Enricher_0"/>
<ee:transform doc:name="Transform Message" doc:id="5b0518ac-139a-42f8-ae12-a42cce2449c1" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload
]]></ee:set-payload>
</ee:message>
</ee:transform>
<async doc:name="Async">
<choice doc:name="Choice">
<when expression="#[vars.notify == 'true']">
<flow-ref name="Send_Status_Mail_Flow" doc:name="Send_Status_Mail_Flow" />
</when>
<otherwise>
<logger message="Notification flag is not provided as query parameter." level="INFO" doc:name="Logger" />
</otherwise>
</choice>
</async>
<logger message='Final response: #[payload] jobId: #[vars.jobId]' level="DEBUG" doc:name="Response with Errors" />
<logger message="Ingestion status request done" level="INFO" doc:name="Status request completed" />
<error-handler ref="Global_Errorflow_Choice_Exception_Strategy" doc:name="Global Exception Strategy" />
</flow>
<sub-flow name="Ingestion_Status_Main_Flow_Enricher_22">
<flow-ref name="Get_Job_Status_Details_Flow" doc:description="Job status retrieved from status tables."/>
</sub-flow>
</flow>
<sub-flow name="Get_Job_Status_Details_Flow" doc:description="Job status retrieved from status tables.
For now, different stages of the job processing has been reported.
1. Batches not yet created.
2. Batches created, and parts are getting creating.
3. Parts are created, and processing.
4. Some part uploads are failed.
5. Some parts processing is failed i.e. payload is not created. ">
<scatter-gather doc:name="Scatter-Gather">
<route>
<logger level="INFO" doc:name="Logger" message="Calculating the Job Satus ..." />
<flow-ref name="GetDetailedJobStatus_SubFlow" doc:name="GetDetailedJobStatus_SubFlow" />
<set-payload value="#[{
"detailedStatus": vars.detailedStatus
}]" mimeType="application/java" doc:name="Set Payload" doc:id="5ea3c7bf-b1b1-4231-9af3-c8e39f241866"/>
</route>
<route>
<flow-ref name="Get_Job_Details_Flow_Enricher_0" doc:name="Get_Job_Details_Flow_Enricher_0"/>
<set-payload value="#[{
"jobStatus": vars.jobStatus
}]" mimeType="application/java" doc:name="Set Payload" doc:id="e0a78803-a93c-4523-9551-4cf9218f059b"/>
<logger level="INFO" doc:name="Logger Job Details" doc:id="8b31e869-5630-4e01-902d-3e259ba2734e" message="Scatter-Gather Get_Job_Details_Flow_Enricher_0 payload:#[payload], jobStatus:#[vars.jobStatus]"/>
<choice doc:name="CalcJobStatus_IfNeeded-Choice">
<when expression="#[vars.jobStatus == 'IN_PROGRESS']">
<async doc:name="Async">
<flow-ref name="CalcBatchStatus_Flow" doc:name="CalcBatchStatus_Flow" />
</async>
</when>
<otherwise>
<logger message="job status is final" level="INFO" doc:name="Logger" />
</otherwise>
</choice>
</route>
<route>
<flow-ref name="Get_Records_By_Status_SubFlow_Enricher_1" doc:name="Get_Records_By_Status_SubFlow_Enricher_1"/>
<set-payload value="#[{
"recordsByStatus": vars.recordsByStatus
}]" mimeType="application/java" doc:name="Set Payload" />
</route>
<route>
<logger message='#["jobExecution Duration : "]' level="INFO" doc:name="Logger" />
<flow-ref name="Get_Job_Status_Details_Flow_Enricher_2" doc:name="Get_Job_Status_Details_Flow_Enricher_2"/>
<logger message='payload last_mod_date #[vars] #[vars.lastModDate]' level="INFO" doc:name="Logger" />
<flow-ref name="Get_Job_Status_Details_Flow_Enricher_6" target="jobCreatedDate" targetValue="#[payload[0].CREATED_DATE]" doc:name="Get_Job_Status_Details_Flow_Enricher_6"/>
<set-variable value="#[now()]" doc:name="Current time" doc:id="547a11d2-b9dc-479e-a0c4-36e5b367bcee" variableName="currentTime"/>
<set-variable value='#[%dw 2.0
import * from dw::util::Timer
output application/java
---
((toMilliseconds(vars.lastModDate) - toMilliseconds(vars.jobCreatedDate))/1000) as Number as String {format: ".##"}]' doc:name="Set Variable jobExecutionDurationSeconds" doc:id="499b7eda-f565-4a7c-94bd-9aeaf7306941" variableName="jobExecutionDurationSeconds"/>
<set-variable value='#[%dw 2.0
import * from dw::util::Timer
output application/java
---
((toMilliseconds(vars.currentTime) - toMilliseconds(vars.lastModDate))/1000) as Number as String {format: ".##"}]' doc:name="TimeSinceLastMod" doc:id="0f30996f-1c89-4d45-90e9-915f3d2440bb" variableName="timeSinceLastMod"/>
<set-variable value='#[%dw 2.0
output application/json
---
(((vars.jobExecutionDurationSeconds / 3600) as Number) as String {format: ".##"}) ++ ":" ++ ((((vars.jobExecutionDurationSeconds mod 3600) as Number) / 60 as Number) as String)as String {format: ".##"} ++ ":" ++((((vars.jobExecutionDurationSeconds mod 60) as Number))as String) as String {format: ".##"}]' doc:name="Set Variable jobExecutionDuration" doc:id="eaa22fce-6085-4290-8a31-46fc0bdd90c0" variableName="jobExecutionDuration"/>
<set-variable value='#[%dw 2.0
output application/json
---
(((vars.timeSinceLastMod / 3600) as Number) as String) as String {format: ".##"} ++ ":" ++ ((((vars.timeSinceLastMod mod 3600) as Number) / 60 as Number) as String) as String {format: ".##"} ++ ":" ++((((vars.timeSinceLastMod mod 60) as Number))as String) as String {format: ".##"}]' doc:name="Set Variable TimeSinceLastModString" doc:id="15942ccf-d219-40f1-a783-3e4466bdfbbf" variableName="timeSinceLastModString"/>
<logger message='job_create date #[vars]' level="INFO" doc:name="Logger" />
<set-payload value='#[%dw 2.0 output application/json --- {"jobExecutionDuration": vars.jobExecutionDuration, "jobExecutionDurationSeconds": vars.jobExecutionDurationSeconds, "jobCreatedDate":vars.jobCreatedDate,"lastModDate": vars.lastModDate,"currentTime": vars.currentTime,"timeSinceLastMod": vars.timeSinceLastMod}]' doc:name="Set Payload" doc:id="a97e5020-9d64-411e-87bf-ab325f29cd7f" mimeType="application/json"/>
</route>
</scatter-gather>
<logger message="Flowvars used to invoke the restart-flows: payload: #[payload]" level="INFO" doc:name="RestartFlags - Logger" />
</sub-flow>
I am building an api to which i am sending a json request as below :
{
"type":"string",
"code": 101
}
I am using a choice router and i am routing the message based in the code .
i.e if code is not 101 and 100 then when condition will be executed
When Expression is - #[json:code != 101 && json:code != 100]
but even if code is 103 the above experession is returning true.
I'm assuming your comment "code is in double quotes" means the payload is like this:
{
"type": "string",
"code": "100"
}
If so, I'd recommend you convert it to Java and work from there. If the code is a string you need to acount for that as 100 != '100':
<json:json-to-object-transformer returnClass="java.util.Map" doc:name="JSON to Object"/>
<choice doc:name="Choice - Code?">
<when expression="#[payload.code != '101' && payload.code != '100']">
<logger level="INFO" doc:name="Logger - Do this"/>
</when>
<otherwise>
<logger level="INFO" doc:name="Logger - Do that"/>
</otherwise>
</choice>
Use Json to Object transformer before using JSON payload
Use (and , or) instead of (&&,||) for Logical operators in mule: DataWeaveLogicalOperators
xml config code,
<json:json-to-object-transformer returnClass="java.util.Map" doc:name="json to obj"/>
<choice doc:name="Choice">
<when expression="#[payload.code != 101 and payload.code != 100]">
<logger level="INFO" doc:name="logger"/>
</when>
<otherwise>
<logger level="INFO" doc:name="default"/>
</otherwise>
</choice>
Friends,
I have two inputs, A and B, both JSON.
I need to generate with DataMapper, a single output (custom) also in JSON format.
Example:
My Input A:
{
"name": "John Doe",
"age": "40"
}
My Input B:
{
"country": "Brazil"
"city": "Rio de Janeiro"
}
My Custom Output:
{
"customerName": "John Doe",
"customerAge": "40",
"customerCountry": "Brazil",
"customerCity": "Rio de Janeiro"
}
It can generate this output using the Mule DataMapper? How to?
At the time, I know use only one Input with DataMapper.
You need to take one of the input as the payload and the other as the variable.
My Payload was
{
"name": "John Doe",
"age": "40"
}
My Variable was
{
"country": "Brazil"
"city": "Rio de Janeiro"
}
Please find the below sample that I tested and works.
<flow name="combineFlow">
<http:listener config-ref="HTTP_Listener_Configuration"
path="/testings" doc:name="HTTP" />
<logger message="Coming here " level="INFO" doc:name="Logger" />
<set-variable variableName="mypayload"
value="{"country": "Brazil","city": "Rio de Janeiro"}"
doc:name="Variable" mimeType="application/json" />
<logger level="INFO" doc:name="Logger" />
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
"customerName": payload.name,
"customerAge": payload.age,
"customerCountry": flowVars.mypayload.country,
"customerCity": flowVars.mypayload.city
}]]></dw:set-payload>
</dw:transform-message>
</flow>
Hope this helps
Slightly similar with previous answer: you need to take one input as payload and another one as variable.
Following is the implementation using DataMapper (not DataWeave/Transform Message)
XML:
<flow name="genericFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/dm" doc:name="HTTP" allowedMethods="POST"/>
<set-variable variableName="inputB"
value="#['{"country": "Brazil", "city": "Rio de Janeiro"}']" mimeType="application/json"
doc:name="Input B" />
<data-mapper:transform config-ref="JSON_To_JSON" doc:name="JSON To JSON">
<data-mapper:input-arguments>
<data-mapper:input-argument key="inputBjson">#[new org.json.JSONObject(flowVars.inputB)]</data-mapper:input-argument>
</data-mapper:input-arguments>
</data-mapper:transform>
<echo-component doc:name="Echo" />
</flow>
GRF:
...
<Dictionary>
<Entry id="DictionaryEntry0" input="true" name="inputPayload" output="false" type="object"/>
<Entry id="DictionaryEntry1" input="false" name="outputPayload" output="true" type="object"/>
<Entry dictval.__javaType="org.json.JSONObject" id="DictionaryEntry2" input="true" name="inputBjson" output="false" type="object"/>
</Dictionary>
...
<attr name="melScript"><![CDATA[//MEL
//START -> DO NOT REMOVE
output.__id = input.__id;
//END -> DO NOT REMOVE
output.customerName = input.name;
output.customerAge = input.age;
output.customerCountry = inputArguments.inputBjson.getString("country");
output.customerCity = inputArguments.inputBjson.getString("city");]]></attr>
Notes: input B is registered to DataMapper as Input Argument with Type = Object (MEL only), and its class is: org.json.JSONObject
One input give it as payload and other one use message properties and store the second input values as variable.Now inside data mapper use the variable in input argument field and map it.Simple!! hope it helps.
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP" contentType="application/x-www-form-urlencoded" path="getDetails" />
<object-to-string-transformer doc:name="Object to String"/>
<logger message=" Logging ...... #[message:payload]" level="INFO" doc:name="Logger"/>
i invoke thru chrome rest client
http://localhost:8081/getDetails
METHOD : post
below is json data
{
"id": "1",
"firstName": "xyz",
"lastName": "abc",
"address":"xy"
}
whatever json data i passed , i just want to print for processing . but
In logging it shows null payload
any suggesstion are welcome
I tested your scenario with the following :-
<flow name="Flow1" doc:name="Flow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP" contentType="application/x-www-form-urlencoded" path="getDetails" />
<object-to-string-transformer doc:name="Object to String"/>
<logger message=" Logging ...... #[message:payload]" level="INFO" doc:name="Logger"/>
</flow>
And I got it in the log as bellow :-
You have probably posted in the same question in another thread too.
Please read comments in mule post json data to mule endpoint url
After http:inBound you need to convert it to json using object to string transformer
My mule flow:
<flow name="classmappingFlow1" doc:name="classmappingFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="${hostname}" port="${port}" path="insertClass" connector-ref="ConnectorWithoutMuleSession" doc:name="HTTP"/>
<jersey:resources doc:name="REST">
<component class="com.mycompany.mulesoft.rest.AccountMappingService"/>
</jersey:resources>
<json:json-to-object-transformer doc:name="JSON to Object"/>
<logger message="Payload======#[payload]" level="INFO" doc:name="Logger"/>
<logger message="=====Company===#[payload.Company]" level="INFO" doc:name="Logger"/>
<db:insert config-ref="Oracle_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[insert into SIAS_CONFIGURATION values(1, 1,1234,#[payload.Company],'Y','N','Y','you',sysdate,'you',sysdate)]]></db:parameterized-query>
</db:insert>
</flow>
Console:
Payload======[{"Company":"KLM","Class":"Y","Location":"N","Department":"Y","EmplId":"1234"}]
=====Company===null
JSON Data:
[
{
"Company":"KLM",
"Class":"Y",
"Location":"N",
"Department":"Y",
"EmplId":"1234"
}
]
Rest Component:
#POST
#Path("/setClass")
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public String classSettings(#Payload String content){
return content;
}
Issue: I am getting null values and no data(empty) inserted to db
Use returnClass="java.util.List" in json:json-to-object-transformer after jersey:resources like the following :-
<json:json-to-object-transformer returnClass="java.util.List" doc:name="JSON to Object"/>