Filter Mediator on XPATH Functions - xpath

I am facing a problem with my code using Filter mediator and XPATH functions. What I am trying to do in my code is to check if a particular block is empty, do not call/enrich that block and move to another one checks for if it is empty, if not process it and moves to next one and in the end do a commit. Currently I am getting the error as:
FilterMediator Error evaluating XPath expression : fn:exists($body/product/simpleProduct/standardAttributes)
My code is as follows:
<inSequence>
<log level="custom">
<property name="STATUS" value="************ REQUEST ***************"/>
</log>
<transaction action="new"/>
<filter xpath="fn:exists($body/product/simpleProduct/standardAttributes)">
</filter>
<enrich>
<source type="body" clone="true"/>
<target type="property" property="MSG_PAYLOAD"/>
</enrich>
<log level="full"/>
<xslt key="simpleAttributes"/>
<log level="custom">
<property name="STATUS"
value="*********INSERTING Simple Product Attributes *************"/>
</log>
</inSequence>
It fails at fn:exists(). Can you help me with your inputs where am I going wrong?

Apparently the function you use is xpath 2 function. OOTB xpath 2 functions won't work in ESB. If this is xpath2, you have to enable it. To enable xpath 2, for that uncomment synapse.xpath.dom.failover.enabled=true in synapse.properties file.

Related

wso2 xpath selection on property value

in wso2 I've an xml as a local property containing a list of status with code and description (status_list).
I would like to select the correct status for one given code. This code is stored in a property.
I've tried something like
<property name="codes" expression="get-property('status_list')" scope="default" type="OM"/>
<log level="custom">
<property expression="$ctx:codes/status[#code='$ctx:code']" name="Test"/>
</log>
$ctx:codes/status is ok and display the list of all status but as soon as I want to "filter" them it's not working.
Of courise if I hardcode a code the xpath is working.
<property expression="$ctx:codes/status[#code='code1']" name="Test"/>
Do you have an idea how to achieve this?
Ok finally I was not so far away from the response.
The following code is working
<property name="codes" expression="get-property('status_list')" scope="default" type="OM"/>
<log level="custom">
<property expression="$ctx:codes/status[#code=$ctx:code]" name="Test"/>
</log>
I simply had to remove the quotes...

WSo2 Esb filtering messages to an output file

I am working with a filter mediator attempting to send messages to an output xml file. I have my sequence using a filter mediator based on a attribute value, if it is true I want to write the message to a new xml file in a certain directory. If it is false I will drop the record.
Here is my sequence:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="RenaissanceIqtFilterSequence">
<log level="custom">
<property name="sequence" value="FilterSequence"></property>
</log>
<filter xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:ns="http://org.apache.synapse/xsd" xmlns:z="RowsetSchema" xpath="//z:row/#name='RP'">
<then>
<log level="custom">
<property name="sequence" value="Condition Write"></property>
</log>
<call-template target="FileWriteTemplate">
<with-param name="targetFileName" value="NEW_MESSAGE_FILE"></with-param>
<with-param name="addressUri" value="vfs:file:///var/process/rrout"></with-param>
</call-template>
</then>
<else>
<log level="custom">
<property name="sequence" value="Condition Drop"></property>
</log>
<drop></drop>
</else>
</filter>
</sequence>
*I am using a template as you can see to write out to my new output file setting parameters for the file name and uri.
The result is the whole file is being written out to the directory not just the messages I want. I have been running google searches trying to see where I am going wrong. I assume at this point I may be using the Filter mediator incorrectly? Maybe there is a better way or mediator to use to accomplish this task? I would appreciate any thoughts or recommendations folks may have. Thanks for your time!

Querying the cached response in WSO2 DSS/ESB

