Uploaded image for project: 'Mule'
  1. Mule
  2. MULE-6298

Flow with a splitter followed by a filter, returns original collection if no item passes the filter, instead of null message

    Details

    • Severity:
      S2
    • Defect Source:
      Production Defect
    • Requires Customer-facing Documentation:
      No
    • Story Points:
      0
    • Configuration:
      Hide

      USING SUBFLOWS:

      <?xml version="1.0" encoding="UTF-8"?>
      
      <mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="EE-3.3.0" xsi:schemaLocation="
      http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd 
      http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
      http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd 
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
      http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd ">
          <flow name="filterissueFlow1" doc:name="filterissueFlow1">
              <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
              <set-property propertyName="filterText" value="#[payload.toString()]" doc:name="Property"/>
              <flow-ref name="filterissueFlow2" doc:name="Flow Reference"/>
              <logger message="Payload on primary flow after filtering: #[payload.getClass()] #[payload.toString()]" level="INFO" doc:name="Logger"/>
          </flow>
          <sub-flow name="filterissueFlow2" doc:name="filterissueFlow2">
              <scripting:component doc:name="Groovy">
                  <scripting:script engine="Groovy">
                      <scripting:text><![CDATA[payload = new LinkedList();
      payload.add("/a");
      payload.add("/b");
      payload.add("/c");
      return payload;]]></scripting:text>
                  </scripting:script>
              </scripting:component>
              <collection-splitter doc:name="Collection Splitter"/>
              <logger message="Before aplying filter [#[message.outboundProperties['filterText']]] to: [#[payload.getClass()] #[payload.toString()]]" level="INFO" doc:name="Logger"/>
              <expression-filter expression="#[payload == message.outboundProperties['filterText']]" doc:name="Expression"/>
              <logger message="Element passed filter: [#[payload.getClass()] #[payload.toString()]]" level="INFO" doc:name="Logger"/>
          </sub-flow>
      </mule>
      


      USING VMs:

      <?xml version="1.0" encoding="UTF-8"?>
      
      <mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="EE-3.3.0" xsi:schemaLocation="
      http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd 
      http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
      http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd 
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
      http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd ">
          <flow name="filterissueFlow21" doc:name="filterissueFlow21">
              <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP"/>
              <set-property propertyName="filterText" value="#[payload.toString()]" doc:name="Property"/>
              <vm:outbound-endpoint exchange-pattern="request-response" path="in" doc:name="VM"/>
              <logger message="Payload on primary flow after filtering: #[payload.getClass()] #[payload.toString()]" level="INFO" doc:name="Logger"/>
          </flow>
          <flow name="filterissueFlow22" doc:name="filterissueFlow22">
              <vm:inbound-endpoint exchange-pattern="request-response" path="in" doc:name="VM"/>
              <scripting:component doc:name="Groovy">
                  <scripting:script engine="Groovy">
                      <scripting:text><![CDATA[payload = new LinkedList();
      payload.add("/a");
      payload.add("/b");
      payload.add("/c");
      return payload;]]></scripting:text>
                  </scripting:script>
              </scripting:component>
              <collection-splitter doc:name="Collection Splitter"/>
              <logger message="Before aplying filter [#[message.inboundProperties['filterText']]] to: [#[payload.getClass()] #[payload.toString()]]" level="INFO" doc:name="Logger"/>
              <expression-filter expression="#[payload == message.inboundProperties['filterText']]" doc:name="Expression"/>
              <logger message="Element passed filter: [#[payload.getClass()] #[payload.toString()]]" level="INFO" doc:name="Logger"/>
          </flow>
      </mule>
      
      Show
      USING SUBFLOWS: <?xml version= "1.0" encoding= "UTF-8" ?> <mule xmlns= "http: //www.mulesoft.org/schema/mule/core" xmlns:vm= "http://www.mulesoft.org/schema/mule/vm" xmlns:http= "http://www.mulesoft.org/schema/mule/http" xmlns:scripting= "http://www.mulesoft.org/schema/mule/scripting" xmlns:doc= "http://www.mulesoft.org/schema/mule/documentation" xmlns:spring= "http://www.springframework.org/schema/beans" xmlns:core= "http://www.mulesoft.org/schema/mule/core" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" version= "EE-3.3.0" xsi:schemaLocation=" http: //www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd http: //www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http: //www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd http: //www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http: //www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd "> <flow name= "filterissueFlow1" doc:name= "filterissueFlow1" > <http:inbound-endpoint exchange-pattern= "request-response" host= "localhost" port= "8081" doc:name= "HTTP" /> <set-property propertyName= "filterText" value= "#[payload.toString()]" doc:name= "Property" /> <flow-ref name= "filterissueFlow2" doc:name= "Flow Reference" /> <logger message= "Payload on primary flow after filtering: #[payload.getClass()] #[payload.toString()]" level= "INFO" doc:name= "Logger" /> </flow> <sub-flow name= "filterissueFlow2" doc:name= "filterissueFlow2" > <scripting:component doc:name= "Groovy" > <scripting:script engine= "Groovy" > <scripting:text><![CDATA[payload = new LinkedList(); payload.add( "/a" ); payload.add( "/b" ); payload.add( "/c" ); return payload;]]></scripting:text> </scripting:script> </scripting:component> <collection-splitter doc:name= "Collection Splitter" /> <logger message= "Before aplying filter [#[message.outboundProperties[ 'filterText' ]]] to: [#[payload.getClass()] #[payload.toString()]]" level= "INFO" doc:name= "Logger" /> <expression-filter expression= "#[payload == message.outboundProperties[ 'filterText' ]]" doc:name= "Expression" /> <logger message= "Element passed filter: [#[payload.getClass()] #[payload.toString()]]" level= "INFO" doc:name= "Logger" /> </sub-flow> </mule> – USING VMs: <?xml version= "1.0" encoding= "UTF-8" ?> <mule xmlns= "http: //www.mulesoft.org/schema/mule/core" xmlns:vm= "http://www.mulesoft.org/schema/mule/vm" xmlns:http= "http://www.mulesoft.org/schema/mule/http" xmlns:scripting= "http://www.mulesoft.org/schema/mule/scripting" xmlns:doc= "http://www.mulesoft.org/schema/mule/documentation" xmlns:spring= "http://www.springframework.org/schema/beans" xmlns:core= "http://www.mulesoft.org/schema/mule/core" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" version= "EE-3.3.0" xsi:schemaLocation=" http: //www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd http: //www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http: //www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd http: //www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http: //www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd "> <flow name= "filterissueFlow21" doc:name= "filterissueFlow21" > <http:inbound-endpoint exchange-pattern= "request-response" host= "localhost" port= "8082" doc:name= "HTTP" /> <set-property propertyName= "filterText" value= "#[payload.toString()]" doc:name= "Property" /> <vm:outbound-endpoint exchange-pattern= "request-response" path= "in" doc:name= "VM" /> <logger message= "Payload on primary flow after filtering: #[payload.getClass()] #[payload.toString()]" level= "INFO" doc:name= "Logger" /> </flow> <flow name= "filterissueFlow22" doc:name= "filterissueFlow22" > <vm:inbound-endpoint exchange-pattern= "request-response" path= "in" doc:name= "VM" /> <scripting:component doc:name= "Groovy" > <scripting:script engine= "Groovy" > <scripting:text><![CDATA[payload = new LinkedList(); payload.add( "/a" ); payload.add( "/b" ); payload.add( "/c" ); return payload;]]></scripting:text> </scripting:script> </scripting:component> <collection-splitter doc:name= "Collection Splitter" /> <logger message= "Before aplying filter [#[message.inboundProperties[ 'filterText' ]]] to: [#[payload.getClass()] #[payload.toString()]]" level= "INFO" doc:name= "Logger" /> <expression-filter expression= "#[payload == message.inboundProperties[ 'filterText' ]]" doc:name= "Expression" /> <logger message= "Element passed filter: [#[payload.getClass()] #[payload.toString()]]" level= "INFO" doc:name= "Logger" /> </flow> </mule>
    • Log Output:
      Hide
      {code}
      **********************************************************************
      * Application: filterissue *
      * OS encoding: MacRoman, Mule encoding: UTF-8 *
      * *
      * Agents Running: *
      * Clustering Agent *
      * JMX Agent *
      **********************************************************************
      INFO 2012-06-15 17:12:11,977 [main] org.mule.module.launcher.DeploymentService:
      ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      + Started app 'filterissue' +
      ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      INFO 2012-06-15 17:12:16,872 [[filterissue].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: Before aplying filter [/a] to: [class java.lang.String /a]
      INFO 2012-06-15 17:12:16,873 [[filterissue].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: Element passed filter: [class java.lang.String /a]
      INFO 2012-06-15 17:12:16,876 [[filterissue].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: Before aplying filter [/a] to: [class java.lang.String /b]
      INFO 2012-06-15 17:12:16,879 [[filterissue].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: Before aplying filter [/a] to: [class java.lang.String /c]
      INFO 2012-06-15 17:12:16,881 [[filterissue].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: Payload on primary flow after filtering: class java.lang.String /a
      INFO 2012-06-15 17:12:19,431 [[filterissue].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: Before aplying filter [/x] to: [class java.lang.String /a]
      INFO 2012-06-15 17:12:19,434 [[filterissue].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: Before aplying filter [/x] to: [class java.lang.String /b]
      INFO 2012-06-15 17:12:19,436 [[filterissue].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: Before aplying filter [/x] to: [class java.lang.String /c]
      INFO 2012-06-15 17:12:19,437 [[filterissue].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: Payload on primary flow after filtering: class java.util.LinkedList [/a, /b, /c]
      {code}
      Show
      {code} ********************************************************************** * Application: filterissue * * OS encoding: MacRoman, Mule encoding: UTF-8 * * * * Agents Running: * * Clustering Agent * * JMX Agent * ********************************************************************** INFO 2012-06-15 17:12:11,977 [main] org.mule.module.launcher.DeploymentService: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + Started app 'filterissue' + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ INFO 2012-06-15 17:12:16,872 [[filterissue].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: Before aplying filter [/a] to: [class java.lang.String /a] INFO 2012-06-15 17:12:16,873 [[filterissue].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: Element passed filter: [class java.lang.String /a] INFO 2012-06-15 17:12:16,876 [[filterissue].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: Before aplying filter [/a] to: [class java.lang.String /b] INFO 2012-06-15 17:12:16,879 [[filterissue].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: Before aplying filter [/a] to: [class java.lang.String /c] INFO 2012-06-15 17:12:16,881 [[filterissue].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: Payload on primary flow after filtering: class java.lang.String /a INFO 2012-06-15 17:12:19,431 [[filterissue].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: Before aplying filter [/x] to: [class java.lang.String /a] INFO 2012-06-15 17:12:19,434 [[filterissue].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: Before aplying filter [/x] to: [class java.lang.String /b] INFO 2012-06-15 17:12:19,436 [[filterissue].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: Before aplying filter [/x] to: [class java.lang.String /c] INFO 2012-06-15 17:12:19,437 [[filterissue].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: Payload on primary flow after filtering: class java.util.LinkedList [/a, /b, /c] {code}
    • Sprint:
      ESB McKinley 2

      Description

      The example flow fabricates a linked list with elements

      { "/a", "/b", "/c" } and applies a splitter, which evaluates to true if the element matches the path of the http request.

      The incorrect behavior is that if no element matches the filter, the flow returns the original collection, when the expected behaviour is to return NullPayload, since no element passed the filer.

      Steps to reproduce:
      1. Invoke http://localhost:8081/a
      2. Observe reply is "/a", which is correct, since "/a" is the only element that matches the filter
      3. Invoke http://localhost:8081/x
      4. Observe reply is LinkedList { "/a", "/b", "/c" }

      , which is incorrect, since NO element matches the filter

      Two examples attached: one using sub-flow and the other using vm endpoints.

        Attachments

        1. apitest.xml
          3 kB
        2. filterissue.xml
          2 kB
        3. filterissue2.xml
          3 kB

          Activity

            People

            • Assignee:
              rodrigo.merino Rodrigo Merino
              Reporter:
              jesus.deoliveira Jesus De Oliveira
            • Votes:
              2 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: