I am developing a proxy service in WSO2 ESB.
With this configuration, I retrieve the xml web service response. The response uses a default namespace as shown:
<enrich>
<source type="body" clone="true" />
<target type="property" property="soapXmlResponseReadCahceDataService" />
</enrich>
This is the xml response:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body>
<cacheServices **xmlns="http://cache.services"**>
<cacheService>
<id>1</id>
<xmlrequesthash>b1e97b67-1226-4b1d-9081-b2a140690efd</xmlrequesthash>
<xmlrequestpayload>c</xmlrequestpayload>
<xmlresponsepayload>d</xmlresponsepayload>
<quantity>1</quantity>
</cacheService>
</cacheServices>
</soapenv:Body> </soapenv:Envelope>
thereafter I need get the element quantity:
<property xmlns="http://cache.services" name="count" expression="//cacheServices/cacheService/quantity" />
WSO2 ESB does not allow you to place a namespace without a prefix, and I can not obtain this value. I can do to obtain this value, since the xml response has no namespace prefix?
Can you try this xpath in property mediator ?
<property name="count" expression="//*[name()='cacheServices']/*[name()='cacheService']/*[name()='quantity']" scope="default" type="STRING"/>
Alternatively you can use this by adding any namespace prefix since you are using default namespace.
<property xmlns:ns1="http://cache.services" name="count" expression="//ns1:cacheServices/ns1:cacheService/ns1:quantity" scope="default" type="STRING"/>
Related
I am reading some values from source table and writing to a target table.Since the fields are different in names and some values , i am using XSLT mediator in WSO2 ESB.
After the xslt mediator , i want to inject few more values into the payload.Say some variables which i have previously store. I cant do it xslt because these values are in some variables.
So below is my code.What should be the code the dashed lines?
<enrich>
<source clone="true" property="SOURCE_TABLE_PAYLOAD" type="property"/>
<target type="body"/>
</enrich>
<xslt key="gov:/bcogc/transformation/SourcetoTargetTransformation.xslt"/>
----------------ADD SOME MORE VALUES HERE to the payload------------------
<header name="Action" scope="default" value="urn:inserttotargettable"/>
<call>
<endpoint key="gov:/endpoints/INSERT_DataService_EP.xml"/>
</call>
Please throw some lights
You can again use an enrich mediator for example ,
<property name="orderID" scope="default" description="orderID">
<orderID xmlns="">2</orderID>
</property>
<enrich>
<source clone="true" xpath="$ctx:orderID"/>
<target action="sibling" xpath="//orders"/>
</enrich>
Here the orderID property is defined , so now you can add that property as a sibling with you request coming out of XSLT, so the request will look like below after enriching
<orders>
<order>
<price>50.00</price>
<quantity>500</quantity>
<symbol>IBM</symbol>
<comment>REF 10053</comment>
</order>
<order>
<price>18.00</price>
<quantity>500</quantity>
<symbol>MSFT</symbol>
<comment>ref 20088398289</comment>
</order>
</orders>
<orderID>2</OrderID>
This is existing header
<s:Header>
<ActivityId xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics" CorrelationId="10018d27-2573-4d6b-8bcb-b49f6c686f1a">5d827c1d-bd7b-437f-904f-5f82c9844022</ActivityId>
</s:Header>
I need to add following security in header part using enrich mediator
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<o:UsernameToken u:Id="uuid-05a278f7-0f00-4710-b81c-4401fd280d6d-3">
<o:Username>FISEPAY_DEV</o:Username>
<o:Password>RaDrup5E4awreP</o:Password>
</o:UsernameToken>
</o:Security>
So how i need to add using enrich mediator
Try using the below code.
<enrich>
<source type="inline" clone="true">
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<o:UsernameToken u:Id="uuid-05a278f7-0f00-4710-b81c-4401fd280d6d-3">
<o:Username>FISEPAY_DEV</o:Username>
<o:Password>RaDrup5E4awreP</o:Password>
</o:UsernameToken>
</o:Security>
</source>
<target xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
xpath="//<s:Header>"/>
</enrich>
<log level="full"/>
Use the property mediator as below ,
<property name="test" expression="get-property('registry','conf:/test.xml')" scope="default" type="OM" />
conf:/test.xml should be the path where your xml is stored.
Now this variable "test" can be used in enrich mediator.
I'm trying to use the Filter mediator for my response to check whether the response is a collection.
So what I did here is to check whether the element id in belongs_to_collection is a numeric
<property expression="/soapenv:Envelope/soapenv:Body/root:movie/belongs_to_collection/id" name="collection" scope="default" type="STRING"/>
<filter description="" regex="[0-9]+" source="get-property('collection')">...</filter>
Here's my full api config
http://pastebin.com/QA3GCd1W
and here's the response to be filter
http://pastebin.com/0dxweJu3
If you don't want to deal with namespaces, you can use local-name() like this.
<property name="collection"
expression="//*[local-name()='belongs_to_collection']/*[local-name()='id']/text()"
scope="default"
type="STRING"/>
If you use namespace prefixes in your expression you need to define those namespaces. For example:
<property expression="/root:movie/belongs_to_collection/id"
name="collection" scope="default" type="STRING" xmlns:root="www.wso2esb.com"/>
The response I see when using your API however is
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<jsonObject>
<belongs_to_collection>
<id>8650</id>
...
Your root element is the soapenv:Envelope tag, so you don't have to put that in your expression anymore. The / at the beginning refers to the root element. Anything after that refers to elements inside your root element.
So the expression should be as follows:
<property xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
name="collection" expression="/soapenv:Body/jsonObject/belongs_to_collection/id"
scope="default" type="STRING"/>
Is it possible to enrich a specific node value with enrich mediator?
My goal is to enrich this xpath:
$ctx:OriginalPayload//Partner[identifiers/businessId = $ctx:CorrelationId]/identifiers/otherId
I have tried these examples:
$ctx:OriginalPayload//Partner/identifiers/otherId
//Partner/identifiers/otherId
//Partner/identifiers/otherId/text()
//Partner/identifiers/otherId/node()
All gave me this error:
ERROR - EnrichMediator Invalid Target object to be enrich.
I'm using this syntax:
<enrich>
<source xpath="//plat:CustomerAccountId"/>
<target xpath="//Partner/identifiers/otherId"/>
</enrich>
Below is my payload which i'm trying to enrich:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="http://iszkody.lsn.io/service/internal/ClaimService">
<soapenv:Header/>
<soapenv:Body>
<ns0:createClaimRequest>
<claim>
<InsClaimData VER="1">
<PartnerList>
<Partner>
<RoleList>
<Role>UBEZP</Role>
</RoleList>
<BusinessPartner>
<partnerType>person</partnerType>
<personData>
<firstName>JANUSZ</firstName>
<lastName>KOWALSKI</lastName>
<PESEL>83248328432</PESEL>
</personData>
<identifiers>
<businessId>123</businessId>
<otherId></otherId>
</identifiers>
</BusinessPartner>
</Partner>
</PartnerList>
</InsClaimData>
</claim>
</ns0:createClaimRequest>
</soapenv:Body>
</soapenv:Envelope>
It doesn't look like a problem with payload or xpath but more like the mediator doesn't implement custom type.
I just tested the following in WSO2 ESB 4.9.0 and also 4.8.1 and in both version the following proxy did work (I enrichted the otherId with the businessId):
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Test_XPath" transports="http" xmlns:avintis="http://www.avintis.com">
<target faultSequence="faultSequence">
<inSequence>
<sequence key="initSequence" />
<log level="full"></log>
<log level="custom">
<property expression="$body//businessId" name="xpath" />
</log>
<log level="custom">
<property expression="$body//Partner/BusinessPartner/identifiers/businessId" name="xpath" />
</log>
<enrich>
<source xpath="//businessId" />
<target xpath="//otherId" />
</enrich>
<log level="full" />
</inSequence>
</target>
</proxy>
As you commented that you now use the *[local-name()='BusinessPartner'] syntax, this points out to be an issue with the namespaces. Try to use the correct namespace of the BusinessParter elements.
I have to set the soap envolope from a OM property populated with xml content. I use the enrich mediator to do this with the following code:
<log>
<property xmlns:ns="http://org.apache.synapse/xsd" name="envelope" expression="$ctx:mensaje" />
</log>
<enrich>
<source xmlns:ns="http://org.apache.synapse/xsd" clone="false" type="property" property="mensaje" />
<target action="replace" type="envelope" xpath="" property="" />
</enrich>
The log instruction shows a correct soap envelope but the system log stops with
08:12:26,997 [-] [HttpServerWorker-8] INFO Start : Enrich mediator
and I get this soap fault:
<soapenv:Fault>
<faultcode>soapenv:Server</faultcode>
<faultstring>Index: 0, Size: 0</faultstring>
<detail/>
</soapenv:Fault>
Any help?
You are trying to get property from message context..Use like this in your source configuration..
get-property('mensaje')