SimpleMethodInvoker now delegates to an ArgumentConvertingMethodInvoker.
This commit is contained in:
@@ -18,6 +18,7 @@ package org.springframework.integration.util;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.springframework.beans.support.ArgumentConvertingMethodInvoker;
|
||||
import org.springframework.integration.MessagingException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.MethodInvoker;
|
||||
@@ -50,7 +51,7 @@ public class SimpleMethodInvoker<T> {
|
||||
|
||||
public Object invokeMethod(Object ... args) {
|
||||
try {
|
||||
MethodInvoker methodInvoker = new MethodInvoker();
|
||||
MethodInvoker methodInvoker = new ArgumentConvertingMethodInvoker();
|
||||
methodInvoker.setTargetObject(this.object);
|
||||
methodInvoker.setTargetMethod(this.method);
|
||||
methodInvoker.setArguments(args);
|
||||
@@ -63,11 +64,11 @@ public class SimpleMethodInvoker<T> {
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
throw new MessagingException(
|
||||
"Method '" + this.method + "' threw exception", e.getTargetException());
|
||||
"Method '" + this.method + "' threw an Exception.", e.getTargetException());
|
||||
}
|
||||
catch (Throwable e) {
|
||||
throw new MessagingException("Failed to invoke method '" + this.method +
|
||||
"' with arguments " + ObjectUtils.nullSafeToString(args), e);
|
||||
"' with arguments: " + ObjectUtils.nullSafeToString(args), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,18 @@ public class MessageEndpointAnnotationPostProcessorTests {
|
||||
context.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeConvertingHandler() throws InterruptedException {
|
||||
AbstractApplicationContext context = new ClassPathXmlApplicationContext("typeConvertingEndpointTests.xml", this.getClass());
|
||||
context.start();
|
||||
MessageChannel inputChannel = (MessageChannel) context.getBean("inputChannel");
|
||||
MessageChannel outputChannel = (MessageChannel) context.getBean("outputChannel");
|
||||
inputChannel.send(new StringMessage("123"));
|
||||
Message<?> message = outputChannel.receive(1000);
|
||||
assertEquals(246, message.getPayload());
|
||||
context.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPolledAnnotation() throws InterruptedException {
|
||||
MessageBus messageBus = new MessageBus();
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.endpoint.annotation;
|
||||
|
||||
import org.springframework.integration.annotation.Handler;
|
||||
import org.springframework.integration.annotation.MessageEndpoint;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@MessageEndpoint(input="inputChannel", defaultOutput="outputChannel", pollPeriod=10)
|
||||
public class TypeConvertingTestEndpoint {
|
||||
|
||||
@Handler
|
||||
public int multiplyByTwo(int number) {
|
||||
return number * 2;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:integration="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd">
|
||||
|
||||
<bean id="bus" class="org.springframework.integration.bus.MessageBus"/>
|
||||
|
||||
<integration:channel id="inputChannel"/>
|
||||
|
||||
<integration:channel id="outputChannel"/>
|
||||
|
||||
<bean id="endpoint" class="org.springframework.integration.endpoint.annotation.TypeConvertingTestEndpoint"/>
|
||||
|
||||
<bean class="org.springframework.integration.config.MessageEndpointAnnotationPostProcessor">
|
||||
<constructor-arg ref="bus"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user