XmlBlaster Logo

REQUIREMENT

mime.plugin.access.regex

XmlBlaster Logo


Type NEW
Priority MEDIUM
Status CLOSED
Topic XmlBlaster allows to access messages filtered with regular expressions
Des
cription

XmlBlaster allows you to query messages 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.

For this frequent use case we deliver a plugin using regular expressions to check the message content.

The plugin is registered for all message mime types, which allows you to do regular expression filtering on any message content.

This filter is available for synchronous access with get() and asynchronous access with subscribe() and as a filter for xmlBlaster cluster support.
You can specify the filter rules with two xmlBlaster methods:

  1. Synchronous access with the get() invocation:
    Specify the filter rule in the QoS of the get() method to filter the desired messages. The messages are returned as the get() return value.
  2. Asynchronous access with the subscribe() invocation
    Specify the filter rule in the QoS of the subscribe() method to filter the desired messages. The messages are returned with the asynchronous update() callback.

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:
On subscribe first the usual XPATH or exact subscription is checked. The client is added as subscriber to all matching message types. If now real messages arrive, the filter plugin is additionally filtering messages away. The same applies for get() invocations.

Example
any

Example key and QoS of a get() or subscribe() invocation:

      
      <key queryType='XPATH'>
         //StockData
      </key>

      <qos>
         <filter type='GnuRegexFilter'>
            a*b
         </filter>
      </qos>
      
      

All messages containing the xml meta information element <StockData/> are selected. Those message are further filtered to contain any number of 'a' and ending with exactly one 'b'.

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() method

      
   import 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,
            "GnuRegexFilter", "1.0", "a*b"));

   MsgUnit[] msgUnits = con.get(
            "<key queryType='XPATH'> //StockData </key>",
            qos.toXml());
      
      

The code snippet new AccessFilterQos(...) adds the above raw <filter> xml ASCII string, so we don't need to do it our self. The second and third parameters "GnuRegexFilter", "1.0" choose the plugin (in this case the regex plugin) and the fourth parameter add the query rule for the plugin (in this case a regular expression).

You can play with regular expressions, just invoke (you need xmlBlaster.jar in your CLASSPATH):

   java RETest "aaa*b" "aab"
      
Example
Java

Command line example

Start the server

java -jar lib/xmlBlaster.jar

Start a subscriber

java -cp lib/xmlBlaster.jar javaclients.HelloWorldSubscribe -oid Hello -filter.type GnuRegexFilter -filter.query ".*A"

Start a publisher with matching content

java -cp lib/xmlBlaster.jar javaclients.HelloWorldPublish -numPublish 100 -oid Hello -content "xxA"

Start a publisher with NO matching content

java -cp lib/xmlBlaster.jar javaclients.HelloWorldPublish -numPublish 100 -oid Hello -content "12B"

Now you can play with the full text filtering feature

Configure

These parameters allow to configure the regex plugin.

Property Default Description Implemented
MimeAccessPlugin[GnuRegexFilter][1.0] org.xmlBlaster.engine.mime.regex.GnuRegexFilter Loads the regex plugin on demand. yes

NOTE: Configuration parameters are specified on command line (-someValue 17) or in the xmlBlaster.properties file (someValue=17). See requirement "util.property" for details.
Columns named Impl tells you if the feature is implemented.
Columns named Hot tells you if the configuration is changeable in hot operation.

See http://www.cacas.org/java/gnu/regexp/
See http://developer.java.sun.com/developer/technicalArticles/releases/1.4regex/
See API org.xmlBlaster.engine.mime.regex.GnuRegexFilter
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 TEST org.xmlBlaster.test.mime.TestGetRegexFilter

This page is generated from the requirement XML file xmlBlaster/doc/requirements/mime.plugin.access.regex.xml

Back to overview