我有这些频道和变压器。
<integration:channel id="channel">
<integration:interceptors>
<integration:wire-tap channel="logChannel"/>
</integration:interceptors>
</integration:channel>
<integration:transformer input-channel="channel"
output-channel="resultChannel"
ref="transformerImpl"
method="transform">
</integration:transformer>
在变换器中,我无法通过@Header访问标题中的自定义属性。但在logChannel中,我记录我的标题,一切正常。我的财产存在。任何想法?
答案 0 :(得分:0)
在框架中,我们有几个类似方法的测试用例:
@Transformer
public String headerTest(String s, @Header("number") Integer num) {
return s + num;
}
@Transformer
public String optionalHeaderTest(String s, @Header(value = "number", required = false) Integer num) {
return s + num;
}
optionalHeaderTest
变换器的测试如下:
@Test
public void optionalHeaderAnnotation() throws Exception {
TestBean testBean = new TestBean();
Method testMethod = testBean.getClass().getMethod("optionalHeaderTest", String.class, Integer.class);
MethodInvokingTransformer transformer = new MethodInvokingTransformer(testBean, testMethod);
Message<String> message = MessageBuilder.withPayload("foo").setHeader("number", 99).build();
Message<?> result = transformer.transform(message);
assertEquals("foo99", result.getPayload());
}
@Test
public void optionalHeaderValueNotProvided() throws Exception {
TestBean testBean = new TestBean();
Method testMethod = testBean.getClass().getMethod("optionalHeaderTest", String.class, Integer.class);
MethodInvokingTransformer transformer = new MethodInvokingTransformer(testBean, testMethod);
Message<String> message = MessageBuilder.withPayload("foo").build();
Message<?> result = transformer.transform(message);
assertEquals("foonull", result.getPayload());
}
您可以查看哪些邮件已添加到transform()
整个Message<?>
对象中吗?这样您就可以访问所有标题。