title: Spring Integration DSL Custom Error Channel Not Work
body: <p>I use DSL implementation of Spring Integration.
  I have code below and I can not use my custom error flow. When authenticate method throws Runtime Exception, the errorChannel starts to process. I enrich header to use my custom error flow, but not use.</p>
  
  <pre><code>// In Class - 1
   @Bean
      public MarshallingWebServiceInboundGateway marshallingWebServiceInboundGateway(BeanFactoryChannelResolver channelResolver, Jaxb2Marshaller marshaller) {
  
          MarshallingWebServiceInboundGateway wsInboundGateway = new MarshallingWebServiceInboundGateway();
          wsInboundGateway.setRequestChannel(channelResolver.resolveDestination("incomingRequest.input"));
          wsInboundGateway.setReplyChannel(channelResolver.resolveDestination("outgoingResponse.input"));
          wsInboundGateway.setErrorChannel(channelResolver.resolveDestination("errorChannel"));
          wsInboundGateway.setMarshaller(marshaller);
          wsInboundGateway.setUnmarshaller(marshaller);
          return wsInboundGateway;
      }
  
  
  // In Class - 2
  @Bean
      public IntegrationFlow incomingRequest() {
          return f -&gt; f.&lt;Object, Class&lt;?&gt;&gt;route(t -&gt; t.getClass(),
                  mapping -&gt; mapping.subFlowMapping(payloadType1(),
                          sf -&gt; sf.gateway("type1.input", ConsumerEndpointSpec::transactional))
                          .subFlowMapping(payloadType2(),
                                  sf -&gt; sf.gateway("type2.input", ConsumerEndpointSpec::transactional)),
                          conf -&gt; conf.id("router:Incoming request router"));
      }
  
  // In Class - 3
      @Bean
      public IntegrationFlow type1() {
          IntegrationFlow integrationFlow = f -&gt; f
                  .enrichHeaders(h -&gt; h.header(MessageHeaders.ERROR_CHANNEL, "error222", true))
                  .&lt;Type1&gt;handle((p, h) -&gt; authentication.authenticate(p),
                          conf -&gt; conf.id("service-activator:Authenticate"))
                  .transform(transformer::transformType1MsgToDataX,
                          conf -&gt; conf.id("transform:Unmarshall type1 Message"))
                  .enrichHeaders(h -&gt; h.headerExpression(TypeDataIntegrationMessageHeaderAccessor.MESSAGE_ID, "payload.id")
                          .headerExpression(TypeDataIntegrationMessageHeaderAccessor.MESSAGE_TYPE, "payload.messageType"))
                  .handle((GenericHandler&lt;DataX&gt;) repository::successResponseMessage,
                          conf -&gt; conf.id("service-activator:return success"))
                  .channel("outgoingResponse.input")
                  ;
  
          return integrationFlow;
      }
  
  // In Class - 3
  @Bean
      public IntegrationFlow error222Flow() {
  
          return IntegrationFlows.from("error222").handle("repository", "failureResponseMessage").get()
  
                  ;
  
      }
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>After Artem's answers, my code like below. But still, I can't access header parameter in the error flow. I get error - "No channel resolved by router 'router:error response prepare' "</p>
  
  <pre><code> // In Class - 1
   @Bean
      public MarshallingWebServiceInboundGateway marshallingWebServiceInboundGateway(BeanFactoryChannelResolver channelResolver, Jaxb2Marshaller marshaller) {
  
          MarshallingWebServiceInboundGateway wsInboundGateway = new MarshallingWebServiceInboundGateway();
          wsInboundGateway.setRequestChannel(channelResolver.resolveDestination("incomingRequest.input"));
          wsInboundGateway.setReplyChannel(channelResolver.resolveDestination("outgoingResponse.input"));
          wsInboundGateway.setErrorChannel(channelResolver.resolveDestination("errorResponse.input"));
          wsInboundGateway.setMarshaller(marshaller);
          wsInboundGateway.setUnmarshaller(marshaller);
          return wsInboundGateway;
      }
  
  
  // In Class - 2
  @Bean
      public IntegrationFlow incomingRequest() {
          return f -&gt; f.&lt;Object, Class&lt;?&gt;&gt;route(t -&gt; t.getClass(),
                  mapping -&gt; mapping.subFlowMapping(payloadType1(),
                          sf -&gt; sf.gateway("type1.input", ConsumerEndpointSpec::transactional))
                          .subFlowMapping(payloadType2(),
                                  sf -&gt; sf.gateway("type2.input", ConsumerEndpointSpec::transactional)),
                          conf -&gt; conf.id("router:Incoming request router"));
      }
  
  // In Class - 2
  @Bean 
  public IntegrationFlow errorResponse(){ 
      return f -&gt; f.&lt;MessageHandlingException, Object&gt;route(t -&gt; t.getFailedMessage().getHeaders().get("ABCDEF"), 
                          mapping -&gt; mapping.subFlowMapping("ABCDEF", 
                                  sf -&gt; sf.gateway("customError.input", ConsumerEndpointSpec::transactional)), 
                                  conf -&gt; conf.id("router:error response prepare"));
  }
  
  // In Class - 3
      @Bean
      public IntegrationFlow type1() {
          IntegrationFlow integrationFlow = f -&gt; f
                  .enrichHeaders(h -&gt; h.header("ABCDEF", "ABCDEF", true)) 
                  .&lt;Type1&gt;handle((p, h) -&gt; authentication.authenticate(p),
                          conf -&gt; conf.id("service-activator:Authenticate"))
                  .transform(transformer::transformType1MsgToDataX,
                          conf -&gt; conf.id("transform:Unmarshall type1 Message"))
                  .enrichHeaders(h -&gt; h.headerExpression(TypeDataIntegrationMessageHeaderAccessor.MESSAGE_ID, "payload.id")
                          .headerExpression(TypeDataIntegrationMessageHeaderAccessor.MESSAGE_TYPE, "payload.messageType"))
                  .handle((GenericHandler&lt;DataX&gt;) repository::successResponseMessage,
                          conf -&gt; conf.id("service-activator:return success"))
                  .channel("outgoingResponse.input")
                  ;
  
          return integrationFlow;
      }
  
  // In Class - 3
  @Bean
      public IntegrationFlow customError(){
          return f -&gt; f.handle((GenericHandler&lt;MessageHandlingException&gt;)eventRepository::failureResponseMessage,
                                  conf -&gt; conf.id("service-activator:return failure"));
      }
  </code></pre>
  
  <p><strong>EDIT - 2:</strong></p>
  
  <p>I try Artem's test code, it works in this scenario. If I convert the type1 flow to the subflow mapping as below (I do it, because I'm doubtful my subflow code block), the error flow can't print ABCDEF parameter value.
  After that, I add another header(XYZTWR) to the subflow mapping, but it can't be printed too.</p>
  
  <pre><code>@Bean
  public IntegrationFlow type1() {
      return f -&gt; f.&lt;String, String&gt;route(t -&gt; t.toString(), mapping -&gt; mapping.subFlowMapping("foo",
              sf -&gt; sf.gateway("fooFlow.input", ConsumerEndpointSpec::transactional).enrichHeaders(h -&gt; h.header("XYZTRW", "XYZTRW", true))));
  }
  
  @Bean
  public IntegrationFlow fooFlow() {
      return f -&gt; f.enrichHeaders(h -&gt; h.header("ABCDEF", "ABCDEF", true))
              .handle((p, h) -&gt; {
                  throw new RuntimeException("intentional");
              });
  }
  </code></pre>
  
  <p>My S.OUT is :</p>
  
  <pre><code>GenericMessage [payload=foo, headers={history=testGateway,type1.input, id=1fad7a65-4abe-c41d-0b22-36839a103269, timestamp=1503029553071}]
  </code></pre>