Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WSO2 ESB payload from property

Tags:

wso2

wso2-esb

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?

like image 267
Clovis Leoncio Junior Avatar asked Oct 31 '25 16:10

Clovis Leoncio Junior


2 Answers

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.

like image 183
Bee Avatar answered Nov 02 '25 06:11

Bee


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>
like image 28
namalfernandolk Avatar answered Nov 02 '25 07:11

namalfernandolk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!