How to access property mediator outside iterator which is defined inside iterator? - properties

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?

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')

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

Related

How can we inject properties into wso2 Micro Integrator and Enterprise Integrator using file.properties?

I want to use the .car file on another server without using integration studio. So I want to be able to change the hostname and port dynamically using a configuration file. My endpoint URL has variables in it {uri.var.x} that's why I can't use $FILE:x to get the complete URL from file.properties.
I have already tried How to read a property injected from file.properties in WSO2 - micro integrator? but it did not work.
You can simply read the Property from the file and assign it to the variable you desire. Then use it in your Endpoint configurations.
<property expression="get-property('file', 'x')" name="uri.var.x"/>
You can store the values in a properties file called file.properties in the MI_HOME/conf folder and it will be loaded automatically. If you are using a different fileName you can pass it to the server startup script like -Dproperties.file.path=/home/dev/dev.properties. Then you can read them through a Property Mediator.
Further, if you want to construct the full URL from multiple properties you can use Xpath functions.
<property expression="concat('https://', get-property('file', 'host'), ':', get-property('file', 'port'))" name="uri.var.x" scope="default" type="STRING" />
If the properties are not picked from the default file, pass the file path like below.
sh micro-integrator.sh -Dproperties.file.path=./conf/file.properties
Update on WSO2 EI
It seems file scope is not supported in EI. But instead, you can read variables from Environment variables with get-property('env', 'NAME_OF_VARIABLE')
<property expression="concat('https://', get-property('env', 'host'), ':', get-property('env', 'port'))" name="uri.var.x" scope="default" type="STRING"/>
If you want to read them from a properties file, you can do something like the below. Assuming you have a properties file like below.
stockQuoteEP=http://localhost:9000/services/SimpleStockQuoteService
ycr=test1234
host=localycr
port=6676
Add the following script to integrator.sh to export the properties as environment variables. You can improve the script as you require.
while read line; do
echo "Exporting $line"
export $line
done < /home/wso2/wso2ei-6.6.0/conf/file.properties
Then in your integration read them as below.
<property expression="concat('https://', get-property('env', 'host'), ':', get-property('env', 'port'))" name="uri.var.x" scope="default" type="STRING"/>
Update 2 on File Scope in Property mediator
As Sanoj mentioned, file scope in the property mediator is only available from MI 4.0 onward vanilla packs. If you have a WSO2 subscription you can get it as an update for both MI and EI.

Wrong value while using property mediator in WSO2 ESB

I have made a proxy service where the value of "Request1" property showing properly as in incoming request
<s1:PALMUpdateCatalogueRequest xmlns:s1="http://www.example.org/prodcatItemWSO2/">
<s1:updateproductCatalogueList>
<s1:catalogueinternalid>1</s1:catalogueinternalid>
ABC
<s1:itemList>
<s1:Item>
<s1:custitem_prod_cat_item>390</s1:custitem_prod_cat_item>
<s1:item_price_level>7</s1:item_price_level>
<s1:typeofitem>PQR</s1:typeofitem>
</s1:Item>
</s1:itemList>
</s1:updateproductCatalogueList>
<s1:transactionid />
</s1:PALMUpdateCatalogueRequest>
But,after calling a sequence when I am using this below expression to fetch the value of Request1,it's not showing.
What will I do to solve this issue?
<property name="REQUEST" expression="get-property('Request1')" scope="default" type="STRING"/>
You should use correct scopes to read properties. If your property is in the synapse scope, you can read it like this.
<property name="REQUEST" expression="$ctx:Request1" scope="default" type="STRING"/>

WSO2 ESB access context property in the response sequence of an HTTP endpoint

I'm calling an HTTP endpoint and getting the response in
a sequence. Response is getting logged in the seq_sla_resp.
<send receive="seq_sla_resp">
<endpoint key="gov:EDI/SLA/endpoints/edi_sla_payment_ep.xml" />
</send>
Inside this response sequence I'm unable to get a property which I set previously during the call (in the main proxy).
<property expression="//m1:sla_row/m1:tran_id/text()"
name="tran_id" scope="default" type="STRING"
xmlns:m1="http://ws.wso2.org/dataservice" />
When I try to log the property in the seq_sla_resp it ends up in the below error message
<log>
<property expression="$tran_id" name="tran_id" xmlns:m0="http://ws.wso2.org/dataservice"/>
</log>
Following is the error.
SynapseXPath Evaluation of the XPath expression $tran_id resulted in an error
org.jaxen.UnresolvableException: Variable tran_id
How can i get the context value in the response sequence.
In the documentaion it says default scope has the largest life span for the property.
Any help is very much appreciated.
I think you would find that your expression would also not work in the inSequence. You should either use expression="$ctx:tran_id" or expression="get-property('tran_id')"
Please note that WSO2 recommends using $ctx instead of the get-property if the scope is default. The get-property methods search in the registry if the value is not available in the message context. Therefore, it affects the performance.
In your case , you can use
<property expression="$ctx:tran_id" name="tran_id" scope="default" xmlns:m0="http://ws.wso2.org/dataservice"/>
Thanks
Kranthi

Dynamic xpath for the property creation in wso2 esb

My Requirement is that i have to create some property based on xpath based on chaining.
Flow is something like :
1)i am calling service1 and based on that response i am creating the property mediator (svc1_property).
2)The call is made to service2 and the response fetched from the service2 has a list of values .
3) I need to fetch a node from the response of svc2 based on the xpath using property : svc1_property.
Config is :
expression="fn:concat("//ImageList[Level='Employee'][ImageCaption='",$ctx:EmpName,"']/IMG_Large")"
scope="default"
type="STRING"
EmpName is the property created on svc1
Use evaluate
Example:
<property name="xpathexpr" expression="fn:concat('//',get-property('xpathexpression'))" scope="default" type="STRING"/>
<property name="xpatheval" expression="evaluate($ctx:xpathexpr)" scope="default" type="STRING"/>
You can find more infomation in this blog.
The Above article shows the case where property is being used for source . But my requirement is different. The response coming from one API will give the empname and based on that i will fetch the pics of the emp from the list expression="fn:concat("//ImageList[Level='Employee'][ImageCaption='",$ctx:EmpName,"']/IMG_Large")" scope="default" type="STRING" on execution of the above expression the reponse i am getting is //ImageList[Level='Employee'][ImageCaption='Timmy']/IMG_Large ...... if Timmy is the empname. it is just picking the variable name(Timmy in this case) and is not parsing the xpath getting created

Sending Property Value to Wix Extension Method

I have a wix property
<Property Id="VAR1" Value="aValue" />
And i want to send this value into my Extension method
<Property Id="TEST" Value="$(extension.GetResult(VAR1)" />
I want to send the value aValue into the GetResult method, but cant seem to find
the correct syntax to convert VAR1 to 'aValue'
The extension is a preprocessor extension and the Property VAR1 will get set via the user interface...
Properties are only available at runtime, other than by parsing source itself.