Raw Metadata Selector (.^raw)

Raw Metadata Selector (.^raw)

Returns the underlying binary value of a POJO. This selector is sometimes used when calculating an MD5 or some other cryptographic hash function to check for man-in-the-middle (MITM) attacks.

The following example uses the Set Payload component (set-payload) to produce a binary value, then uses the Transform Message component (ee:transform) component to return raw data for the MD5 (MD5(payload.^raw)) of the binary value. The Logger component (logger) is also set to write the raw data to the Studio console. For comparison, the second Logger returns the typical payload in a standard JSON format.

Mule App XML in Anypoint Studio:

<flow name=”rawcaret2Flow” >

<scheduler doc:name=”Scheduler” >

<scheduling-strategy >

<fixed-frequency frequency=”30″ timeUnit=”SECONDS”/>

</scheduling-strategy>

</scheduler>

<set-payload value=’#[“1234-5678-9123″ as Binary]’ doc:name=”Set Payload” />

<ee:transform doc:name=”Transform Message” >

<ee:message >

<ee:set-payload ><![CDATA[%dw 2.0

import * from dw::Crypto

output application/json

{ “myRawData” : MD5(payload.^raw) }]]></ee:set-payload>

</ee:message>

</ee:transform>

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

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

</flow>

Notice that instead of producing standard JSON output, the raw output in the Logger message surrounds the entire payload in double-quotes and inserts new line characters (\n) for each new line.

Console Output in Anypoint Studio:

INFO  2019-04-22 14:10:14,537 [[MuleRuntime].cpuLight.08:

[rawcaret2].rawcaret2Flow.CPU_LITE @764a5a61]

[event: 058f6a90-6543-11e9-9d99-8c8590a99d48]

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

“{\n  “myRawData”: “5403e5a202c594871d59898b13054be5″\n}”

INFO  2019-04-22 14:10:14,540 [[MuleRuntime].cpuLight.08:

[rawcaret2].rawcaret2Flow.CPU_LITE @764a5a61]

[event: 058f6a90-6543-11e9-9d99-8c8590a99d48]

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

{ “myRawData”: “5403e5a202c594871d59898b13054be5” }

The following example uses the HTTP Listener source (listener) to get the XML payload received via a POST request, then uses the Transform Message component (ee:transform) to get the encoding value of the XML payload, by returning the raw data ((payload.^raw as String) scan /encoding='([A-z0-9-]+)’/)). The Logger component (logger) returns the payload in a JAVA format.

Mule App XML in Anypoint Studio:

<http:listener-config name=”HTTP_Listener_config” >

<http:listener-connection host=”0.0.0.0″ port=”8081″ />

</http:listener-config>

<flow name=”test-flow”>

<http:listener path=”/test” config-ref=”HTTP_Listener_config”/>

<ee:transform>

    <ee:message>

    <ee:set-payload ><![CDATA[%dw 2.0

output application/java

((payload.^raw as String) scan /encoding='([A-z0-9-]+)’/)[0][1]]]></ee:set-payload>

    </ee:message>

</ee:transform>

<logger level=”INFO” message=”#[payload]”/>

</flow>

Using your preferred REST client or API testing tool, send a POST request with the XML body:

<?xml version=’1.0′ encoding=’ISO-8859-1′?>

<test>

</test>

The Logger message returns the extracted encoding value ISO-8859-1:

Follow Me

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

Instagram

Facebook

Recent Posts

Find Intersection of Two Singly Linked Lists

You are given two singly linked lists that intersect at some node. Your task is…

4 months ago

Minimum Cost to Paint Houses with K Colors

A builder plans to construct N houses in a row, where each house can be…

4 months ago

Longest Absolute Path in File System Representation

Find the length of the longest absolute path to a file within the abstracted file…

4 months ago

Efficient Order Log Storage

You manage an e-commerce website and need to keep track of the last N order…

5 months ago

Select a Random Element from a Stream

You are given a stream of elements that is too large to fit into memory.…

5 months ago

Estimate π Using Monte Carlo Method

The formula for the area of a circle is given by πr². Use the Monte…

5 months ago