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

Square Root of Integer

Given an integer A. Compute and return the square root of A. If A is…

1 year ago

Build Array From Permutation

Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…

1 year ago

DSA: Heap

A heap is a specialized tree-based data structure that satisfies the heap property. It is…

1 year ago

DSA: Trie

What is a Trie in DSA? A trie, often known as a prefix tree, is…

1 year ago

Trees: Lowest Common Ancestor

What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…

1 year ago

Binary Search Tree (BST)

A Binary Search Tree (BST) is a type of binary tree that satisfies the following…

1 year ago