I'm trying to create a payload from a property content:
<payloadFactory media-type="xml">
<format>$1</format>
<args>
<arg evaluator="xml" expression="get-property('Response')"/>
</args>
</payloadFactory>
WSO2 ESB is not accepting this as a valid payload format. What can I do to achieve this?
You can't use Payload Factory for this. It requires a wrapping XML tag like this.
<payloadFactory media-type="xml">
<format><Root>$1</Root></format>
<args>
<arg evaluator="xml" expression="get-property('Response')"/>
</args>
</payloadFactory>
But you can do what you want with Enrich mediator.
<enrich>
<source clone="false" type="property" property="ORIGINAL_PAYLOAD"/>
<target action="replace" type="body"/>
</enrich>
Here is a similar sample.
May be because of the type of the 'Response' Clovis. I'm using this and found no problem.
<property description="requestBk" expression="json-eval($.)" name="requestBk" scope="default" type="STRING"/>
<payloadFactory media-type="json">
<format>$1</format>
<args>
<arg evaluator="xml" expression="$ctx:requestBk"/>
</args>
</payloadFactory>
One other tip. Use $ctx: instead of get-property method for a better performance. Because get-property looks in the registry also.
And yes! as Bhathiya and Maria suggested you can use the Enrich mediator also as mentioned below.
Copy the original payload to a property using the Enrich mediator.
<enrich>
<source clone="false" type="body"/>
<target action="replace" type="property" property="ORGINAL_PAYLOAD"/>
</enrich>
Then whenever you need the original payload, you replace the message body with this property value using the Enrich mediator as follows:
<enrich>
<source clone="false" type="property" property="ORIGINAL_PAYLOAD"/>
<target action="replace" type="body"/>
</enrich>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With