title: How do I call a validator method to validate the input that's coming through gateway before passing to the parallel flows in scatterer?
body: <p>I'm using Spring-integration in my project and the pattern used is scatter-gather. Here three parallel processes are being carried out. Before any of the parallel process starts I want to call a method which returns nothing but that will validate the Request body that is being sent via gateway to the main flow.</p>
  <p>Below is the code - -</p>
  <p>//Config file</p>
  <pre><code>@Configuration
      public class IntegrationConfiguration {
        @Autowired LionsServiceImpl lionsService;
      
        long dbId = new SequenceGenerator().nextId();
    //   Main flow
    @Bean
    public IntegrationFlow flow() {
      return flow -&gt;
          flow.split()
              .log()
              .channel(c -&gt; c.executor(Executors.newCachedThreadPool()))
              .convert(LoanProvisionRequest.class)
              .scatterGather(
                  scatterer -&gt;
                      scatterer
                          .applySequence(true)
                          .recipientFlow(flow1())
                          .recipientFlow(flow2())
                          .recipientFlow(flow3()),
                  gatherer -&gt; gatherer.releaseLockBeforeSend(true))
              .log()
              .aggregate(a -&gt; a.outputProcessor(MessageGroup::getMessages))
              .channel(&quot;output-flow&quot;);
    }
    //   flow1
    @Bean
    public IntegrationFlow flow1() {
      return integrationFlowDefination -&gt;
          integrationFlowDefination
              .channel(c -&gt; c.executor(Executors.newCachedThreadPool()))
              .handle(
                  message -&gt; {
                    try {
                      lionService.saveLionRequest(
                          (LionRequest) message.getPayload(), String.valueOf(dbId));
                    } catch (JsonProcessingException e) {
                      throw new RuntimeException(e);
                    }
                  });
    }
  
    //   flow2
    @Bean
    public IntegrationFlow flow2() {
      return integrationFlowDefination -&gt;
          integrationFlowDefination
              .channel(c -&gt; c.executor(Executors.newCachedThreadPool()))
              .handle(
                  message -&gt;
                      lionService.getData(
                          (LionRequest) message.getPayload(), SourceSystem.PROVISION))
              .log();
    }
  
    //  flow3
    @Bean
    public IntegrationFlow flow3() {
      return integrationFlowDefination -&gt;
          integrationFlowDefination
              .channel(c -&gt; c.executor(Executors.newCachedThreadPool()))
              .handle(
                  message -&gt;
                      lionService.prepareCDRequest(
                          (LionRequest) message));
    }
  
    @Bean
    public MessageChannel replyChannel() {
      return MessageChannels.executor(&quot;output-flow&quot;, outputExecutor()).get();
    }
  
    @Bean
    public ThreadPoolTaskExecutor outputExecutor() {
      ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
      pool.setCorePoolSize(4);
      pool.setMaxPoolSize(4);
      return pool;
    }
  }  
  </code></pre>
  <p>Here before passing LionRequest to the parallel flows in the scatter block I want to call a method probably just before/after calling split() to validate that request and if the request is not as per my standard then my method will throw exception and the main flow also should stop there. Where and How should I call that method. That method returns nothing and accept LionRequest as input parameter.</p>
  <p>Gateway</p>
  <pre><code> @MessagingGateway
      public interface LionGateway {
      
        @Gateway(requestChannel = &quot;flow.input&quot;, replyChannel = &quot;output-flow&quot;)
        List&lt;?&gt; echo(LionRequest lionRequest);
      }
  </code></pre>