How to use apostrophe character in the fn:concat-property expression WSO2 ESB - wso2-esb

I'm having a problem with using apostrophe character in the property expression.
I tried ', \', but they were failed. So, currently I'm managing myself with defining it as another property as mentioned below.
<property value="'" name="apos" scope="default" type="STRING"/>
<property description="xpathexpr" expression="fn:concat('$ctx:hotel-static-data-rs//jsonObject/rows[id=',$ctx:apos,'hotelbeds_v3-',$ctx:hotelcode,$ctx:apos,']/value')" name="xpathexpr" scope="default" type="STRING"/>
<property description="hotel-static-data-element" expression="evaluate($ctx:xpathexpr)" name="hotel-static-data-element" scope="default" type="OM"/>
I'm sure there must be a better way to handle this. So, if anyone have a clue please update.
WSO2 ESB version : 5.0.0

Try replace apostrophe character as this example.
<property name="hotelContentExpr"
expression="fn:concat('//content[hotelcode=','"',get-property('htlCode'),'"',']')"
scope="default"
type="STRING"/>

Related

Not being able to fetch the result to log in POST API

I am trying to do post api request and trying to fetch the data through SQL Query, however, I am unable to understand how to log the results. Any help would mean a lot, the code I have written is below:
<statement>
<sql><![CDATA[SELECT * FROM TEST2 t WHERE t.CORRELATION_ID = 1]]></sql>
<result column="CORRELATION_ID" name="CORRELATION_ID"/>
<result column="MSISDN" name="MSISDN"/>
<result column="FL" name="FLAG"/>
</statement>
<log level="full">
<property name="After Query" value="Below Query"/>
<property expression="get-property(FLAG)" name="FLAGG"/>
</log>
I am not getting any value in logs instead it is printing nothing as the value is given as "FLAGG = ".
Thank You
If you get data from the Database the returned values should be assigned to properties. Your Log seems to be a bit off. Can you try the following?
<log level="full">
<property name="After Query" value="Below Query"/>
<property expression="$ctx:FLAG" name="FLAGG"/>
<property expression="$ctx:CORRELATION_ID" name="CORRELATION_ID"/>
</log>

WSO2 get request body using property expression

I want extract request body of a API call returning as a text.
Response from log mediator.
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><text xmlns="http://ws.apache.org/commons/ns/payload">**1**</text></soapenv:Body></soapenv:Envelope>
I want to extract 1 which is coming in the body. Please see the screenshot.
I have tried following it didn't work
<property expression="$body" name="api_response_status" scope="default" type="STRING"/>
Following Property Expression worked for me.
<property expression="json-eval($.text)" name="api_response_status" scope="default" type="STRING"/>

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 node from xml in property

i stored an XML document in a property:
<property expression="$body//*" name="InDoc"
scope="default" type="OM"/>
in a later step of the proxy a want to access the XML doucment.
This
<log level="custom">
<property name="InDoc" expression="get-property('InDoc')"/>
</log>
gives the whole XML document. But I would like to access only some parts of the XML e.g. only one value in a later step of the proxy. I already tried
<log level="custom">
<property name="InDoc" expression="get-property('InDoc')//AAA"/>
</log>
or this
<log level="custom">
<property name="InDoc" expression="$ctx:InDoc//AAA"/>
</log>
But both do not work. Is there another way?
Thanks in advance.
Roland
I think both way should work fine. The expression support XPath 1.0. You can run any XPath after the "get-property" in expression.
But you need check,
make sure you use the right XPath.
So you can log/copy the get-property('InDoc'), and then you can use any XPath tool to validate your XPath.
Namespace of the XPath in expression,
if your xml payload have namespace, make sure your XPath namespace is right, and declare right NS in property.
Through property mediator, you are not going to store XML file, you just retrieving content from it. As you have to retrieve part of it, you can give it through property mediator.
<property expression="$body//*" name="InDoc" scope="default" type="OM"/>
Through expression you should define it.
expression="$body//*"
You can change this and get required parts of xml. If you need few parts, you can add several properties for each and retrieve value from it.

Change nhibernate config with nant xmlpoke

How can I change the connection string from nhibernate.config file using nant
the problem is that all examples are about changing attribute value, but nhibernate has inner text
eq:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.connection_string">Data Source.\server;Database=UnitTestDb;UID=user;pwd=pass;</property>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="show_sql">true</property>
<property name="connection.release_mode">auto</property>
<property name="adonet.batch_size">500</property>
....
I need to change property connection.connection_string
<xmlpoke file="${nhibernate.file}"
xpath="/hibernate-configuration/session-factory/add[#key='connection.connection_string']/#value"
value="${connection.string}">
</xmlpoke>
this does not work in this case.
Thanks
The sample xpath you're using refers to elements named add with attributes called key. In your case you are looking for property elements with attributes called name.
Next, since you want to change the inner text and not the #value attribute on the property element you should remove the trailing attribute reference.
And finally, since the NHibernate xml has a specific namespace you will have to inform xmlpoke to use the correct namespace.
So the task should look like this:
<xmlpoke file="${nhibernate.file}"
xpath="/nhc:hibernate-configuration/nhc:session-factory/nhc:property[#name='connection.connection_string']"
value="${connection.string}">
<namespaces>
<namespace prefix="nhc" uri="urn:nhibernate-configuration-2.2" />
</namespaces>
</xmlpoke>
Note: I've not tested this out, but general xml/xpath rules are in work here so I hope it works. Also, it could be that there is a way to indicate to xmlpoke that the specified namespace should be the default and thus eliminate the need to namespace prefix all the various parts in the xpath.
Good luck!