I have a Oracle database view containing details of around 8000 employees. I need to populate employee search suggestions from that view. I'm planning to use WSO2 DSS/ DSS+ESB to create a data service for that. Rather querying the view for each and every service call, i'm thinking of caching the whole view in DSS/ESB and query the cache for all the filter queries("like", "where" queries) until cache expires.
Is there any possibilities around ESB/DSS related to the above scenario?
Thanks in advance.
You can use cache mediator with WSO2 ESB :
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Test" transports="https http" startOnLoad="true" trace="disable">
<description/>
<target>
<inSequence>
<cache id="someCache" scope="per-host" collector="false" hashGenerator="org.wso2.caching.digest.DOMHASHGenerator" timeout="10">
<onCacheHit>
<log level="custom">
<property name="debug" value="incache"/>
</log>
<header name='To' action="remove"/>
<send/> <!-- send back previous reponse, outSequence will not be executed -->
</onCacheHit>
<implementation type="memory" maxSize="1000"/>
</cache>
<send> <!-- Current request (hash) has not been found in the cache -->
<endpoint>
<address uri="http://myhost:8080/myapp/MyService"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<cache id="someCache" scope="per-host" collector="true"/> <!-- Add this response to the cache -->
<log level="custom">
<property name="debug" value="outseq"/>
</log>
<send/>
</outSequence>
</target>
</proxy>
Inside the inSequence, if current request exists in the cache, 'onCacheHit' mediation will be executed with previous response. Otherwise, the 'send' to the endpoint will be executed
Inside outSequence, you add the response to the cache

How to retrive the value in Wso2esb using Xpath

I am using wso2esb4.7.0 i have written jms proxy so i wish send my data to endpoint but i am unable process this
my proxy is
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="MediaMoveQueue"
transports="jms"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<property name="readingspayload" expression="$body"/>
<payloadFactory media-type="xml">
<format>
<p:hello xmlns:p="http://jaxws.youtility.in/">
<arg0 xmlns="">$1</arg0>
</p:hello>
</format>
<args>
<arg evaluator="xml" expression="get-property('readingspayload')"/>
</args>
</payloadFactory>
<!--header name="Action" value="hello"/-->
<log level="full"/>
<send>
<endpoint>
<address uri="http://192.168.1.2:8282/services/media_move_service_i_f"
format="soap11"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="full"/>
<send/>
</outSequence>
</target>
</proxy>
in this proxy i am getting the data like this if i log this esb
my log is look like this
{"timestamp":1383715637698,"tmpfilename":"313d79a7-c29b-4e1a-9609-818610a6a66b.pdf","objecttype":"Punch","filename":"enterprisedb_order.pdf","totalfilesize":994086,"uuid":"313d79a7-c29b-4e1a-9609-818610a6a66b","objectid":"313d79a7-c29b-4e1a-9609-818610a6a66b","fullpath":"/tmp/tmpmedia//313d79a7-c29b-4e1a-9609-818610a6a66b.pdf","deviceId":"911202500210109","filemimetype":"PNG"}
but i need to just send that json format of data to my endpoint for that i have tried this xpath but its showing errors of name space how would i get this
$axis2ns58:text
but its throwing errors i wish to send that data to my endpoint
i have tried this but i need above format of data only
//soapenv:Body
its giving like this result
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<axis2ns58:text xmlns:axis2ns58="http://ws.apache.org/commons/ns/payload">{"timestamp":1383715637698,"tmpfilename":"313d79a7-c29b-4e1a-9609-818610a6a66b.pdf","objecttype":"Punch","filename":"enterprisedb_order.pdf","totalfilesize":994086,"uuid":"313d79a7-c29b-4e1a-9609-818610a6a66b","objectid":"313d79a7-c29b-4e1a-9609-818610a6a66b","fullpath":"/tmp/tmpmedia//313d79a7-c29b-4e1a-9609-818610a6a66b.pdf","deviceId":"911202500210109","filemimetype":"PNG"}</axis2ns58:text>
</soapenv:Body>
but i wish to send below data to my endpoint even payload also not supporting for this
{"timestamp":1383715637698,"tmpfilename":"313d79a7-c29b-4e1a-9609-818610a6a66b.pdf","objecttype":"Punch","filename":"enterprisedb_order.pdf","totalfilesize":994086,"uuid":"313d79a7-c29b-4e1a-9609-818610a6a66b","objectid":"313d79a7-c29b-4e1a-9609-818610a6a66b","fullpath":"/tmp/tmpmedia//313d79a7-c29b-4e1a-9609-818610a6a66b.pdf","deviceId":"911202500210109","filemimetype":"PNG"}
You could try doing
//soapenv:Body/ns:text
and set the namespace
ns="http://ws.apache.org/commons/ns/payload"
Try this:
Modify your Proxy service as below :
Instead of <property name="readingspayload" expression="$body"/> , modify it to below,
<property xmlns:ns="http://ws.apache.org/commons/ns/payload" name="readingspayload" expression="$body/ns:text/text()"/>
****
Hope this should work!!!

