REQUIREMENT mime.plugin.access.xpath |
Type | NEW |
Priority | MEDIUM |
Status | CLOSED |
Topic | XmlBlaster allows to access message instances filtered with XPath expressions | ||||||||||||||||||||||||||||
Des cription |
XmlBlaster allows you to query topics based on their meta information with XPath. Sometimes this is not enough and you want to do sort of a full text search over the message content, also with XPath, thereby supplying full XML/XPath content based routing of messages. For this frequent use case we deliver a plugin using XPath expressions to check the message content, optionally, by setting the property matchAgainstQos=true you can match against the QoS of the published message instead of the content.
The plugin is registered for the This filter is available for synchronous access with get() and asynchronous access with subscribe()
and as a filter for xmlBlaster cluster support.
Multiple filters can be specified in one subscribe/get invocation. Each of them may address another plugin. They are sequentially executed and if one filter denies access (the match() method returns 'false') the message is not delivered. The filters are logically AND connected.
The cascading approach for XPath/exact query and filters:
The XPathFilter is currently based on the Jaxen xpath engine. It is
also possible to register Jaxen extension functions by specifying them
in the property |
||||||||||||||||||||||||||||
Example any |
Example key and QoS of a get() or subscribe() invocation:<key oid="News/> <qos> <filter type='XPathFilter'> /news[@type='sport'] </filter> </qos> All messages of the topic oid=News are first selected. Those message are further filtered to contain the attribute type equals sport in the news element. Don't forget to put your query in a <![CDATA[ ... ]]> section if you use "<" in your query string. |
||||||||||||||||||||||||||||
Example Java |
Code snippet in Java with the get() methodimport org.xmlBlaster.client.qos.GetQos; import org.xmlBlaster.util.MsgUnit; import org.xmlBlaster.util.qos.AccessFilterQos; GetQos qos = new GetQos(glob); qos.addAccessFilter( new AccessFilterQos(glob, "XPathFilter", "1.0", "/news[@type='sport']")); MsgUnit[] msgUnits = con.get( "<key oid='News'/>", qos.toXml());
The code snippet |
||||||||||||||||||||||||||||
Example Java |
Command line example: Testing your XPath syntaxThis example allows you to test your XPath queries on command line, first set the CLASSPATH to contain the JAXEN libraries export CLASSPATH=$CLASSPATH:$XMLBLASTER_HOME/lib/jaxen.jar now create a file <qos> <clientProperty name='corrId' type='int'>120001</clientProperty> <clientProperty name='SayHello'>Hello World</clientProperty> <clientProperty name='aKey'>aValue</clientProperty> <clientProperty name='MyXmlString' type='String' encoding='base64'> QmxhPEJsYUJsYQ== </clientProperty> </qos> and then start the command line test java org.xmlBlaster.engine.mime.xpath.XPathFilter -inFile test.xmlxpath> /qos/clientProperty/@name='corrId' Match: true xpath> /qos/clientProperty/@name='corYX' Match: false You can now play further with the XPath query as shown above. |
||||||||||||||||||||||||||||
Example Java |
Command line example: Test the plugin with xmlBlasterAssure that the plugin is registered in xmlBlaster.properties MimeAccessPlugin[XPathFilter][1.0]=org.xmlBlaster.engine.mime.xpath.XPathFilterStart the server java -jar lib/xmlBlaster.jarStart a subscriber java -cp lib/xmlBlaster.jar javaclients.HelloWorldSubscribe -oid Hello -filter.type XPathFilter -filter.query "//tomato"Start a publisher with matching content java -cp lib/xmlBlaster.jar javaclients.HelloWorldPublish -numPublish 10 -oid Hello -content "<tomato/>"Start a publisher with NO matching content java -cp lib/xmlBlaster.jar javaclients.HelloWorldPublish -numPublish 10 -oid Hello -content "<apple/>"Now you can play with the full text filtering feature |
||||||||||||||||||||||||||||
Configure |
If you make a xmlBlaster distribution you must make shure to copy xmlBlaster/lib/jaxen.jar and add the jar files to the CLASSPATH. These parameters allow to configure the XPath plugin.
Example for xmlBlaster.properties: MimeAccessPlugin[XPathFilter][1.0]=org.xmlBlaster.engine.mime.xpath.XPathFilter,engine.mime.xpath.maxcachesize=20
NOTE: Configuration parameters are specified on command line (-someValue 17) or in the
xmlBlaster.properties file (someValue=17). See requirement "util.property" for details. |
||||||||||||||||||||||||||||
See API | org.xmlBlaster.engine.mime.xpath.XPathFilter | ||||||||||||||||||||||||||||
See API | org.xmlBlaster.engine.mime.xpath.ContainsIgnoreCaseFunction | ||||||||||||||||||||||||||||
See API | org.xmlBlaster.engine.mime.xpath.RecursiveTextFunction | ||||||||||||||||||||||||||||
See API | org.xmlBlaster.util.qos.AccessFilterQos | ||||||||||||||||||||||||||||
See API | org.xmlBlaster.engine.mime.I_AccessFilter | ||||||||||||||||||||||||||||
See API | org.xmlBlaster.util.plugin.I_Plugin | ||||||||||||||||||||||||||||
See REQ | mime.plugin.accessfilter.howto | ||||||||||||||||||||||||||||
See REQ | mime.plugin.accessfilter | ||||||||||||||||||||||||||||
See REQ | cluster | ||||||||||||||||||||||||||||
See | JAXEN homepage | ||||||||||||||||||||||||||||
See TEST | org.xmlBlaster.test.mime.TestXPathSubscribeFilter | ||||||||||||||||||||||||||||
See TEST | org.xmlBlaster.test.mime.TestXPathTransformer |
This page is generated from the requirement XML file xmlBlaster/doc/requirements/mime.plugin.access.xpath.xml