Media Type Metadata Selector (.^mediaType)
Returns the MIME type of a value that includes parameters (for example, application/json;charset=UTF-16). The expression in the value of { “myMediaType” : payload.^mediaType } might return “myMediaType”: “/; charset=UTF-8″ for an input POJO.
In the following Mule app flow, the Logger uses payload.^mediaType to select the media type of 2014-10-12T11:11:19-00:03 set in the Set Payload (set-payload) component.
Mule App XML in Anypoint Studio:
<flow name=”setpayloadobjectFlow” >
<scheduler doc:name=”Scheduler” >
<scheduling-strategy >
<fixed-frequency frequency=”15″ timeUnit=”SECONDS”/>
</scheduling-strategy>
</scheduler>
<set-payload value=’#[|2014-10-12T11:11:19-00:03| as DateTime]’ doc:name=”Set Payload” />
<logger level=”INFO” doc:name=”Logger” message=”#[payload.^mediaType]”/>
</flow>
The Studio console output shows that the DateTime payload has the application/java; charset=UTF-8 media type.
Console Output in Anypoint Studio:
INFO 2019-04-20 16:41:01,276 [[MuleRuntime].cpuLight.04:
[setpayloadobject].setpayloadobjectFlow.CPU_LITE @7e991c71]
[event: c0e96860-63c5-11e9-bcff-8c8590a99d48]
rg.mule.runtime.core.internal.processor.LoggerMessageProcessor:
application/java; charset=UTF-8
In the following Mule app flow, the Loggers use payload.^mediaType to select a string “my string”, then to select a string that is set within an fx expression (#[“my string as String type” as String]) in the Set Payload (set-payload) component.
Mule App XML in Anypoint Studio:
<flow name=”setpayloadobjectFlow” >
<scheduler doc:name=”Scheduler” >
<scheduling-strategy >
<fixed-frequency frequency=”15″ timeUnit=”SECONDS”/>
</scheduling-strategy>
</scheduler>
<!– Set the payload to “my string”. –>
<set-payload value='”my string”‘ doc:name=”Set Payload” />
<!– Select the media type of “my string”. –>
<logger level=”INFO” doc:name=”Logger” message=’#[payload.^mediaType]’/>
<!– Set the payload using the fx expression “my string” as String. –>
<set-payload value=’#[“my string as String type” as String]’ doc:name=”Set Payload” />
<!– Select the media type of a Java string. –>
<logger level=”INFO” doc:name=”Logger” message=’#[payload.^mediaType]’/>
</flow>
The Studio console output shows that the simple string has the media type /, while the string that is set in the fx expression has the media type application/java; charset=UTF-8.
Console Output in Anypoint Studio:
INFO 2019-04-20 16:52:50,801 [[MuleRuntime].cpuLight.01:
[setpayloadobject].setpayloadobjectFlow.CPU_LITE @5d914abe]
[event: 68121cd0-63c7-11e9-bcff-8c8590a99d48]
org.mule.runtime.core.internal.processor.LoggerMessageProcessor:
*/*
INFO 2019-04-20 16:52:51,085 [[MuleRuntime].cpuLight.01:
[setpayloadobject].setpayloadobjectFlow.CPU_LITE @5d914abe]
[event: 68121cd0-63c7-11e9-bcff-8c8590a99d48]
org.mule.runtime.core.internal.processor.LoggerMessageProcessor:
application/java; charset=UTF-8
If you like my post please follow me to read my latest post on programming and technology.
You are given two singly linked lists that intersect at some node. Your task is…
A builder plans to construct N houses in a row, where each house can be…
Find the length of the longest absolute path to a file within the abstracted file…
You manage an e-commerce website and need to keep track of the last N order…
You are given a stream of elements that is too large to fit into memory.…
The formula for the area of a circle is given by πr². Use the Monte…