WSO2 ESB: Using external parameter definition for proxy?

We are using several proxies that are listening to different locations. But during develpment, we aren't having the same URI as in the production environment. Is it possible to have the URI (transport.vfs.File.URI) external defined? (Maybe local-entry or another property?)
Following line should be able to load external definition of the actual URI:
<parameter name="transport.vfs.FileURI">get-property('myURI')</parameter>
Full Proxy Example (not working):
<proxy xmlns="http://ws.apache.org/ns/synapse" name="getRN100xml"
statistics="disable" trace="disable" transports="vfs">
<target>
<inSequence>
<send>...</send>
</inSequence>
</target>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.PollInterval">5</parameter>
<parameter name="transport.vfs.MoveAfterProcess">C:/WSO2/In/saved</parameter>
<parameter name="transport.vfs.FileURI">get-property('myURI')</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.xml</parameter>
<parameter name="transport.vfs.ContentType">application/xml</parameter>
<parameter name="transport.vfs.MoveTimestampFormat">yyMMddHHmmss</parameter>
You can check out this post WSO2 ESB - Dynamic value for proxy parameters (transport) for an example how to dynamically set values in a proxy sequence.
A simple way to do this is to make a sequence template and set your parameters in that template. You read this template as the first action in your inSequence.
Your proxy definition looks like:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="getRN100xml"
statistics="disable" trace="disable" transports="vfs">
<target>
<inSequence>
<call-template target="transport_vfs_parameter_settings"/>
<send>...</send>
/<inSequence>
</target>
The template difinition looks sg. like:
<template xmlns="http://ws.apache.org/ns/synapse" name="transport_vfs_parameter_settings">
<sequence>
<property xmlns:ns="http://org.apache.synapse/xsd" name="transport.vfs.FileNamePattern" expression="test.xml"></property>
<property xmlns:ns="http://org.apache.synapse/xsd" name="transport.PollInterval" expression="15" scope="transport"></property>
<property xmlns:ns="http://org.apache.synapse/xsd" name="transport.vfs.ActionAfterProcess" expression="MOVE" scope="transport"></property>
<property xmlns:ns="http://org.apache.synapse/xsd" name="transport.vfs.FileURI" expression="//localhost/D:/Test/in" scope="transport"></property>
<property xmlns:ns="http://org.apache.synapse/xsd" name="transport.vfs.MoveAfterProcess" expression="//localhost/D:/Test/processed" scope="transport"></property>
<property xmlns:ns="http://org.apache.synapse/xsd" name="transport.vfs.MoveAfterFailure" expression="//localhost/D:/Test/failure" scope="transport"></property>
<property xmlns:ns="http://org.apache.synapse/xsd" name="transport.vfs.ContentType" expression="text/xml" scope="transport"></property>
<property xmlns:ns="http://org.apache.synapse/xsd" name="transport.vfs.ActionAfterFailure" expression="MOVE" scope="transport"></property>
</sequence>
</template>
In this way transporting your proxy definition to another environment means using a different template.
Naturally, you can only set in the inSequence those parameters, whose values can be determined at the beginning of the inSequence. For example, if you want the replyFilename contain the reply messageID, set it in the outSequence.

Resources