INT-1216, INT-1257 removed tangle between 'history' and 'context' packages. The MessageHistoryWritingMessageHandler is now a non-public class in the 'config' package (it's only used by ConsumerEndpointFactoryBean)
This commit is contained in:
@@ -35,7 +35,6 @@ import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.endpoint.PollingConsumer;
|
||||
import org.springframework.integration.history.MessageHistoryAwareMessageHandler;
|
||||
import org.springframework.integration.history.MessageHistoryWriter;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
import org.springframework.integration.scheduling.PollerMetadata;
|
||||
@@ -108,7 +107,7 @@ public class ConsumerEndpointFactoryBean
|
||||
if (historyWriters.size() == 1) {
|
||||
MessageHistoryWriter writer = historyWriters.values().iterator().next();
|
||||
if (!this.beanName.startsWith("org.springframework") && this.handler instanceof IntegrationObjectSupport) {
|
||||
this.handler = new MessageHistoryAwareMessageHandler(this.handler, writer, this.beanName);
|
||||
this.handler = new MessageHistoryWritingMessageHandler(this.handler, writer, this.beanName);
|
||||
}
|
||||
}
|
||||
this.initializeEndpoint();
|
||||
|
||||
@@ -14,11 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.history;
|
||||
package org.springframework.integration.config;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.integration.context.NamedComponent;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.history.MessageHistoryWriter;
|
||||
import org.springframework.integration.history.NamedComponent;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -31,7 +32,7 @@ import org.springframework.util.Assert;
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
public class MessageHistoryAwareMessageHandler implements NamedComponent, MessageHandler, Ordered {
|
||||
class MessageHistoryWritingMessageHandler implements NamedComponent, MessageHandler, Ordered {
|
||||
|
||||
private final MessageHandler targetHandler;
|
||||
|
||||
@@ -45,7 +46,7 @@ public class MessageHistoryAwareMessageHandler implements NamedComponent, Messag
|
||||
* @param endpointName
|
||||
* @param targetHandler
|
||||
*/
|
||||
public MessageHistoryAwareMessageHandler(MessageHandler targetHandler, MessageHistoryWriter historyWriter, String endpointName) {
|
||||
public MessageHistoryWritingMessageHandler(MessageHandler targetHandler, MessageHistoryWriter historyWriter, String endpointName) {
|
||||
Assert.notNull(targetHandler, "targetHandler must not be null");
|
||||
Assert.notNull(historyWriter, "historyWriter must not be null");
|
||||
this.targetHandler = targetHandler;
|
||||
@@ -71,7 +72,9 @@ public class MessageHistoryAwareMessageHandler implements NamedComponent, Messag
|
||||
* Writes the MessageHistory event and then invokes the target handler.
|
||||
*/
|
||||
public void handleMessage(Message<?> message) {
|
||||
this.historyWriter.writeHistory(this, message);
|
||||
if (message != null) {
|
||||
this.historyWriter.writeHistory(this, message.getHeaders().getHistory());
|
||||
}
|
||||
this.targetHandler.handleMessage(message);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.integration.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.channel.ChannelResolver;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.history.MessageHistoryWriter;
|
||||
import org.springframework.integration.history.NamedComponent;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -171,8 +172,8 @@ public abstract class IntegrationObjectSupport implements BeanNameAware, NamedCo
|
||||
}
|
||||
|
||||
protected void writeMessageHistory(Message<?> message) {
|
||||
if (historyWriter != null) {
|
||||
historyWriter.writeHistory(this, message);
|
||||
if (historyWriter != null && message != null) {
|
||||
historyWriter.writeHistory(this, message.getHeaders().getHistory());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.Iterator;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import org.springframework.integration.context.NamedComponent;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,8 +22,6 @@ import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.ListableBeanFactory;
|
||||
import org.springframework.integration.context.NamedComponent;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -52,9 +50,9 @@ public class MessageHistoryWriter implements BeanFactoryAware, InitializingBean{
|
||||
}
|
||||
}
|
||||
|
||||
public void writeHistory(NamedComponent component, Message<?> message) {
|
||||
if (message != null) {
|
||||
message.getHeaders().getHistory().addEvent(component);
|
||||
public void writeHistory(NamedComponent component, MessageHistory history) {
|
||||
if (history != null) {
|
||||
history.addEvent(component);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.context;
|
||||
package org.springframework.integration.history;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -41,33 +41,37 @@ import org.springframework.integration.message.MessageRejectedException;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
public class MessageHistoryIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testHistoryAwareMessageHandler(){
|
||||
public void testHistoryAwareMessageHandler() {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("messageHistoryWithHistoryWriter.xml", MessageHistoryIntegrationTests.class);
|
||||
Map<String, ConsumerEndpointFactoryBean> cefBeans = ac.getBeansOfType(ConsumerEndpointFactoryBean.class);
|
||||
for (ConsumerEndpointFactoryBean cefBean : cefBeans.values()) {
|
||||
DirectFieldAccessor bridgeAccessor = new DirectFieldAccessor(cefBean);
|
||||
assertTrue(bridgeAccessor.getPropertyValue("handler") instanceof MessageHistoryAwareMessageHandler);
|
||||
String handlerClassName = bridgeAccessor.getPropertyValue("handler").getClass().getName();
|
||||
assertEquals("org.springframework.integration.config.MessageHistoryAwareMessageHandler", handlerClassName);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoHistoryAwareMessageHandler(){
|
||||
public void testNoHistoryAwareMessageHandler() {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("messageHistoryWithoutHistoryWriter.xml", MessageHistoryIntegrationTests.class);
|
||||
Map<String, ConsumerEndpointFactoryBean> cefBeans = ac.getBeansOfType(ConsumerEndpointFactoryBean.class);
|
||||
for (ConsumerEndpointFactoryBean cefBean : cefBeans.values()) {
|
||||
DirectFieldAccessor bridgeAccessor = new DirectFieldAccessor(cefBean);
|
||||
assertFalse(bridgeAccessor.getPropertyValue("handler") instanceof MessageHistoryAwareMessageHandler);
|
||||
String handlerClassName = bridgeAccessor.getPropertyValue("handler").getClass().getName();
|
||||
assertFalse("org.springframework.integration.config.MessageHistoryAwareMessageHandler".equals(handlerClassName));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tetsMessageHistoryWithHistoryWriter(){
|
||||
public void tetsMessageHistoryWithHistoryWriter() {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("messageHistoryWithHistoryWriter.xml", MessageHistoryIntegrationTests.class);
|
||||
SampleGateway gateway = ac.getBean("sampleGateway", SampleGateway.class);
|
||||
DirectChannel endOfThePipeChannel = ac.getBean("endOfThePipeChannel", DirectChannel.class);
|
||||
MessageHandler handler = Mockito.spy(new MessageHandler() {
|
||||
MessageHandler handler = Mockito.spy(new MessageHandler() {
|
||||
public void handleMessage(Message<?> message)
|
||||
throws MessageRejectedException, MessageHandlingException,MessageDeliveryException {
|
||||
System.out.println(message);
|
||||
@@ -141,7 +145,7 @@ public class MessageHistoryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tetsMessageHistoryWithoutHistoryWriter(){
|
||||
public void tetsMessageHistoryWithoutHistoryWriter() {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("messageHistoryWithoutHistoryWriter.xml", MessageHistoryIntegrationTests.class);
|
||||
SampleGateway gateway = ac.getBean("sampleGateway", SampleGateway.class);
|
||||
DirectChannel endOfThePipeChannel = ac.getBean("endOfThePipeChannel", DirectChannel.class);
|
||||
@@ -160,8 +164,9 @@ public class MessageHistoryIntegrationTests {
|
||||
gateway.echo("hello");
|
||||
Mockito.verify(handler, Mockito.times(1)).handleMessage(Mockito.any(Message.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageHistoryParser(){
|
||||
public void testMessageHistoryParser() {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("messageHistoryWithHistoryWriterNamespace.xml", MessageHistoryIntegrationTests.class);
|
||||
SampleGateway gateway = ac.getBean("sampleGateway", SampleGateway.class);
|
||||
DirectChannel endOfThePipeChannel = ac.getBean("endOfThePipeChannel", DirectChannel.class);
|
||||
@@ -179,16 +184,19 @@ public class MessageHistoryIntegrationTests {
|
||||
gateway.echo("hello");
|
||||
Mockito.verify(handler, Mockito.times(1)).handleMessage(Mockito.any(Message.class));
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionParsingException.class)
|
||||
public void testMessageHistoryMoreThenOneNamespaceFail(){
|
||||
public void testMessageHistoryMoreThenOneNamespaceFail() {
|
||||
new ClassPathXmlApplicationContext("messageHistoryWithHistoryWriterNamespace-fail.xml", MessageHistoryIntegrationTests.class);
|
||||
}
|
||||
|
||||
@Test(expected=BeanCreationException.class)
|
||||
public void testMessageHistoryMoreThenOneFail(){
|
||||
public void testMessageHistoryMoreThenOneFail() {
|
||||
new ClassPathXmlApplicationContext("messageHistoryWithHistoryWriter-fail.xml", MessageHistoryIntegrationTests.class);
|
||||
}
|
||||
|
||||
public static interface SampleGateway{
|
||||
|
||||
|
||||
public static interface SampleGateway {
|
||||
public Message<?> echo(String value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.context.NamedComponent;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
|
||||
@@ -34,11 +34,11 @@ import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.integration.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.channel.MessagePublishingErrorHandler;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.context.NamedComponent;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.endpoint.AbstractPollingEndpoint;
|
||||
import org.springframework.integration.history.NamedComponent;
|
||||
import org.springframework.integration.message.MessageDeliveryException;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
|
||||
@@ -27,13 +27,13 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.channel.SubscribableChannel;
|
||||
import org.springframework.integration.context.NamedComponent;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHeaders;
|
||||
import org.springframework.integration.core.MessagingException;
|
||||
import org.springframework.integration.history.MessageHistory;
|
||||
import org.springframework.integration.history.MessageHistoryEvent;
|
||||
import org.springframework.integration.history.NamedComponent;
|
||||
import org.springframework.integration.jms.DefaultJmsHeaderMapper;
|
||||
import org.springframework.integration.message.MessageDeliveryException;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
|
||||
@@ -19,10 +19,10 @@ package org.springframework.integration.rmi;
|
||||
import java.rmi.registry.Registry;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.context.NamedComponent;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.gateway.RemotingInboundGatewaySupport;
|
||||
import org.springframework.integration.gateway.RequestReplyExchanger;
|
||||
import org.springframework.integration.history.NamedComponent;
|
||||
import org.springframework.remoting.rmi.RmiServiceExporter;
|
||||
import org.springframework.remoting.support.RemoteInvocationExecutor;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -25,8 +25,8 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.integration.context.NamedComponent;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.history.NamedComponent;
|
||||
import org.springframework.security.access.ConfigAttribute;
|
||||
import org.springframework.security.access.SecurityMetadataSource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -32,11 +32,11 @@ import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.integration.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.channel.MessagePublishingErrorHandler;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.context.NamedComponent;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.endpoint.AbstractPollingEndpoint;
|
||||
import org.springframework.integration.history.NamedComponent;
|
||||
import org.springframework.integration.message.MessageDeliveryException;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
|
||||
Reference in New Issue
Block a user