diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/ServiceActivatingHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/ServiceActivatingHandler.java index e3afc4832b..ee927f6e25 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/ServiceActivatingHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/ServiceActivatingHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2012 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. @@ -24,10 +24,11 @@ import org.springframework.integration.annotation.ServiceActivator; /** * @author Mark Fisher + * @author Artem Bilan */ public class ServiceActivatingHandler extends AbstractReplyProducingMessageHandler { - private final AbstractMessageProcessor processor; + private final MessageProcessor processor; public ServiceActivatingHandler(final Object object) { @@ -42,7 +43,7 @@ public class ServiceActivatingHandler extends AbstractReplyProducingMessageHandl this(new MethodInvokingMessageProcessor(object, methodName)); } - public ServiceActivatingHandler(AbstractMessageProcessor processor) { + public ServiceActivatingHandler(MessageProcessor processor) { this.processor = processor; } @@ -55,7 +56,9 @@ public class ServiceActivatingHandler extends AbstractReplyProducingMessageHandl @Override public final void onInit() { super.onInit(); - this.processor.setConversionService(this.getConversionService()); + if (processor instanceof AbstractMessageProcessor) { + ((AbstractMessageProcessor) this.processor).setConversionService(this.getConversionService()); + } } @Override diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/ServiceActivatorDefaultFrameworkMethodTests-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/handler/ServiceActivatorDefaultFrameworkMethodTests-context.xml index 26ccf6b3bc..e67b1b63d5 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/ServiceActivatorDefaultFrameworkMethodTests-context.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/ServiceActivatorDefaultFrameworkMethodTests-context.xml @@ -1,11 +1,11 @@ - + http://www.springframework.org/schema/integration/spring-integration.xsd"> @@ -13,6 +13,8 @@ + + @@ -25,4 +27,8 @@ + + + + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/ServiceActivatorDefaultFrameworkMethodTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/ServiceActivatorDefaultFrameworkMethodTests.java index be20df2b1c..54405d9b11 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/ServiceActivatorDefaultFrameworkMethodTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/ServiceActivatorDefaultFrameworkMethodTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2012 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. @@ -17,23 +17,33 @@ package org.springframework.integration.handler; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThat; +import org.hamcrest.Matchers; 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.endpoint.EventDrivenConsumer; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; 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; +import java.util.Map; + /** * See INT-1688 for background. * * @author Mark Fisher + * @author Artem Bilan * @since 2.0.1 */ @ContextConfiguration @@ -46,6 +56,15 @@ public class ServiceActivatorDefaultFrameworkMethodTests { @Autowired private MessageChannel handlerTestInputChannel; + @Autowired + private MessageChannel processorTestInputChannel; + + @Autowired + private EventDrivenConsumer processorTestService; + + @Autowired + private TestMessageProcessor testMessageProcessor; + @Test public void testGateway() { QueueChannel replyChannel = new QueueChannel(); @@ -65,6 +84,20 @@ public class ServiceActivatorDefaultFrameworkMethodTests { assertEquals("handlerTestInputChannel,handlerTestService,testMessageHandler", reply.getHeaders().get("history").toString()); } +// INT-2399 + @Test + public void testMessageProcessor() { + Object processor = TestUtils.getPropertyValue(processorTestService, "handler.processor"); + assertSame(testMessageProcessor, processor); + + QueueChannel replyChannel = new QueueChannel(); + Message message = MessageBuilder.withPayload("bar").setReplyChannel(replyChannel).build(); + this.processorTestInputChannel.send(message); + Message reply = replyChannel.receive(0); + assertEquals("foo:bar", reply.getPayload()); + assertEquals("processorTestInputChannel,processorTestService", reply.getHeaders().get("history").toString()); + } + @SuppressWarnings("unused") private static class TestMessageHandler extends AbstractReplyProducingMessageHandler { @@ -75,4 +108,18 @@ public class ServiceActivatorDefaultFrameworkMethodTests { } } + + private static class TestMessageProcessor implements MessageProcessor { + + private String prefix; + + public void setPrefix(String prefix) { + this.prefix = prefix; + } + + public String processMessage(Message message) { + return prefix + ":" + message.getPayload(); + } + } + } diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyServiceActivatorTests-context.xml b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyServiceActivatorTests-context.xml index 927c3e8713..4641ef303a 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyServiceActivatorTests-context.xml +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyServiceActivatorTests-context.xml @@ -41,5 +41,17 @@ - + + + + + + + + diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyServiceActivatorTests.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyServiceActivatorTests.java index fa482f8bc9..20dbe94cc0 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyServiceActivatorTests.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyServiceActivatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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,14 +18,16 @@ package org.springframework.integration.groovy.config; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.*; + import groovy.lang.GroovyObject; +import groovy.lang.MissingPropertyException; import java.util.Date; import java.util.HashMap; import java.util.Map; +import org.hamcrest.Matchers; import org.junit.Test; import org.junit.runner.RunWith; @@ -34,7 +36,11 @@ import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.Message; import org.springframework.integration.MessageChannel; +import org.springframework.integration.MessageHandlingException; import org.springframework.integration.channel.QueueChannel; +import org.springframework.integration.handler.ReplyRequiredException; +import org.springframework.integration.message.ErrorMessage; +import org.springframework.integration.message.GenericMessage; import org.springframework.integration.scripting.ScriptVariableGenerator; import org.springframework.integration.support.MessageBuilder; import org.springframework.scripting.groovy.GroovyObjectCustomizer; @@ -44,6 +50,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher * @author Oleg Zhurakousky + * @author Artem Bilan * @since 2.0 */ @ContextConfiguration @@ -59,6 +66,9 @@ public class GroovyServiceActivatorTests { @Autowired private MessageChannel withScriptVariableGenerator; + @Autowired + private MessageChannel invalidInlineScript; + @Autowired private MyGroovyCustomizer groovyCustomizer; @@ -127,7 +137,24 @@ public class GroovyServiceActivatorTests { assertNull(replyChannel.receive(0)); assertTrue(groovyCustomizer.executed); } - + + //INT-2399 + @Test(expected = MessageHandlingException.class) + public void invalidInlineScript() throws Exception { + Message message = new ErrorMessage(new ReplyRequiredException(new GenericMessage("test"), "reply required!")); + try { + this.invalidInlineScript.send(message); + fail("MessageHandlingException expected!"); + } + catch (Exception e) { + Throwable cause = e.getCause(); + assertEquals(MissingPropertyException.class, cause.getClass()); + assertThat(cause.getMessage(), Matchers.containsString("No such property: ReplyRequiredException for class: groovy.lang")); + throw e; + } + + } + @Test(expected=BeanDefinitionParsingException.class) public void inlineScriptAndVariables() throws Exception{ new ClassPathXmlApplicationContext("GroovyServiceActivatorTests-fail-context.xml", this.getClass());