I am creating a proxy in which i am creating a property that gets data from the request body using x-path expression. The property i have written is:
<property xmlns:xs="http://www.openoandm.org/xml/ISBM/" name="ChannelURI" expression="//xs:ChannelURI" scope="default" type="STRING"/>
Now i have called a class mediator to which i am passing the value of this property. So in my class mediator, i have written
public String channelUriFromProp = String.valueOf(context.getProperty("ChannelURI"));
So now if i pass any string value to the ChannelURI property, I can get that value inside my class mediator string channelUriFromProp.
But the real problem is that when i pass null value in from request
<body>
<p:OpenPublicationSession xmlns:p="http://www.openoandm.org/xml/ISBM/">
<!--Exactly 1 occurrence-->
<xs:ChannelURI xmlns:xs="http://www.openoandm.org/xml/ISBM/"></xs:ChannelURI>
</p:OpenPublicationSession>
</body>
Then when i print the value of channelUriFromProp in class mediator code i get
<xs:ChannelURI xmlns:xs="http://www.openoandm.org/xml/ISBM/"/>
instead of getting null or empty. Whatam i doing wrong in here?
Thanks in advance.
Your xpath is wrong, it should be like this..
<property xmlns:xs="http://www.openoandm.org/xml/ISBM/" xmlns:p="XXXXXXXXX" name="ChannelURI" expression="//p:OpenPublicationSession/xs:ChannelURI"
Related
I'm trying to use Call Template Mediator in WSO2 and I'm trying to get a dynamic value inside function, but I don't find the way to get it.
For example:
<property expression="$ctx:variable" name="test" type="STRING"/>
<call-template target="HelloWorld_Logger">
<with-param name="message" value="VARIABLE: " expression="$ctx:test" />
</call-template>
I'm not able to get the property "test", if i remove value field the IDE reports an error.
There is some way to get a property inside <call-template> function?
The Call Template Mediator doesn't have a parameter called expression to pass dynamic values. You must pass the XPath expression within {} to the value parameter itself. In your case, the call-template will be as follows,
<call-template target="HelloWorld_Logger">
<with-param name="message" value="{$ctx:test}"/>
</call-template>
Please refer to the Call Template Mediator for more information.
It's possible to set a variable of mediator configuration field with a file? I just don't want to hard code the timeout field of a cache mediator, it is possible?
Thanks!
It seems that we are not able to pass an expression to timeout value. [1] only expects an integer to be provided not an expression.
[1]-https://github.com/wso2/carbon-mediation/blob/master/components/mediation-ui/mediators-ui/org.wso2.carbon.mediator.cache.ui/src/main/java/org/wso2/carbon/mediator/cache/ui/CacheMediator.java#L419
You can read a file stored in the registry like this, but I'm not sure if it's possible to change the cache timeout using a variable.
<property name="xmlFile" expression="get-property('registry','gov:/test.xml')" scope="default" type="OM"></property>
<log level="custom">
<property name="Book_Name" expression="$ctx:xmlFile//book"></property>
</log>
Ref: https://movingaheadblog.blogspot.com/2015/09/wso2-esb-how-to-read-value-from-xml.html
I need to cut body content in logs in WSO2 ESB. For this purpose, I have two parameters in registry: enabled (true or false) and limit (integer, for example: 1024).
For that, I have next expression in a property:
<property name="BODY_TO_LOG" expression="fn:substring(get-property('default','BODY'),0,getproperty('default','LIMIT'))" type="STRING" scope="default"/>
Note that BODY and LIMIT properties have been set previously.
My problem is it does not limit in logs, although the value of these properties are right.
Is it correct that form of limit the content of property?
Your expression should work. I have tested it and came to the nonsensical conclusion that when you declare your LIMIT property with type INTEGER, it doesn't log anything. When you declare your LIMIT property without a type - it works. If you declare your LIMIT property with a type STRING it also works.
So, basically your declaration of the LIMIT property should resemble the following:
<property name="LIMIT" type="STRING" value="1024" scope="default"/>
or
<property name="LIMIT" value="1024" scope="default"/>
I want to get a URI VAR value from request to call correct case in switch in WSO2 ESB API resource, like this:
<api name="apk" context="/apk"><resource methods="GET" uri-
template="/apk/{appName}"><inSequence><header name="App"
scope="transport" action="remove"/><switch source="get-
property('uri.var.appName')"><case regex="BEBE"><send><endpoint><http
method="GET" uri-template="http://localhost/apk/Bebe.apk></http>
</endpoint></send></case><case regex="CITAS"><send><endpoint><http
method="GET" uri-template="http://localhost/apk/Citas.apk></http>
</endpoint></send></case></switch></inSequence></resource></api>
In switch, source="get-property('uri.var.appName')" it's not correct.
Can I get this value using $url SynapseXpath valiables like $url?
What you have done is correct. Please try the same with a log mediator and see whether you get the value properly.
<log level="custom">
<property name="AppName" expression="get-property('uri.var.appName')"/>
</log>
Alternatively you can assign this to a property and use that inside your switch mediator.
I have my request body as:
<tns:InputRequest xmlns:tns="http://tempuri.org/">
<tns:ID>ID_001</tns:ID>
<tns:ID>ID_002</tns:ID>
<tns:Description>Description for ID_001</tns:Description>
<tns:Description>Description for ID_002</tns:Description>
</tns:InputRequest>
and to get the value of ID and Description, i Have created property as:
<property xmlns:tns="http://tempuri.org/" name="ID" expression="//tns:ID" scope="default" type="STRING"/>
<property xmlns:tns="http://tempuri.org/" name="Description" expression="//tns:Description" scope="default" type="STRING"/>
But this gets me only one value. How can i make a property array so that i can store multiple values of ID and description in it and how to retreive from this array property?Looking forward to your reply.Thanks in advance
You should be able to extract those values using XPATH (//node/child::node()) and then set to property.
Below thread will help you to extract required nodes and set to property. You need to set the type as 'OM' to preserve XML as it is.
how to catch an array of nodes to a property