INT-2399 fix processMessage for service-activator
ServiceActivatorFactoryBean#createMessageProcessingHandler: force 'processMessage' method-name parameter into constructor ServiceActivatingHandler for MessageProcessor Test for check 'handlerMethods' in ServiceActivatingHandler's MethodInvokingMessageProcessor Integration test for <service-activator> with invalid Groovy inline script
This commit is contained in:
@@ -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<Object> processor;
|
||||
private final MessageProcessor<?> processor;
|
||||
|
||||
|
||||
public ServiceActivatingHandler(final Object object) {
|
||||
@@ -42,7 +43,7 @@ public class ServiceActivatingHandler extends AbstractReplyProducingMessageHandl
|
||||
this(new MethodInvokingMessageProcessor<Object>(object, methodName));
|
||||
}
|
||||
|
||||
public ServiceActivatingHandler(AbstractMessageProcessor<Object> processor) {
|
||||
public <T> ServiceActivatingHandler(MessageProcessor<T> 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
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
<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"
|
||||
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">
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<message-history/>
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
<service-activator id="handlerTestService" input-channel="handlerTestInputChannel" ref="testMessageHandler"/>
|
||||
|
||||
<service-activator id="processorTestService" input-channel="processorTestInputChannel" ref="testMessageProcessor"/>
|
||||
|
||||
<gateway id="gateway" default-request-channel="requestChannel" default-reply-channel="replyChannel"/>
|
||||
|
||||
<channel id="requestChannel"/>
|
||||
@@ -25,4 +27,8 @@
|
||||
|
||||
<beans:bean id="testMessageHandler" class="org.springframework.integration.handler.ServiceActivatorDefaultFrameworkMethodTests$TestMessageHandler"/>
|
||||
|
||||
<beans:bean id="testMessageProcessor" class="org.springframework.integration.handler.ServiceActivatorDefaultFrameworkMethodTests$TestMessageProcessor">
|
||||
<beans:property name="prefix" value="foo"/>
|
||||
</beans:bean>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -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<String> {
|
||||
|
||||
private String prefix;
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public String processMessage(Message<?> message) {
|
||||
return prefix + ":" + message.getPayload();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user