Reputation: 48
I am building a simple API in WSO2 EI/ESB. I am saving each of the request parameters to properties like so:
<property expression="json-eval($.client_id)" name="client_id" scope="default" type="STRING"/>
And then building a payload using the payload factory:
<payloadFactory media-type="json">
<format>
{
"req_type": "1",
"client_id": $1
}
</format>
<args>
<arg evaluator="xml" expression="get-property('client_id')"/>
</args>
</payloadFactory>
However, if I sent an empty message {}
(without the client_id) then nothing is placed in the $1 argument and the resulting payload will not validate:
{
"req_type": "1",
"client_id:
}
What I would like to know is if there is a way to set a default value when saving this expression in the property mediator? For example:
<property expression="json-eval($.client_id)" name="client_id" scope="default" type="STRING" defaultValue="0"/>
or something like that.
I am aware I can implement filters to check whether the field exists and validate it but I find that can become a bit cluttered.
Upvotes: 2
Views: 1703
Reputation: 1832
Conditional xpath ? This might work. Play around with code underneath.
<enrich>
<source clone="true" type="custom" xpath="0" />
<target action="replace" type="custom" xpath="" property="boolean(string-length(//client_id) != 0)" />
</enrich>
Upvotes: 0
Reputation: 88
No you can't using payloadFactory. You have to choose from different solutions:
Upvotes: 2
Reputation: 12512
I don't think there is a way to do that. You will have to use filters.
Upvotes: 0