2017-02-15 13 views
0

Мне нужно добавить заголовок из spring-module.xml. Я получаю ниже ответКак добавить новый заголовок из spring-module.xml

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

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

В заголовке мне нужно добавить еще одно поле, как «время: временная метка» эти заголовок следует добавить только из пружинного module.xml. Ожидание заголовков, как показано ниже.

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

ниже моя весна-module.xml файл:

<?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> 

Какие изменения мне нужно сделать, добавить еще один заголовок, как «время» от весенне-module.xml ..?

ответ

1

См. 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> 
+0

Да, спасибо за ваш ответ. Исходя из этого, я могу добавить заголовок. Еще раз спасибо. –