Reputation: 1063
I'm having a few problems in understanding how to pass a query param to a payload factory that creates a json, and then passing its data to a data service. What I thought would be the correct config is
<payloadFactory media-type="json">
<format>{"cod_uo" : "$1"}</format>
<args>
<arg evaluator="xml" expression="get-property('query.param.id')"/>
</args>
</payloadFactory>
<log>
<property expression="json-eval($.cod_uo)" name="string"/>
</log>
<dataServiceCall description="GET operation" serviceName="MyService">
<operations type="single">
<operation name="MyOperationName">
---> <param evaluator="xml" expression="json-eval('$.cod_uo')" name="cod_uo"/> <-- This Line
</operation>
</operations>
<source type="inline"/>
<target type="body"/>
</dataServiceCall>
but the system doesn't recognize the json-eval function here. I tried also a direct json evaluation with
<param evaluator="json" name="id" expression="$.cod_uo"/>
but i get a DataServiceCallMediator
Current Request Name: MyOperationName
Current Params: {cod_uo=}
Nested Exception:-
java.lang.NumberFormatException: For input string: ""
What is the correct method to use the 'cod_uo' property of the payload factory payload in a subsequent data service call?
I'm using the latest Integration Studio (8.0.0.202104161647)
The log ALWAYS returns
{api:MyApi:v1.0.0} To: /my/path?id=123, MessageID: urn:uuid:[uuid], correlation_id: [correlation_id], Direction: request, string = 123
All combinations + errors:
<param evaluator="xml" expression="json-eval('$.cod_uo')" name="cod_uo"/>
[2021-07-30 08:50:41,179] ERROR {SynapseXPath} - Evaluation of the XPath expression json-eval('$.cod_uo') resulted in an error org.jaxen.UnresolvableException: No Such Function json-eval
<param evaluator="xml" expression="json-eval($.cod_uo)" name="cod_uo"/>
(doesn't compile: "Invalid XPath expression for attribute expression : json-eval($.cod_uo)"
<param evaluator="json" expression="json-eval('$.cod_uo')" name="cod_uo"/>
<param evaluator="json" expression="json-eval($.cod_uo)" name="cod_uo"/>
<param evaluator="json" expression="$.cod_uo" name="cod_uo"/>
Current Request Name: MyOperationName
Current Params: {cod_uo=}
Nested Exception:-
org.postgresql.util.PSQLException: ERROR: invalid input syntax for integer: ""
<param evaluator="xml" expression="$.cod_uo" name="cod_uo"/>
(doesn't compile: Invalid XPath expression for attribute expression : $.cod_uo)
Upvotes: 0
Views: 700
Reputation: 2218
Since both Payload Factory
mediator and the Data Service Call
mediator is in the same sequence, you can make use of the get-property()
function to retrieve the value and assign it.
For example,
<param evaluator="json" name="id" expression="get-property('query.param.id')"/>
Furthermore, if you wanted to access the property through json-eval()
, I think there has been a typo that is causing the empty value behavior. Please remove the quotes around the key and try the scenario
Update Note: The
json-eval()
approach didn't solve the problem. But, keeping the following segment as a reference. Look at theUpdate
section to access the payload using XPath expression.
<!-- without single quotes around the $.myId -->
<param evaluator="json" name="id" expression="json-eval($.myId)"/>
You can also try accessing the Payload using XPath expression as following
<param evaluator="xml" name="id" expression="$body//myId"/>
Upvotes: 2