WSO2 get request body using property expression - api

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"/>

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>

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

I'm having a problem with using apostrophe character in the property expression.
I tried &apos;, \', 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"/>

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.

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