coderz.py

Keep Coding Keep Cheering!

Encoding Metadata Selector (.^encoding)

Encoding Metadata Selector (.^encoding)

Returns the encoding of a value. For example, { “myEncoding” : payload.^encoding } might return {“myEncoding”: “UTF-8”} for an input POJO.

In the following Mule app flow, the Logger uses payload.^encoding to select the encoding of “my string”`set in the Set Payload (`set-payload) component. The Scheduler (scheduler) component is simply an event source that regularly generates a new Mule event to hold the payload set in Set Payload.

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 encoding of “my string”. –>

  <logger level=”INFO” doc:name=”Logger” message=”#[payload.^encoding]”/>

</flow>

The Studio console output shows that the payload string has UTF-8 encoding.

Console Output in Anypoint Studio:

INFO  2019-04-20 16:14:24,222 [[MuleRuntime].cpuLight.03:

 [setpayloadobject].setpayloadobjectFlow.CPU_LITE @62bea6a6]

 [event: 0938bf70-63c2-11e9-98e0-8c8590a99d48]

 org.mule.runtime.core.internal.processor.LoggerMessageProcessor:

 UTF-8

Follow Me

If you like my post please follow me to read my latest post on programming and technology.

Instagram

Facebook

Leave a Comment

Your email address will not be published. Required fields are marked *

Advertisement