INT-3748: BridgeHandler: don't copy headers

JIRA: https://jira.spring.io/browse/INT-3748

- override `shouldCopyRequestHeaders` to return false;
- modify existing tests (not specific to `BridgeHandler`) that rely on the fact that `BridgeHandler` copies headers and creates a new message instance to use a custom test handler with the expected behaviour;

INT-3748 Polishing

- moved test RequestHeaderCopyingMessageHandler
- updated author tags and copyrights
This commit is contained in:
Marius Bogoevici
2015-06-18 12:19:04 -04:00
committed by Artem Bilan
parent f4104c199a
commit ec1154fb93
4 changed files with 28 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 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.
@@ -31,6 +31,7 @@ import org.springframework.messaging.Message;
*
* @author Mark Fisher
* @author Iwein Fuld
* @author Marius Bogoevici
*/
public class BridgeHandler extends AbstractReplyProducingMessageHandler {
@@ -44,4 +45,8 @@ public class BridgeHandler extends AbstractReplyProducingMessageHandler {
return requestMessage;
}
@Override
protected boolean shouldCopyRequestHeaders() {
return false;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2015 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.
@@ -30,7 +30,7 @@ import org.springframework.integration.channel.PublishSubscribeChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.config.ConsumerEndpointFactoryBean;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.handler.BridgeHandler;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.integration.message.MessageBuilderAtConfigTests.MBConfig;
import org.springframework.integration.support.MessageBuilderFactory;
import org.springframework.integration.support.MutableMessageBuilderFactory;
@@ -43,6 +43,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Gary Russell
* @author Marius Bogoevici
*/
@ContextConfiguration(classes=MBConfig.class)
@RunWith(SpringJUnit4ClassRunner.class)
@@ -92,7 +93,7 @@ public class MessageBuilderAtConfigTests {
}
@Bean
public ConsumerEndpointFactoryBean bridge1() throws Exception {
public ConsumerEndpointFactoryBean echo1() throws Exception {
ConsumerEndpointFactoryBean factory = new ConsumerEndpointFactoryBean();
factory.setHandler(handler1());
factory.setInputChannel(in());
@@ -100,14 +101,14 @@ public class MessageBuilderAtConfigTests {
}
@Bean
public BridgeHandler handler1() {
BridgeHandler handler = new BridgeHandler();
public AbstractReplyProducingMessageHandler handler1() {
AbstractReplyProducingMessageHandler handler = new RequestHeaderCopyingEchoHandler();
handler.setOutputChannel(pubSub());
return handler;
}
@Bean
public ConsumerEndpointFactoryBean bridge2() throws Exception {
public ConsumerEndpointFactoryBean echo2() throws Exception {
ConsumerEndpointFactoryBean factory = new ConsumerEndpointFactoryBean();
factory.setHandler(handler2());
factory.setInputChannel(pubSub());
@@ -115,14 +116,14 @@ public class MessageBuilderAtConfigTests {
}
@Bean
public BridgeHandler handler2() {
BridgeHandler handler = new BridgeHandler();
public AbstractReplyProducingMessageHandler handler2() {
AbstractReplyProducingMessageHandler handler = new RequestHeaderCopyingEchoHandler();
handler.setOutputChannel(out());
return handler;
}
@Bean
public ConsumerEndpointFactoryBean bridge3() throws Exception {
public ConsumerEndpointFactoryBean echo3() throws Exception {
ConsumerEndpointFactoryBean factory = new ConsumerEndpointFactoryBean();
factory.setHandler(handler3());
factory.setInputChannel(pubSub());
@@ -130,12 +131,18 @@ public class MessageBuilderAtConfigTests {
}
@Bean
public BridgeHandler handler3() {
BridgeHandler handler = new BridgeHandler();
public AbstractReplyProducingMessageHandler handler3() {
AbstractReplyProducingMessageHandler handler = new RequestHeaderCopyingEchoHandler();
handler.setOutputChannel(out());
return handler;
}
}
private static class RequestHeaderCopyingEchoHandler extends AbstractReplyProducingMessageHandler {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
return requestMessage;
}
}
}

View File

@@ -7,7 +7,9 @@
<int:channel id="in" />
<int:bridge input-channel="in" output-channel="pub" />
<int:service-activator input-channel="in" output-channel="pub">
<bean class="org.springframework.integration.message.MessageBuilderAtConfigTests.RequestHeaderCopyingEchoHandler"/>
</int:service-activator>
<int:publish-subscribe-channel id="pub" />

View File

@@ -19,6 +19,7 @@ package org.springframework.integration.message;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.messaging.Message;
/**