Java Learing
Java Learing

Reputation: 271

How to add new header from spring-module.xml

I need to add header from spring-module.xml. I am getting below response

headers:    
file_name:  sample.txt
content_type:   text/plain

Payload: { "json":{ "type":"abcd","value":"1234" }}

In the header I need to add another field like "time:timestamp" these header we should add from spring-module.xml only. Expecting headers like below.

headers:    
file_name:  sample.txt
content_type:   text/plain
time:timestamp

below is my spring-module.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
  xmlns:beans="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:int="http://www.springframework.org/schema/integration"
       xmlns:context="http://www.springframework.org/schema/context"
  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
                                 http://www.springframework.org/schema/mvc
                                 http://www.springframework.org/schema/mvc/spring-mvc.xsd
                                 http://www.springframework.org/schema/context
                                 http://www.springframework.org/schema/context/spring-context.xsd">

<channel id="input"/>
  <transformer input-channel="input" output-channel="output">
    <beans:bean class="com.sample.PayloadValidation" >
    </beans:bean>
  </transformer>
<channel id="output"/>

</beans:beans>

What are the changes I need to do add one more header like "time" from the spring-module.xml..?

Upvotes: 1

Views: 633

Answers (1)

Gary Russell
Gary Russell

Reputation: 174769

See Header Enricher.

<int:header-enricher input-channel="in" output-channel="out">
    <int:header name="foo" value="123"/>
    <int:header name="bar" ref="someBean"/>
    <int:header name="baz" expression="@someBean.getHeaderValue(payload)"/>
</int:header-enricher>

Upvotes: 2

Related Questions