title: How and where to invoke HeaderValueRouter and HeaderEnricher for jms or activemq with spring-integration
body: <p>In my project ,we use <strong>spring-integration</strong> to implement the queue. The configuration for Header-Value-Router is in the xml as below:</p>
  
  <pre><code>&lt;header-value-router input-channel="jmsUVMasterMessageChannel"
      header-name="METADATA_TYPE" default-output-channel="nullChannel"
      resolution-required="false"&gt;
      &lt;mapping value="ASSEMBLY" channel="downloadImageToS3Channel" /&gt;
      &lt;mapping value="THIRDPARTY" channel="invokeUVMasterAPIChannel" /&gt;
  &lt;/header-value-router&gt;
  
  &lt;header-enricher input-channel="JuiceVendorMessageChannel"
      output-channel="JuiceHeaderEnricherChannel"&gt;
      &lt;header name="sourceName" value="JUICE" /&gt;
  &lt;/header-enricher&gt;
  </code></pre>
  
  <p>And here is the gateway config:</p>
  
  <p>I wanna know how to implement this config in java code? I searched google and found following code:</p>
  
  <pre><code>@Bean
  public HeaderValueRouter headerRouter(String gatewayPrefix) {
    HeaderValueRouter router = new HeaderValueRouter("METADATA_TYPE");
    router.setChannelMapping("ASSEMBLY", "downloadImageToS3Channel");
    router.setChannelMapping("THIRDPARTY", "invokeUVMasterAPIChannel");
    router.setDefaultOutputChannel(new NullChannel());
    router.setResolutionRequired(false);
    return router;
  }
  
  @Bean
  @Transformer(inputChannel="sdiVenderMessageChannel", outputChannel="sdiHeaderEnricherChannel")
  public HeaderEnricher enrichHeaders() {
      Map&lt;String, HeaderValueMessageProcessor&lt;?&gt;&gt; headersToAdd = new HashMap&lt;String, HeaderValueMessageProcessor&lt;?&gt;&gt;();
      // TODO 
      //headersToAdd.put("sourceName",new StaticHeaderValueMessageProcessor&lt;String&gt;("SDI"));
      headersToAdd.put("sourceName", null);
      HeaderEnricher enricher = new HeaderEnricher(headersToAdd);
      if(logger.isDebugEnabled()){
          logger.debug("HeaderEnricher bean initial!");
      }
      return enricher;
  }
  </code></pre>
  
  <p>But here are my questions:</p>
  
  <p>1) how to config the 'input-channel' in java config?</p>
  
  <p>2) Where should I invoke this function? When I start the application , the code doesn't run into this function. I know the headerValueRouter is used to dispatcher the message from input-channel to the output-channel, but what's the exact place that I can invoke this router? In the ConnectionFactory or ListenerContainer? </p>
  
  <p>And here is the gateway I defined: </p>
  
  <pre><code>public void registerDynamicInboundGateway(DefaultListableBeanFactory beanFactory) {
      this.beanFactory = beanFactory;
  
      BeanDefinitionBuilder builder = BeanDefinitionBuilder
              .genericBeanDefinition("org.springframework.integration.jms.JmsMessageDrivenEndpoint");
      String jndiFactoryName = this.registerJndiObjectFactoryBean(gatewayPrefix, jmsQueueValue);
      this.destination = jndiFactoryName;
      String containerBeanName = this.registerMessageListenerContainer();
      String listenerBeanName = this.registerMessageListener();
      builder.addConstructorArgReference(containerBeanName);
      builder.addConstructorArgReference(listenerBeanName);
      setValueIfAttributeDefined(builder, autoStartup, "auto-startup");
  
      String beanName = null;
      if(gatewayPrefix.equals(HCC_GATEWAY_PREFIX)){
          beanName = gatewayPrefix + DynamicInboundGateway.HCC_GATEWAY_SUFIX;
      } else if (gatewayPrefix.equals(UVMASTER_GATEWAY_PREFIX)) {
          beanName = gatewayPrefix + DynamicInboundGateway.UVMASTER_GATEWAY_PREFIX;
      } else {
          beanName = gatewayPrefix + DynamicInboundGateway.GATEWAY_SUFIX;
      }
  
      this.beanFactory.registerBeanDefinition(
              beanName, builder.getBeanDefinition());
  }
  </code></pre>
  
  <p>I felt confused and didn't found any sample code for this.
  Thanks a lot!</p>
  
  <p>When I define the HeaderEnricher according to the sample code in the spring-integration website like below:</p>
  
  <pre><code>@Bean
  @Transformer(inputChannel="sdiVenderMessageChannel", outputChannel="sdiHeaderEnricherChannel")
  public HeaderEnricher enrichHeaders() {
      Map&lt;String, HeaderValueMessageProcessor&lt;?&gt;&gt; headersToAdd = new HashMap&lt;String, HeaderValueMessageProcessor&lt;?&gt;&gt;();
      // TODO 
      headersToAdd.put("sourceName",new StaticHeaderValueMessageProcessor&lt;String&gt;("SDI"));
      //headersToAdd.put("sourceName", null);
      HeaderEnricher enricher = new HeaderEnricher(headersToAdd);
      if(logger.isDebugEnabled()){
          logger.debug("HeaderEnricher bean initial!");
      }
      return enricher;
  }
  </code></pre>
  
  <p>And this occured some error:</p>
  
  <pre><code>StaticHeaderValueMessageProcessor cannot be resolved to a type
  </code></pre>
  
  <p>But I've import all the required packages with maven. I can not figure out why.</p>