INT-2433: Get Rid of MessageProcessors wrapping

Previously, provided `MessageProcessor` to create a `MessageHandler`
for endpoint was wrapped to `MethodInvokingMessageProcessor`,
e.g. `GroovyScriptExecutingMessageProcessor`.

Check the type of provided object in the constructor
of `MethodInvoking*` strategies and use it directly if it is `MessageProcessor`

JIRA: https://jira.springsource.org/browse/INT-2433
This commit is contained in:
Artem Bilan
2013-09-06 15:54:40 +03:00
committed by Gary Russell
parent 417c848c0b
commit 4d3bc36ff0
15 changed files with 129 additions and 29 deletions

View File

@@ -7,7 +7,7 @@
http://www.springframework.org/schema/integration/groovy http://www.springframework.org/schema/integration/groovy/spring-integration-groovy.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<filter input-channel="referencedScriptInput">
<filter id="groovyFilter" input-channel="referencedScriptInput">
<groovy:script location="org/springframework/integration/groovy/config/GroovyFilterTests.groovy"/>
</filter>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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.
@@ -19,20 +19,30 @@ package org.springframework.integration.groovy.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.core.MessageSelector;
import org.springframework.integration.filter.MessageFilter;
import org.springframework.integration.filter.MethodInvokingSelector;
import org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor;
import org.springframework.integration.handler.MessageProcessor;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @author Artem Bilan
* @since 2.0
*/
@ContextConfiguration
@@ -45,6 +55,9 @@ public class GroovyFilterTests {
@Autowired
private MessageChannel inlineScriptInput;
@Autowired
@Qualifier("groovyFilter.handler")
private MessageHandler groovyFilterMessageHandler;
@Test
public void referencedScript() {
@@ -57,7 +70,7 @@ public class GroovyFilterTests {
Message<?> message2 = MessageBuilder.withPayload("test-2")
.setReplyChannel(replyChannel)
.setHeader("type", "good")
.build();
.build();
this.referencedScriptInput.send(message1);
this.referencedScriptInput.send(message2);
assertEquals("test-2", replyChannel.receive(0).getPayload());
@@ -69,7 +82,7 @@ public class GroovyFilterTests {
QueueChannel replyChannel = new QueueChannel();
replyChannel.setBeanName("returnAddress");
Message<?> message1 = MessageBuilder.withPayload("bad").setReplyChannel(replyChannel).build();
Message<?> message2 = MessageBuilder.withPayload("good").setReplyChannel(replyChannel).build();
Message<?> message2 = MessageBuilder.withPayload("good").setReplyChannel(replyChannel).build();
this.inlineScriptInput.send(message1);
this.inlineScriptInput.send(message2);
Message<?> received = replyChannel.receive(0);
@@ -79,4 +92,14 @@ public class GroovyFilterTests {
assertNull(replyChannel.receive(0));
}
@Test
public void testInt2433VerifyRiddingOfMessageProcessorsWrapping() {
assertTrue(this.groovyFilterMessageHandler instanceof MessageFilter);
MessageSelector selector = TestUtils.getPropertyValue(this.groovyFilterMessageHandler, "selector",
MethodInvokingSelector.class);
MessageProcessor messageProcessor = TestUtils.getPropertyValue(selector, "messageProcessor", MessageProcessor.class);
//before it was MethodInvokingMessageProcessor
assertTrue(messageProcessor instanceof GroovyScriptExecutingMessageProcessor);
}
}

View File

@@ -15,7 +15,7 @@
<queue/>
</channel>
<router input-channel="referencedScriptInput">
<router id="groovyRouter" input-channel="referencedScriptInput">
<groovy:script location="org/springframework/integration/groovy/config/GroovyRouterTests.groovy"/>
</router>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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.
@@ -18,20 +18,28 @@ package org.springframework.integration.groovy.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor;
import org.springframework.integration.handler.MessageProcessor;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.router.MethodInvokingRouter;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @author Artem Bilan
* @since 2.0
*/
@ContextConfiguration
@@ -50,6 +58,9 @@ public class GroovyRouterTests {
@Autowired
private PollableChannel shortStrings;
@Autowired
@Qualifier("groovyRouter.handler")
private MessageHandler groovyRouterMessageHandler;
@Test
public void referencedScript() { // long is > 3
@@ -93,4 +104,13 @@ public class GroovyRouterTests {
assertNull(longStrings.receive(0));
}
@Test
public void testInt2433VerifyRiddingOfMessageProcessorsWrapping() {
assertTrue(this.groovyRouterMessageHandler instanceof MethodInvokingRouter);
MessageProcessor messageProcessor = TestUtils.getPropertyValue(this.groovyRouterMessageHandler,
"messageProcessor", MessageProcessor.class);
//before it was MethodInvokingMessageProcessor
assertTrue(messageProcessor instanceof GroovyScriptExecutingMessageProcessor);
}
}

View File

@@ -7,7 +7,7 @@
http://www.springframework.org/schema/integration/groovy http://www.springframework.org/schema/integration/groovy/spring-integration-groovy.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<splitter input-channel="referencedScriptInput">
<splitter id="groovySplitter" input-channel="referencedScriptInput">
<groovy:script location="org/springframework/integration/groovy/config/GroovySplitterTests.groovy"/>
</splitter>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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.
@@ -18,20 +18,28 @@ package org.springframework.integration.groovy.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor;
import org.springframework.integration.handler.MessageProcessor;
import org.springframework.integration.splitter.MethodInvokingSplitter;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @author Artem Bilan
* @since 2.0
*/
@ContextConfiguration
@@ -44,6 +52,9 @@ public class GroovySplitterTests {
@Autowired
private MessageChannel inlineScriptInput;
@Autowired
@Qualifier("groovySplitter.handler")
private MessageHandler groovySplitterMessageHandler;
@Test
public void referencedScript() {
@@ -69,4 +80,13 @@ public class GroovySplitterTests {
assertNull(replyChannel.receive(0));
}
@Test
public void testInt2433VerifyRiddingOfMessageProcessorsWrapping() {
assertTrue(this.groovySplitterMessageHandler instanceof MethodInvokingSplitter);
MessageProcessor messageProcessor = TestUtils.getPropertyValue(this.groovySplitterMessageHandler,
"messageProcessor", MessageProcessor.class);
//before it was MethodInvokingMessageProcessor
assertTrue(messageProcessor instanceof GroovyScriptExecutingMessageProcessor);
}
}

View File

@@ -7,7 +7,7 @@
http://www.springframework.org/schema/integration/groovy http://www.springframework.org/schema/integration/groovy/spring-integration-groovy.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<transformer input-channel="referencedScriptInput">
<transformer id="groovyTransformer" input-channel="referencedScriptInput">
<groovy:script location="org/springframework/integration/groovy/config/GroovyTransformerTests.groovy"/>
</transformer>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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.
@@ -18,20 +18,30 @@ package org.springframework.integration.groovy.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor;
import org.springframework.integration.handler.MessageProcessor;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.transformer.AbstractMessageProcessingTransformer;
import org.springframework.integration.transformer.MessageTransformingHandler;
import org.springframework.integration.transformer.Transformer;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @author Artem Bilan
* @since 2.0
*/
@ContextConfiguration
@@ -44,6 +54,9 @@ public class GroovyTransformerTests {
@Autowired
private MessageChannel inlineScriptInput;
@Autowired
@Qualifier("groovyTransformer.handler")
private MessageHandler groovyTransformerMessageHandler;
@Test
public void referencedScript() {
@@ -73,4 +86,13 @@ public class GroovyTransformerTests {
assertNull(replyChannel.receive(0));
}
@Test
public void testInt2433VerifyRiddingOfMessageProcessorsWrapping() {
assertTrue(this.groovyTransformerMessageHandler instanceof MessageTransformingHandler);
Transformer transformer = TestUtils.getPropertyValue(this.groovyTransformerMessageHandler, "transformer", Transformer.class);
assertTrue(transformer instanceof AbstractMessageProcessingTransformer);
MessageProcessor messageProcessor = TestUtils.getPropertyValue(transformer, "messageProcessor", MessageProcessor.class);
//before it was MethodInvokingMessageProcessor
assertTrue(messageProcessor instanceof GroovyScriptExecutingMessageProcessor);
}
}