Announcement Announcement Module
Collapse
No announcement yet.
xpath router vs xpath selector Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • xpath router vs xpath selector

    Hi,

    By replacing xpath router with xpath selector in the Booking order example give the same result?? What is exactly the difference between the two??Lets imagine that the Booking order example has many orderItems marked with "instock" and v r using xpath router to route the messages based on the same xpath expression (used in example) will it then load the whole document with orderItems marked instock or will it just load ONLY the orderItems marked with instock.What should I do to load ONLY the orderItems marked with instock?? Im asking this cos I am dealing with a very similar situation. Thanks in advance

  • #2
    XPath selector is an implementation of MessageSelector which is intended to allow selection of messages matching given criteria. The router implementations are a strategy for determining which of possibly many message channels a particular message goes to next.

    If you are only interested in the orders that are in stock you can use a MessageFilter in conjunction with a MessageSelector to decide which messages match the given criteria, in stock in this case. Those that don't match are dropped. In the example orders for items not in stock are routed to a resupply channel therefore a router is used.

    See chapter 8 of the reference docs an excerpt of which is below.

    Message Filters are used to decide whether a Message should be passed along or dropped based on some criteria such as a Message Header value or even content within the Message itself. Therefore, a Message Filter is similar to a router, except that for each Message received from the filter's input channel, that same Message may or may not be sent to the filter's output channel. Unlike the router, it makes no decision regarding which Message Channel to send to but only decides whether to send.

    Comment


    • #3
      Thanks for the response. Sorry if its a dumb question but Im not getting things clear..Please help..I have a Dom document with the following XML structure and I need to extract only those Divisions Elements which has "Change-Occured=true". Im getting confused as of how to use Message Selector here.What does it mean by using Message Filter in conjuction with Message Selector in terms of XML config?? An example would be appreciated.

      My Dom Structure

      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <div:divisionResponse xmlns:div="http://gid.com/div/schemas">
      <div:Divisions Added="false" Change-Occured="false" Deleted="false" ID="1"/>
      <div:Divisions Added="false" Change-Occured="false" Deleted="false" ID="32"/>
      </div:divisionResponse>
      How should I use Message Selector with Message Filter to achieve what I want ?? Should it be something like this:
      Code:
      <filter input-channel="input" ref="selector" output-channel="output"/>
      
       <bean id="selector" class="example.MessageSelectorImpl"/>
      //Do v have to provide our own implementation for this bean??
      or

      Code:
      <filter input-channel="input" ref="selector" output-channel="output"/>
      <bean id="selector"
          class="org.springframework.integration.channel.interceptor.MessageSelectingInterceptor">
          <constructor-arg>
              <bean class="org.springframework.integration.xml.selector.BooleanTestXPathMessageSelector">
                  <constructor-arg value="boolean(/order)" />
              </bean>
          </constructor-arg>
      </bean>
      or

      Code:
      <filter input-channel="input" ref="selector" output-channel="output"/>
      <si-xml:xpath-selector id="selector" evaluation-result-type="boolean" >
          <si-xml:xpath-expression expression="/name"/>
      </si-xml:xpath-selector>
      Last edited by ashleyvijay; Dec 16th, 2008, 02:51 AM.

      Comment


      • #4
        Your configuration for the message filter looks fine either one would work obviously the version using the namespace is more readable.

        It sounds like you want to split the xml document before applying the filter. If you pass in whole document to a filter then it will discard or pass on the whole document.

        Code:
        <!--  split into one message per division element -->
        <si-xml:xpath-splitter input-channel="divisionResponseDocs" output-channel="divisionElements">
            <si-xml:xpath-expression expression="//Divsions"/>
        </si-xml:xpath-splitter>
        	
        <!--  discard any messages representing divisions that have not changed -->
        <si:filter input-channel="divisionElements" output-channel="divisionsThatHaveChangedElements" />
        <si-xml:xpath-selector evaluation-result-type="boolean" id="hasChangedSelector">
        	<si-xml:xpath-expression expression="boolean(boolean(./@Change-occured)"/>
        </si-xml:xpath-selector>

        Comment


        • #5
          Filter problem??

          Thanks for all ur effiort to code Jonas. Unfortunately I tried ur code and I get something like below although one or two Divisions's "Change-Occured" value is true. Im relatively new to XPath expressions so I believe ur expression is right. If thats the case could it be a filter problem??

          Code:
          [div:Divisions: null][div:Divisions: null][div:Divisions: null][div:Divisions: null][div:Divisions: null]
          My Code
          Code:
          <!--  split into one message per division element -->
          <si-xml:xpath-splitter input-channel="divisionResponseDocs" output-channel="divisionElements">
              <si-xml:xpath-expression expression="//div:Divisions" ns-prefix="div" ns-uri="http://gid.com/div/schemas"/>
          </si-xml:xpath-splitter>
          	
          <!--  discard any messages representing divisions that have not changed -->
          <filter input-channel="divisionElements" output-channel="divisionsThatHaveChangedElements" ref="hasChangedSelector" />
          <si-xml:xpath-selector evaluation-result-type="boolean" id="hasChangedSelector">
          	<si-xml:xpath-expression expression="boolean(boolean(./@Change-Occured))" ns-prefix="div" ns-uri="http://gid.com/div/schemas" />
          </si-xml:xpath-selector>
          
          <!--  Print those Divisions that are changed to the console -->
          <stream:stdout-channel-adapter id="divisionsThatHaveChangedElements"/>
          Last edited by ashleyvijay; Dec 16th, 2008, 07:03 AM.

          Comment


          • #6
            ./@Change-occured='true'

            Comment


            • #7
              Thanks Jonas again. It Works now!
              Last edited by ashleyvijay; Dec 17th, 2008, 06:41 AM.

              Comment

              Working...
              X