title: Spring Integration nested chains with filters
body: <p>I have a sequence of processing steps that I'm trying to process, but my tests are not always passing, not always failing...</p>
  
  <p>I've produced a simple example which seems to exhibit what I'm seeing in my real tests.</p>
  
  <pre><code>import static org.junit.Assert.assertEquals;
  import static org.junit.Assert.assertNotEquals;
  
  import java.util.Arrays;
  import java.util.List;
  
  import org.springframework.integration.test.support.AbstractRequestResponseScenarioTests;
  import org.springframework.integration.test.support.PayloadValidator;
  import org.springframework.integration.test.support.RequestResponseScenario;
  import org.springframework.test.context.ContextConfiguration;
  
  @ContextConfiguration
  public class FlowTest extends AbstractRequestResponseScenarioTests {
  
      @Override
      protected List&lt;RequestResponseScenario&gt; defineRequestResponseScenarios() {
          return Arrays.asList(
                  new RequestResponseScenario("inputChannel", "outputChannel")
                      .setPayload("a")
                      .setResponseValidator(new PayloadValidator&lt;String&gt;() {
                          @Override
                          protected void validateResponse(String response) {
                              assertEquals("AA", response);
                          }
                      }),
                  new RequestResponseScenario("inputChannel", "outputChannel")
                      .setPayload("b")
                      .setResponseValidator(new PayloadValidator&lt;String&gt;() {
                          @Override
                          protected void validateResponse(String response) {
                              assertNotEquals("AA", response);
                          }
                      })
                  );
      }
  }
  </code></pre>
  
  <p>And the XML</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:int="http://www.springframework.org/schema/integration"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd"&gt;
  
      &lt;int:channel id="inputChannel"/&gt;
      &lt;int:channel id="outputChannel"/&gt;
      &lt;int:channel id="errorChannel"/&gt;
  
      &lt;int:chain input-channel="inputChannel" output-channel="outputChannel"&gt;
          &lt;int:gateway request-channel="processOne"/&gt;
          &lt;int:gateway request-channel="processTwo"/&gt;
      &lt;/int:chain&gt;
  
      &lt;int:chain input-channel="processOne"&gt;
          &lt;int:service-activator expression="payload + payload"/&gt;
          &lt;int:filter expression="payload == 'aa'" discard-channel="errorChannel"/&gt;
      &lt;/int:chain&gt;
  
      &lt;int:chain input-channel="processTwo"&gt;
          &lt;int:service-activator expression="payload.toUpperCase()"/&gt;
      &lt;/int:chain&gt;
  
      &lt;int:transformer input-channel="errorChannel" output-channel="outputChannel" expression="payload + payload"/&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>It seems that the message flow is happening and a message always appears on <code>responseChannel</code>, and is processed by the PayloadValidator.</p>
  
  <p>However, if a message happens to pass through the error handling detour then the application context doesn't shut down, it just kind of sits there stalled.</p>
  
  <p>Is this sort of pattern, using a filter to pull messages out of the chain and onto an alternate path, supported?</p>
  
  <p>I'm guessing the chain is waiting on a reply message, and some correlation is getting lost en-route.</p>
  
  <p>I am using a rather ancient version of Spring Integration :-(</p>
  
  <h3>Update</h3>
  
  <p>It does seem like this is an effect of using the nested chains. If I move the filter into the top-level chain, things work as expected. Which kind of makes sense, given it'll be the gateway waiting on a response.</p>
  
  <p>I'm using the nested chains because I need the separate processes to individually deal with retry logic.</p>
  
  <p>Perhaps I simply need to forego the syntactic sugar that is chains?</p>