INT-712 Headers defined by 'header-enricher' elements are now configured as sub-elements rather than attributes. This applies to the "core" as well as the JMS and Mail namespace support.
This commit is contained in:
@@ -28,8 +28,9 @@
|
||||
</chain>
|
||||
|
||||
<chain input-channel="headerEnricherInput">
|
||||
<header-enricher reply-channel="replyOutput"
|
||||
correlation-id="ABC">
|
||||
<header-enricher>
|
||||
<reply-channel ref="replyOutput"/>
|
||||
<correlation-id value="ABC"/>
|
||||
<header name="testValue" value="XYZ" />
|
||||
<header name="testRef" ref="testHeaderValue" />
|
||||
</header-enricher>
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
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">
|
||||
|
||||
<header-enricher input-channel="replyChannelInput" output-channel="echoInput">
|
||||
<reply-channel ref="testReplyChannel"/>
|
||||
</header-enricher>
|
||||
|
||||
<transformer input-channel="echoInput" expression="payload.toUpperCase()"/>
|
||||
|
||||
<channel id="testReplyChannel">
|
||||
<queue/>
|
||||
</channel>
|
||||
|
||||
<channel id="errorChannelInput">
|
||||
<queue/>
|
||||
</channel>
|
||||
|
||||
<header-enricher input-channel="errorChannelInput" output-channel="failInput">
|
||||
<poller max-messages-per-poll="1">
|
||||
<interval-trigger interval="3000"/>
|
||||
</poller>
|
||||
<error-channel ref="testErrorChannel"/>
|
||||
</header-enricher>
|
||||
|
||||
<transformer input-channel="failInput" expression="payload.noSuchProperty"/>
|
||||
|
||||
<channel id="testErrorChannel">
|
||||
<queue/>
|
||||
</channel>
|
||||
|
||||
<header-enricher input-channel="correlationIdValueInput">
|
||||
<correlation-id value="ABC"/>
|
||||
</header-enricher>
|
||||
|
||||
<header-enricher input-channel="correlationIdRefInput">
|
||||
<correlation-id ref="testCorrelationId"/>
|
||||
</header-enricher>
|
||||
|
||||
<beans:bean id="testCorrelationId" class="java.lang.Integer">
|
||||
<beans:constructor-arg value="123"/>
|
||||
</beans:bean>
|
||||
|
||||
<header-enricher input-channel="expirationDateValueInput">
|
||||
<expiration-date value="1111"/>
|
||||
</header-enricher>
|
||||
|
||||
<header-enricher input-channel="expirationDateRefInput">
|
||||
<expiration-date ref="testExpirationDate"/>
|
||||
</header-enricher>
|
||||
|
||||
<beans:bean id="testExpirationDate" class="java.lang.Long">
|
||||
<beans:constructor-arg value="9999"/>
|
||||
</beans:bean>
|
||||
|
||||
<header-enricher input-channel="priorityInput">
|
||||
<priority value="HIGH"/>
|
||||
</header-enricher>
|
||||
|
||||
</beans:beans>
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessagePriority;
|
||||
import org.springframework.integration.gateway.SimpleMessagingGateway;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.transformer.MessageTransformationException;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class HeaderEnricherTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void replyChannel() {
|
||||
PollableChannel replyChannel = context.getBean("testReplyChannel", PollableChannel.class);
|
||||
MessageChannel inputChannel = context.getBean("replyChannelInput", MessageChannel.class);
|
||||
inputChannel.send(new StringMessage("test"));
|
||||
Message<?> result = replyChannel.receive(0);
|
||||
assertNotNull(result);
|
||||
assertEquals("TEST", result.getPayload());
|
||||
assertEquals(replyChannel, result.getHeaders().getReplyChannel());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void errorChannel() {
|
||||
PollableChannel errorChannel = context.getBean("testErrorChannel", PollableChannel.class);
|
||||
MessageChannel inputChannel = context.getBean("errorChannelInput", MessageChannel.class);
|
||||
inputChannel.send(new StringMessage("test"));
|
||||
Message<?> errorMessage = errorChannel.receive(1000);
|
||||
assertNotNull(errorMessage);
|
||||
Object errorPayload = errorMessage.getPayload();
|
||||
assertEquals(MessageTransformationException.class, errorPayload.getClass());
|
||||
Message<?> failedMessage = ((MessageTransformationException) errorPayload).getFailedMessage();
|
||||
assertEquals("test", failedMessage.getPayload());
|
||||
assertEquals(errorChannel, failedMessage.getHeaders().getErrorChannel());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correlationIdValue() {
|
||||
SimpleMessagingGateway gateway = new SimpleMessagingGateway();
|
||||
gateway.setRequestChannel(context.getBean("correlationIdValueInput", MessageChannel.class));
|
||||
Message<?> result = gateway.sendAndReceiveMessage("test");
|
||||
assertNotNull(result);
|
||||
assertEquals("ABC", result.getHeaders().getCorrelationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correlationIdRef() {
|
||||
SimpleMessagingGateway gateway = new SimpleMessagingGateway();
|
||||
gateway.setRequestChannel(context.getBean("correlationIdRefInput", MessageChannel.class));
|
||||
Message<?> result = gateway.sendAndReceiveMessage("test");
|
||||
assertNotNull(result);
|
||||
assertEquals(new Integer(123), result.getHeaders().getCorrelationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expirationDateValue() {
|
||||
SimpleMessagingGateway gateway = new SimpleMessagingGateway();
|
||||
gateway.setRequestChannel(context.getBean("expirationDateValueInput", MessageChannel.class));
|
||||
Message<?> result = gateway.sendAndReceiveMessage("test");
|
||||
assertNotNull(result);
|
||||
assertEquals(new Long(1111), result.getHeaders().getExpirationDate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expirationDateRef() {
|
||||
SimpleMessagingGateway gateway = new SimpleMessagingGateway();
|
||||
gateway.setRequestChannel(context.getBean("expirationDateRefInput", MessageChannel.class));
|
||||
Message<?> result = gateway.sendAndReceiveMessage("test");
|
||||
assertNotNull(result);
|
||||
assertEquals(new Long(9999), result.getHeaders().getExpirationDate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void priority() {
|
||||
SimpleMessagingGateway gateway = new SimpleMessagingGateway();
|
||||
gateway.setRequestChannel(context.getBean("priorityInput", MessageChannel.class));
|
||||
Message<?> result = gateway.sendAndReceiveMessage("test");
|
||||
assertNotNull(result);
|
||||
assertEquals(MessagePriority.HIGH, result.getHeaders().getPriority());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,7 +11,9 @@
|
||||
|
||||
<bridge id="endpoint5" input-channel="cannel" order="5"/>
|
||||
|
||||
<header-enricher id="endpoint11" input-channel="channel" correlation-id="x" order="11"/>
|
||||
<header-enricher id="endpoint11" input-channel="channel" order="11">
|
||||
<header name="foo" value="bar"/>
|
||||
</header-enricher>
|
||||
|
||||
<splitter id="endpoint1" ref="bean" method="handle" input-channel="channel" order="1"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user