How to access property mediator outside iterator w

2019-09-18 03:56发布

问题:

I have treed as below

<iterate xmlns:oag="http://www.openapplications.org/oagis/10" xmlns:fn="http://www.w3.org/2005/xpath-functions" continueParent="true" preservePayload="true" attachPath="//ProcessCredit/DataArea" expression="//ProcessCredit/DataArea/Credit sequential="true">
.....
 <property xmlns:ns="http://org.apache.synapse/xsd"
                        xmlns:oa="http://www.openapplications.org/oagis/10"
                        name="ChargeTransactionKey"
                        expression="concat(get-property('operation','ChargeTransactionKey'),//Extension/ValueText[@typeCode='Charge Transaction Key'],':')"
                        scope="operation"
                        type="STRING"
                        description="ChargeTransactionKey"/>
 ...........

</iterate >
<log level="full">
<property name="requestIdChargeTransactionKey"
                  expression="get-property('operation','ChargeTransactionKey')"/>
     </log>

but value in property "requestIdChargeTransactionKey" is null, it means I'm unable to capture the property which is defined inside iterator.

can anybody help on syntax?

回答1:

The mediation inside iterate works with clones of MessageContext. If you continue parent mediation (set continueParent attribute to true), you work with the initial MessageContext and therefore all the properties you have set with scope 'default' inside iterate are lost

But there is a scope named 'operation' used to retrieve a property in the operation context level and if you set a property with this scope inside iterate, you can get it's value in the parent mediation

Inside iterate :

<property name="ChargeTransactionKey" value="xxx" scope="operation"/>

In parent mediation :

get-property('operation','ChargeTransactionKey')


回答2:

WSO2 Documentation, You can fetch the property in the operation context level from the operation scope.

The properties within iterated/cloned message with the operation scope are preserved in the sequence even if you have configured your API resources to be sent through the fault sequence when faults exist.

get-property('operation', String propertyName)

A given property with the operation scope only exists in a single request and can be accessed by a single resource. The properties in this scope are passed to the error handler when the FORCE_ERROR_ON_SOAP_FAULT property is set to true