Replaced the @Handler annotation with @ServiceActivator.
This commit is contained in:
@@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.integration.samples.oddeven;
|
package org.springframework.integration.samples.oddeven;
|
||||||
|
|
||||||
import org.springframework.integration.annotation.Handler;
|
|
||||||
import org.springframework.integration.annotation.MessageEndpoint;
|
import org.springframework.integration.annotation.MessageEndpoint;
|
||||||
|
import org.springframework.integration.annotation.ServiceActivator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
@@ -25,7 +25,7 @@ import org.springframework.integration.annotation.MessageEndpoint;
|
|||||||
@MessageEndpoint
|
@MessageEndpoint
|
||||||
public class EvenLogger {
|
public class EvenLogger {
|
||||||
|
|
||||||
@Handler
|
@ServiceActivator
|
||||||
public void log(int i) {
|
public void log(int i) {
|
||||||
System.out.println("even: " + i);
|
System.out.println("even: " + i);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.integration.samples.oddeven;
|
package org.springframework.integration.samples.oddeven;
|
||||||
|
|
||||||
import org.springframework.integration.annotation.Handler;
|
|
||||||
import org.springframework.integration.annotation.MessageEndpoint;
|
import org.springframework.integration.annotation.MessageEndpoint;
|
||||||
|
import org.springframework.integration.annotation.ServiceActivator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
@@ -25,7 +25,7 @@ import org.springframework.integration.annotation.MessageEndpoint;
|
|||||||
@MessageEndpoint
|
@MessageEndpoint
|
||||||
public class OddLogger {
|
public class OddLogger {
|
||||||
|
|
||||||
@Handler
|
@ServiceActivator
|
||||||
public void log(int i) {
|
public void log(int i) {
|
||||||
System.out.println("odd: " + i);
|
System.out.println("odd: " + i);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ package org.springframework.integration.samples.quartzoddeven;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.springframework.integration.annotation.Handler;
|
|
||||||
import org.springframework.integration.annotation.MessageEndpoint;
|
import org.springframework.integration.annotation.MessageEndpoint;
|
||||||
|
import org.springframework.integration.annotation.ServiceActivator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
@@ -29,7 +29,7 @@ import org.springframework.integration.annotation.MessageEndpoint;
|
|||||||
@MessageEndpoint
|
@MessageEndpoint
|
||||||
public class EvenLogger {
|
public class EvenLogger {
|
||||||
|
|
||||||
@Handler
|
@ServiceActivator
|
||||||
public void log(int i) {
|
public void log(int i) {
|
||||||
System.out.println("even: " + i + " at " + new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
|
System.out.println("even: " + i + " at " + new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ package org.springframework.integration.samples.quartzoddeven;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.springframework.integration.annotation.Handler;
|
|
||||||
import org.springframework.integration.annotation.MessageEndpoint;
|
import org.springframework.integration.annotation.MessageEndpoint;
|
||||||
|
import org.springframework.integration.annotation.ServiceActivator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
@@ -29,7 +29,7 @@ import org.springframework.integration.annotation.MessageEndpoint;
|
|||||||
@MessageEndpoint
|
@MessageEndpoint
|
||||||
public class OddLogger {
|
public class OddLogger {
|
||||||
|
|
||||||
@Handler
|
@ServiceActivator
|
||||||
public void log(int i) {
|
public void log(int i) {
|
||||||
System.out.println("odd: " + i + " at " + new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
|
System.out.println("odd: " + i + " at " + new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ import java.math.BigDecimal;
|
|||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.springframework.integration.annotation.Handler;
|
|
||||||
import org.springframework.integration.annotation.MessageEndpoint;
|
import org.springframework.integration.annotation.MessageEndpoint;
|
||||||
|
import org.springframework.integration.annotation.ServiceActivator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
@@ -29,7 +29,7 @@ import org.springframework.integration.annotation.MessageEndpoint;
|
|||||||
@MessageEndpoint
|
@MessageEndpoint
|
||||||
public class QuoteService {
|
public class QuoteService {
|
||||||
|
|
||||||
@Handler(inputChannel="tickers", outputChannel="quotes")
|
@ServiceActivator(inputChannel="tickers", outputChannel="quotes")
|
||||||
public Quote lookupQuote(String ticker) {
|
public Quote lookupQuote(String ticker) {
|
||||||
BigDecimal price = new BigDecimal(new Random().nextDouble() * 100);
|
BigDecimal price = new BigDecimal(new Random().nextDouble() * 100);
|
||||||
return new Quote(ticker, price.setScale(2, RoundingMode.HALF_EVEN));
|
return new Quote(ticker, price.setScale(2, RoundingMode.HALF_EVEN));
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ import org.springframework.integration.aggregator.AggregatingMessageHandler;
|
|||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Documented
|
@Documented
|
||||||
@Handler
|
|
||||||
public @interface Aggregator {
|
public @interface Aggregator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ import java.lang.annotation.Target;
|
|||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Inherited
|
@Inherited
|
||||||
@Documented
|
@Documented
|
||||||
@Handler
|
|
||||||
public @interface Router {
|
public @interface Router {
|
||||||
|
|
||||||
String inputChannel() default "";
|
String inputChannel() default "";
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import java.lang.annotation.Target;
|
|||||||
/**
|
/**
|
||||||
* Indicates that a method is capable of handling a message or message payload.
|
* Indicates that a method is capable of handling a message or message payload.
|
||||||
* <p>
|
* <p>
|
||||||
* A method annotated with @Handler may accept a parameter of type
|
* A method annotated with @ServiceActivator may accept a parameter of type
|
||||||
* {@link org.springframework.integration.message.Message} or of the expected
|
* {@link org.springframework.integration.message.Message} or of the expected
|
||||||
* Message payload's type. Any type conversion supported by
|
* Message payload's type. Any type conversion supported by
|
||||||
* {@link org.springframework.beans.SimpleTypeConverter} will be applied to
|
* {@link org.springframework.beans.SimpleTypeConverter} will be applied to
|
||||||
@@ -39,11 +39,11 @@ import java.lang.annotation.Target;
|
|||||||
*
|
*
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
*/
|
*/
|
||||||
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
@Target(ElementType.METHOD)
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Inherited
|
@Inherited
|
||||||
@Documented
|
@Documented
|
||||||
public @interface Handler {
|
public @interface ServiceActivator {
|
||||||
|
|
||||||
String inputChannel() default "";
|
String inputChannel() default "";
|
||||||
|
|
||||||
@@ -42,7 +42,6 @@ import java.lang.annotation.Target;
|
|||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Documented
|
@Documented
|
||||||
@Handler
|
|
||||||
public @interface Splitter {
|
public @interface Splitter {
|
||||||
|
|
||||||
String inputChannel() default "";
|
String inputChannel() default "";
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ import java.lang.annotation.Target;
|
|||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Inherited
|
@Inherited
|
||||||
@Documented
|
@Documented
|
||||||
@Handler
|
|
||||||
public @interface Transformer {
|
public @interface Transformer {
|
||||||
|
|
||||||
String inputChannel() default "";
|
String inputChannel() default "";
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ import org.springframework.core.annotation.AnnotationUtils;
|
|||||||
import org.springframework.integration.ConfigurationException;
|
import org.springframework.integration.ConfigurationException;
|
||||||
import org.springframework.integration.annotation.Aggregator;
|
import org.springframework.integration.annotation.Aggregator;
|
||||||
import org.springframework.integration.annotation.ChannelAdapter;
|
import org.springframework.integration.annotation.ChannelAdapter;
|
||||||
import org.springframework.integration.annotation.Handler;
|
|
||||||
import org.springframework.integration.annotation.Router;
|
import org.springframework.integration.annotation.Router;
|
||||||
|
import org.springframework.integration.annotation.ServiceActivator;
|
||||||
import org.springframework.integration.annotation.Splitter;
|
import org.springframework.integration.annotation.Splitter;
|
||||||
import org.springframework.integration.annotation.Transformer;
|
import org.springframework.integration.annotation.Transformer;
|
||||||
import org.springframework.integration.bus.MessageBus;
|
import org.springframework.integration.bus.MessageBus;
|
||||||
@@ -78,8 +78,8 @@ public class MessagingAnnotationPostProcessor implements BeanPostProcessor, Init
|
|||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
postProcessors.put(Aggregator.class, new AggregatorAnnotationPostProcessor(this.messageBus));
|
postProcessors.put(Aggregator.class, new AggregatorAnnotationPostProcessor(this.messageBus));
|
||||||
postProcessors.put(ChannelAdapter.class, new ChannelAdapterAnnotationPostProcessor(this.messageBus));
|
postProcessors.put(ChannelAdapter.class, new ChannelAdapterAnnotationPostProcessor(this.messageBus));
|
||||||
postProcessors.put(Handler.class, new ServiceActivatorAnnotationPostProcessor(this.messageBus));
|
|
||||||
postProcessors.put(Router.class, new RouterAnnotationPostProcessor(this.messageBus));
|
postProcessors.put(Router.class, new RouterAnnotationPostProcessor(this.messageBus));
|
||||||
|
postProcessors.put(ServiceActivator.class, new ServiceActivatorAnnotationPostProcessor(this.messageBus));
|
||||||
postProcessors.put(Splitter.class, new SplitterAnnotationPostProcessor(this.messageBus));
|
postProcessors.put(Splitter.class, new SplitterAnnotationPostProcessor(this.messageBus));
|
||||||
postProcessors.put(Transformer.class, new TransformerAnnotationPostProcessor(this.messageBus));
|
postProcessors.put(Transformer.class, new TransformerAnnotationPostProcessor(this.messageBus));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ package org.springframework.integration.config.annotation;
|
|||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.springframework.integration.annotation.Handler;
|
import org.springframework.integration.annotation.ServiceActivator;
|
||||||
import org.springframework.integration.bus.MessageBus;
|
import org.springframework.integration.bus.MessageBus;
|
||||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||||
import org.springframework.integration.endpoint.DefaultServiceInvoker;
|
import org.springframework.integration.endpoint.DefaultServiceInvoker;
|
||||||
@@ -26,9 +26,11 @@ import org.springframework.integration.endpoint.ServiceActivatorEndpoint;
|
|||||||
import org.springframework.integration.endpoint.ServiceInvoker;
|
import org.springframework.integration.endpoint.ServiceInvoker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Post-processor for Methods annotated with {@link ServiceActivator @ServiceActivator}.
|
||||||
|
*
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
*/
|
*/
|
||||||
public class ServiceActivatorAnnotationPostProcessor extends AbstractMethodAnnotationPostProcessor<Handler> {
|
public class ServiceActivatorAnnotationPostProcessor extends AbstractMethodAnnotationPostProcessor<ServiceActivator> {
|
||||||
|
|
||||||
public ServiceActivatorAnnotationPostProcessor(MessageBus messageBus) {
|
public ServiceActivatorAnnotationPostProcessor(MessageBus messageBus) {
|
||||||
super(messageBus);
|
super(messageBus);
|
||||||
@@ -36,7 +38,7 @@ public class ServiceActivatorAnnotationPostProcessor extends AbstractMethodAnnot
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object createMethodInvokingAdapter(Object bean, Method method, Handler annotation) {
|
protected Object createMethodInvokingAdapter(Object bean, Method method, ServiceActivator annotation) {
|
||||||
return new DefaultServiceInvoker(bean, method);
|
return new DefaultServiceInvoker(bean, method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.integration.annotation.Handler;
|
|
||||||
import org.springframework.integration.annotation.MessageEndpoint;
|
import org.springframework.integration.annotation.MessageEndpoint;
|
||||||
|
import org.springframework.integration.annotation.ServiceActivator;
|
||||||
import org.springframework.integration.channel.ChannelRegistry;
|
import org.springframework.integration.channel.ChannelRegistry;
|
||||||
import org.springframework.integration.channel.DirectChannel;
|
import org.springframework.integration.channel.DirectChannel;
|
||||||
import org.springframework.integration.channel.QueueChannel;
|
import org.springframework.integration.channel.QueueChannel;
|
||||||
@@ -125,7 +125,7 @@ public class DirectChannelSubscriptionTests {
|
|||||||
@MessageEndpoint
|
@MessageEndpoint
|
||||||
public static class TestEndpoint {
|
public static class TestEndpoint {
|
||||||
|
|
||||||
@Handler(inputChannel="sourceChannel", outputChannel="targetChannel")
|
@ServiceActivator(inputChannel="sourceChannel", outputChannel="targetChannel")
|
||||||
public Message<?> handle(Message<?> message) {
|
public Message<?> handle(Message<?> message) {
|
||||||
return new StringMessage(message.getPayload() + "-from-annotated-endpoint");
|
return new StringMessage(message.getPayload() + "-from-annotated-endpoint");
|
||||||
}
|
}
|
||||||
@@ -135,7 +135,7 @@ public class DirectChannelSubscriptionTests {
|
|||||||
@MessageEndpoint
|
@MessageEndpoint
|
||||||
public static class FailingTestEndpoint {
|
public static class FailingTestEndpoint {
|
||||||
|
|
||||||
@Handler(inputChannel="sourceChannel", outputChannel="targetChannel")
|
@ServiceActivator(inputChannel="sourceChannel", outputChannel="targetChannel")
|
||||||
public Message<?> handle(Message<?> message) {
|
public Message<?> handle(Message<?> message) {
|
||||||
throw new RuntimeException("intentional test failure");
|
throw new RuntimeException("intentional test failure");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ import org.junit.Test;
|
|||||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
import org.springframework.context.support.GenericApplicationContext;
|
import org.springframework.context.support.GenericApplicationContext;
|
||||||
import org.springframework.integration.annotation.Handler;
|
|
||||||
import org.springframework.integration.annotation.MessageEndpoint;
|
import org.springframework.integration.annotation.MessageEndpoint;
|
||||||
|
import org.springframework.integration.annotation.ServiceActivator;
|
||||||
import org.springframework.integration.bus.DefaultMessageBus;
|
import org.springframework.integration.bus.DefaultMessageBus;
|
||||||
import org.springframework.integration.channel.MessageChannel;
|
import org.springframework.integration.channel.MessageChannel;
|
||||||
import org.springframework.integration.channel.QueueChannel;
|
import org.springframework.integration.channel.QueueChannel;
|
||||||
@@ -38,16 +38,16 @@ import org.springframework.integration.message.StringMessage;
|
|||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
*/
|
*/
|
||||||
public class SubscriberAnnotationPostProcessorTests {
|
public class ServiceActivatorAnnotationPostProcessorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAnnotatedSubscriber() throws InterruptedException {
|
public void testAnnotatedMethod() throws InterruptedException {
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
context.registerBeanDefinition("testChannel", new RootBeanDefinition(QueueChannel.class));
|
context.registerBeanDefinition("testChannel", new RootBeanDefinition(QueueChannel.class));
|
||||||
RootBeanDefinition subscriberDef = new RootBeanDefinition(SubscriberAnnotationTestBean.class);
|
RootBeanDefinition beanDefinition = new RootBeanDefinition(SimpleServiceActivatorAnnotationTestBean.class);
|
||||||
subscriberDef.getConstructorArgumentValues().addGenericArgumentValue(latch);
|
beanDefinition.getConstructorArgumentValues().addGenericArgumentValue(latch);
|
||||||
context.registerBeanDefinition("testBean", subscriberDef);
|
context.registerBeanDefinition("testBean", beanDefinition);
|
||||||
String busBeanName = MessageBusParser.MESSAGE_BUS_BEAN_NAME;
|
String busBeanName = MessageBusParser.MESSAGE_BUS_BEAN_NAME;
|
||||||
context.registerBeanDefinition(busBeanName, new RootBeanDefinition(DefaultMessageBus.class));
|
context.registerBeanDefinition(busBeanName, new RootBeanDefinition(DefaultMessageBus.class));
|
||||||
RootBeanDefinition postProcessorDef = new RootBeanDefinition(MessagingAnnotationPostProcessor.class);
|
RootBeanDefinition postProcessorDef = new RootBeanDefinition(MessagingAnnotationPostProcessor.class);
|
||||||
@@ -55,7 +55,7 @@ public class SubscriberAnnotationPostProcessorTests {
|
|||||||
context.registerBeanDefinition("postProcessor", postProcessorDef);
|
context.registerBeanDefinition("postProcessor", postProcessorDef);
|
||||||
context.refresh();
|
context.refresh();
|
||||||
context.start();
|
context.start();
|
||||||
SubscriberAnnotationTestBean testBean = (SubscriberAnnotationTestBean) context.getBean("testBean");
|
SimpleServiceActivatorAnnotationTestBean testBean = (SimpleServiceActivatorAnnotationTestBean) context.getBean("testBean");
|
||||||
assertEquals(1, latch.getCount());
|
assertEquals(1, latch.getCount());
|
||||||
assertNull(testBean.getMessageText());
|
assertNull(testBean.getMessageText());
|
||||||
MessageChannel testChannel = (MessageChannel) context.getBean("testChannel");
|
MessageChannel testChannel = (MessageChannel) context.getBean("testChannel");
|
||||||
@@ -67,13 +67,13 @@ public class SubscriberAnnotationPostProcessorTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class AbstractSubscriberAnnotationTestBean {
|
public static class AbstractServiceActivatorAnnotationTestBean {
|
||||||
|
|
||||||
protected String messageText;
|
protected String messageText;
|
||||||
|
|
||||||
private CountDownLatch latch;
|
private CountDownLatch latch;
|
||||||
|
|
||||||
public AbstractSubscriberAnnotationTestBean(CountDownLatch latch) {
|
public AbstractServiceActivatorAnnotationTestBean(CountDownLatch latch) {
|
||||||
this.latch = latch;
|
this.latch = latch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,14 +87,14 @@ public class SubscriberAnnotationPostProcessorTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@MessageEndpoint
|
@MessageEndpoint
|
||||||
public static class SubscriberAnnotationTestBean extends SubscriberAnnotationPostProcessorTests.AbstractSubscriberAnnotationTestBean {
|
public static class SimpleServiceActivatorAnnotationTestBean extends AbstractServiceActivatorAnnotationTestBean {
|
||||||
|
|
||||||
public SubscriberAnnotationTestBean(CountDownLatch latch) {
|
public SimpleServiceActivatorAnnotationTestBean(CountDownLatch latch) {
|
||||||
super(latch);
|
super(latch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Handler(inputChannel="testChannel")
|
@ServiceActivator(inputChannel="testChannel")
|
||||||
public void testMethod(String messageText) {
|
public void testMethod(String messageText) {
|
||||||
this.messageText = messageText;
|
this.messageText = messageText;
|
||||||
this.countDown();
|
this.countDown();
|
||||||
@@ -32,9 +32,9 @@ import org.springframework.beans.DirectFieldAccessor;
|
|||||||
import org.springframework.context.support.AbstractApplicationContext;
|
import org.springframework.context.support.AbstractApplicationContext;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
import org.springframework.integration.annotation.ChannelAdapter;
|
import org.springframework.integration.annotation.ChannelAdapter;
|
||||||
import org.springframework.integration.annotation.Handler;
|
|
||||||
import org.springframework.integration.annotation.MessageEndpoint;
|
import org.springframework.integration.annotation.MessageEndpoint;
|
||||||
import org.springframework.integration.annotation.Poller;
|
import org.springframework.integration.annotation.Poller;
|
||||||
|
import org.springframework.integration.annotation.ServiceActivator;
|
||||||
import org.springframework.integration.annotation.Transformer;
|
import org.springframework.integration.annotation.Transformer;
|
||||||
import org.springframework.integration.bus.DefaultMessageBus;
|
import org.springframework.integration.bus.DefaultMessageBus;
|
||||||
import org.springframework.integration.bus.MessageBus;
|
import org.springframework.integration.bus.MessageBus;
|
||||||
@@ -71,8 +71,8 @@ public class MessagingAnnotationPostProcessorTests {
|
|||||||
@Test
|
@Test
|
||||||
public void testSimpleHandlerWithContext() {
|
public void testSimpleHandlerWithContext() {
|
||||||
AbstractApplicationContext context = new ClassPathXmlApplicationContext(
|
AbstractApplicationContext context = new ClassPathXmlApplicationContext(
|
||||||
"handlerAnnotationPostProcessorTests.xml", this.getClass());
|
"serviceActivatorAnnotationPostProcessorTests.xml", this.getClass());
|
||||||
ServiceInvoker invoker = (ServiceInvoker) context.getBean("simpleHandler");
|
ServiceInvoker invoker = (ServiceInvoker) context.getBean("testBean");
|
||||||
String reply = (String) invoker.invoke(new StringMessage("world"));
|
String reply = (String) invoker.invoke(new StringMessage("world"));
|
||||||
assertEquals("hello world", reply);
|
assertEquals("hello world", reply);
|
||||||
context.stop();
|
context.stop();
|
||||||
@@ -81,7 +81,7 @@ public class MessagingAnnotationPostProcessorTests {
|
|||||||
@Test
|
@Test
|
||||||
public void testSimpleHandlerEndpointWithContext() {
|
public void testSimpleHandlerEndpointWithContext() {
|
||||||
AbstractApplicationContext context = new ClassPathXmlApplicationContext(
|
AbstractApplicationContext context = new ClassPathXmlApplicationContext(
|
||||||
"handlerAnnotationPostProcessorTests.xml", this.getClass());
|
"serviceActivatorAnnotationPostProcessorTests.xml", this.getClass());
|
||||||
MessageChannel inputChannel = (MessageChannel) context.getBean("inputChannel");
|
MessageChannel inputChannel = (MessageChannel) context.getBean("inputChannel");
|
||||||
PollableChannel outputChannel = (PollableChannel) context.getBean("outputChannel");
|
PollableChannel outputChannel = (PollableChannel) context.getBean("outputChannel");
|
||||||
inputChannel.send(new StringMessage("foo"));
|
inputChannel.send(new StringMessage("foo"));
|
||||||
@@ -294,7 +294,7 @@ public class MessagingAnnotationPostProcessorTests {
|
|||||||
postProcessor.afterPropertiesSet();
|
postProcessor.afterPropertiesSet();
|
||||||
AnnotatedEndpointWithPolledAnnotation endpoint = new AnnotatedEndpointWithPolledAnnotation();
|
AnnotatedEndpointWithPolledAnnotation endpoint = new AnnotatedEndpointWithPolledAnnotation();
|
||||||
postProcessor.postProcessAfterInitialization(endpoint, "testBean");
|
postProcessor.postProcessAfterInitialization(endpoint, "testBean");
|
||||||
ServiceActivatorEndpoint processedEndpoint = (ServiceActivatorEndpoint) messageBus.lookupEndpoint("testBean.handler");
|
ServiceActivatorEndpoint processedEndpoint = (ServiceActivatorEndpoint) messageBus.lookupEndpoint("testBean.serviceActivator");
|
||||||
DirectFieldAccessor accessor = new DirectFieldAccessor(processedEndpoint);
|
DirectFieldAccessor accessor = new DirectFieldAccessor(processedEndpoint);
|
||||||
MessageSource<?> source = (MessageSource<?>) accessor.getPropertyValue("source");
|
MessageSource<?> source = (MessageSource<?>) accessor.getPropertyValue("source");
|
||||||
assertTrue(source instanceof SubscribableSource);
|
assertTrue(source instanceof SubscribableSource);
|
||||||
@@ -382,7 +382,7 @@ public class MessagingAnnotationPostProcessorTests {
|
|||||||
return this.channelRegistry;
|
return this.channelRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Handler(inputChannel="inputChannel")
|
@ServiceActivator(inputChannel="inputChannel")
|
||||||
public Message<?> handle(Message<?> message) {
|
public Message<?> handle(Message<?> message) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -401,7 +401,7 @@ public class MessagingAnnotationPostProcessorTests {
|
|||||||
|
|
||||||
private static class SimpleAnnotatedEndpointImplementation implements SimpleAnnotatedEndpointInterface {
|
private static class SimpleAnnotatedEndpointImplementation implements SimpleAnnotatedEndpointInterface {
|
||||||
|
|
||||||
@Handler(inputChannel="inputChannel", outputChannel="outputChannel")
|
@ServiceActivator(inputChannel="inputChannel", outputChannel="outputChannel")
|
||||||
public String test(String input) {
|
public String test(String input) {
|
||||||
return "test-" + input;
|
return "test-" + input;
|
||||||
}
|
}
|
||||||
@@ -411,7 +411,7 @@ public class MessagingAnnotationPostProcessorTests {
|
|||||||
@MessageEndpoint
|
@MessageEndpoint
|
||||||
private static class AnnotatedEndpointWithPolledAnnotation {
|
private static class AnnotatedEndpointWithPolledAnnotation {
|
||||||
|
|
||||||
@Handler(inputChannel="testChannel")
|
@ServiceActivator(inputChannel="testChannel")
|
||||||
@Poller(period=1234, initialDelay=5678, fixedRate=true, timeUnit=TimeUnit.SECONDS)
|
@Poller(period=1234, initialDelay=5678, fixedRate=true, timeUnit=TimeUnit.SECONDS)
|
||||||
public String prependFoo(String s) {
|
public String prependFoo(String s) {
|
||||||
return "foo" + s;
|
return "foo" + s;
|
||||||
@@ -422,7 +422,7 @@ public class MessagingAnnotationPostProcessorTests {
|
|||||||
@MessageEndpoint
|
@MessageEndpoint
|
||||||
private static class HandlerAnnotatedBean {
|
private static class HandlerAnnotatedBean {
|
||||||
|
|
||||||
@Handler
|
@ServiceActivator
|
||||||
public String test(String s) {
|
public String test(String s) {
|
||||||
return s + s;
|
return s + s;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.integration.config.annotation;
|
package org.springframework.integration.config.annotation;
|
||||||
|
|
||||||
import org.springframework.integration.annotation.Handler;
|
|
||||||
import org.springframework.integration.annotation.MessageEndpoint;
|
import org.springframework.integration.annotation.MessageEndpoint;
|
||||||
|
import org.springframework.integration.annotation.ServiceActivator;
|
||||||
import org.springframework.integration.endpoint.annotation.ITestEndpoint;
|
import org.springframework.integration.endpoint.annotation.ITestEndpoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,7 +26,7 @@ import org.springframework.integration.endpoint.annotation.ITestEndpoint;
|
|||||||
@MessageEndpoint
|
@MessageEndpoint
|
||||||
public class SimpleAnnotatedEndpoint implements ITestEndpoint {
|
public class SimpleAnnotatedEndpoint implements ITestEndpoint {
|
||||||
|
|
||||||
@Handler(inputChannel="inputChannel", outputChannel="outputChannel")
|
@ServiceActivator(inputChannel="inputChannel", outputChannel="outputChannel")
|
||||||
public String sayHello(String name) {
|
public String sayHello(String name) {
|
||||||
return "hello " + name;
|
return "hello " + name;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,16 +16,16 @@
|
|||||||
|
|
||||||
package org.springframework.integration.config.annotation;
|
package org.springframework.integration.config.annotation;
|
||||||
|
|
||||||
import org.springframework.integration.annotation.Handler;
|
|
||||||
import org.springframework.integration.annotation.MessageEndpoint;
|
import org.springframework.integration.annotation.MessageEndpoint;
|
||||||
|
import org.springframework.integration.annotation.ServiceActivator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
*/
|
*/
|
||||||
@MessageEndpoint
|
@MessageEndpoint
|
||||||
public class SimpleHandlerTestBean {
|
public class SimpleServiceActivatorTestBean {
|
||||||
|
|
||||||
@Handler
|
@ServiceActivator
|
||||||
public String sayHello(String input) {
|
public String sayHello(String input) {
|
||||||
return "hello " + input;
|
return "hello " + input;
|
||||||
}
|
}
|
||||||
@@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.integration.config.annotation;
|
package org.springframework.integration.config.annotation;
|
||||||
|
|
||||||
import org.springframework.integration.annotation.Handler;
|
|
||||||
import org.springframework.integration.annotation.MessageEndpoint;
|
import org.springframework.integration.annotation.MessageEndpoint;
|
||||||
|
import org.springframework.integration.annotation.ServiceActivator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
@@ -25,7 +25,7 @@ import org.springframework.integration.annotation.MessageEndpoint;
|
|||||||
@MessageEndpoint
|
@MessageEndpoint
|
||||||
public class TypeConvertingTestEndpoint {
|
public class TypeConvertingTestEndpoint {
|
||||||
|
|
||||||
@Handler(inputChannel="inputChannel", outputChannel="outputChannel")
|
@ServiceActivator(inputChannel="inputChannel", outputChannel="outputChannel")
|
||||||
public int multiplyByTwo(int number) {
|
public int multiplyByTwo(int number) {
|
||||||
return number * 2;
|
return number * 2;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd">
|
http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd">
|
||||||
|
|
||||||
<message-bus/>
|
<message-bus/>
|
||||||
|
<annotation-driven/>
|
||||||
|
|
||||||
<channel id="inputChannel"/>
|
<channel id="inputChannel"/>
|
||||||
|
|
||||||
@@ -15,12 +16,8 @@
|
|||||||
<queue capacity="5"/>
|
<queue capacity="5"/>
|
||||||
</channel>
|
</channel>
|
||||||
|
|
||||||
<service-activator input-channel="inputChannel" ref="simpleHandler" output-channel="outputChannel"/>
|
<service-activator input-channel="inputChannel" ref="testBean" output-channel="outputChannel"/>
|
||||||
|
|
||||||
<beans:bean class="org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor">
|
<beans:bean id="testBean" class="org.springframework.integration.config.annotation.SimpleServiceActivatorTestBean"/>
|
||||||
<beans:constructor-arg ref="internal.MessageBus"/>
|
|
||||||
</beans:bean>
|
|
||||||
|
|
||||||
<beans:bean id="simpleHandler" class="org.springframework.integration.config.annotation.SimpleHandlerTestBean"/>
|
|
||||||
|
|
||||||
</beans:beans>
|
</beans:beans>
|
||||||
@@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.integration.endpoint.annotation;
|
package org.springframework.integration.endpoint.annotation;
|
||||||
|
|
||||||
import org.springframework.integration.annotation.Handler;
|
|
||||||
import org.springframework.integration.annotation.MessageEndpoint;
|
import org.springframework.integration.annotation.MessageEndpoint;
|
||||||
|
import org.springframework.integration.annotation.ServiceActivator;
|
||||||
import org.springframework.integration.message.Message;
|
import org.springframework.integration.message.Message;
|
||||||
import org.springframework.integration.message.StringMessage;
|
import org.springframework.integration.message.StringMessage;
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ import org.springframework.integration.message.StringMessage;
|
|||||||
@MessageEndpoint
|
@MessageEndpoint
|
||||||
public class MessageParameterAnnotatedEndpoint {
|
public class MessageParameterAnnotatedEndpoint {
|
||||||
|
|
||||||
@Handler(inputChannel="inputChannel", outputChannel="outputChannel")
|
@ServiceActivator(inputChannel="inputChannel", outputChannel="outputChannel")
|
||||||
public StringMessage sayHello(Message<?> message) {
|
public StringMessage sayHello(Message<?> message) {
|
||||||
return new StringMessage("hello " + message.getPayload());
|
return new StringMessage("hello " + message.getPayload());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import java.util.Properties;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.integration.annotation.Handler;
|
|
||||||
import org.springframework.integration.annotation.Header;
|
import org.springframework.integration.annotation.Header;
|
||||||
import org.springframework.integration.message.GenericMessage;
|
import org.springframework.integration.message.GenericMessage;
|
||||||
import org.springframework.integration.message.Message;
|
import org.springframework.integration.message.Message;
|
||||||
@@ -111,7 +110,7 @@ public class DefaultMessageHandlerTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void messageOnlyWithAnnotatedMethod() throws Exception {
|
public void messageOnlyWithAnnotatedMethod() throws Exception {
|
||||||
AnnotatedTestHandler handler = new AnnotatedTestHandler();
|
AnnotatedTestService handler = new AnnotatedTestService();
|
||||||
Method method = handler.getClass().getMethod("messageOnly", Message.class);
|
Method method = handler.getClass().getMethod("messageOnly", Message.class);
|
||||||
DefaultMessageHandler adapter = new DefaultMessageHandler();
|
DefaultMessageHandler adapter = new DefaultMessageHandler();
|
||||||
adapter.setObject(handler);
|
adapter.setObject(handler);
|
||||||
@@ -122,7 +121,7 @@ public class DefaultMessageHandlerTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void payloadWithAnnotatedMethod() throws Exception {
|
public void payloadWithAnnotatedMethod() throws Exception {
|
||||||
AnnotatedTestHandler handler = new AnnotatedTestHandler();
|
AnnotatedTestService handler = new AnnotatedTestService();
|
||||||
Method method = handler.getClass().getMethod("integerMethod", Integer.class);
|
Method method = handler.getClass().getMethod("integerMethod", Integer.class);
|
||||||
DefaultMessageHandler adapter = new DefaultMessageHandler();
|
DefaultMessageHandler adapter = new DefaultMessageHandler();
|
||||||
adapter.setObject(handler);
|
adapter.setObject(handler);
|
||||||
@@ -133,7 +132,7 @@ public class DefaultMessageHandlerTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void convertedPayloadWithAnnotatedMethod() throws Exception {
|
public void convertedPayloadWithAnnotatedMethod() throws Exception {
|
||||||
AnnotatedTestHandler handler = new AnnotatedTestHandler();
|
AnnotatedTestService handler = new AnnotatedTestService();
|
||||||
Method method = handler.getClass().getMethod("integerMethod", Integer.class);
|
Method method = handler.getClass().getMethod("integerMethod", Integer.class);
|
||||||
DefaultMessageHandler adapter = new DefaultMessageHandler();
|
DefaultMessageHandler adapter = new DefaultMessageHandler();
|
||||||
adapter.setObject(handler);
|
adapter.setObject(handler);
|
||||||
@@ -144,7 +143,7 @@ public class DefaultMessageHandlerTests {
|
|||||||
|
|
||||||
@Test(expected = MessagingException.class)
|
@Test(expected = MessagingException.class)
|
||||||
public void conversionFailureWithAnnotatedMethod() throws Exception {
|
public void conversionFailureWithAnnotatedMethod() throws Exception {
|
||||||
AnnotatedTestHandler handler = new AnnotatedTestHandler();
|
AnnotatedTestService handler = new AnnotatedTestService();
|
||||||
Method method = handler.getClass().getMethod("integerMethod", Integer.class);
|
Method method = handler.getClass().getMethod("integerMethod", Integer.class);
|
||||||
DefaultMessageHandler adapter = new DefaultMessageHandler();
|
DefaultMessageHandler adapter = new DefaultMessageHandler();
|
||||||
adapter.setObject(handler);
|
adapter.setObject(handler);
|
||||||
@@ -155,7 +154,7 @@ public class DefaultMessageHandlerTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void messageAndHeaderWithAnnotatedMethod() throws Exception {
|
public void messageAndHeaderWithAnnotatedMethod() throws Exception {
|
||||||
AnnotatedTestHandler handler = new AnnotatedTestHandler();
|
AnnotatedTestService handler = new AnnotatedTestService();
|
||||||
Method method = handler.getClass().getMethod("messageAndHeader", Message.class, Integer.class);
|
Method method = handler.getClass().getMethod("messageAndHeader", Message.class, Integer.class);
|
||||||
DefaultMessageHandler adapter = new DefaultMessageHandler();
|
DefaultMessageHandler adapter = new DefaultMessageHandler();
|
||||||
adapter.setObject(handler);
|
adapter.setObject(handler);
|
||||||
@@ -168,7 +167,7 @@ public class DefaultMessageHandlerTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void multipleHeadersWithAnnotatedMethod() throws Exception {
|
public void multipleHeadersWithAnnotatedMethod() throws Exception {
|
||||||
AnnotatedTestHandler handler = new AnnotatedTestHandler();
|
AnnotatedTestService handler = new AnnotatedTestService();
|
||||||
Method method = handler.getClass().getMethod("twoHeaders", String.class, Integer.class);
|
Method method = handler.getClass().getMethod("twoHeaders", String.class, Integer.class);
|
||||||
DefaultMessageHandler adapter = new DefaultMessageHandler();
|
DefaultMessageHandler adapter = new DefaultMessageHandler();
|
||||||
adapter.setObject(handler);
|
adapter.setObject(handler);
|
||||||
@@ -212,50 +211,41 @@ public class DefaultMessageHandlerTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class AnnotatedTestHandler {
|
private static class AnnotatedTestService {
|
||||||
|
|
||||||
@Handler
|
|
||||||
public String messageOnly(Message<?> message) {
|
public String messageOnly(Message<?> message) {
|
||||||
return (String) message.getPayload();
|
return (String) message.getPayload();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Handler
|
|
||||||
public String messageAndHeader(Message<?> message, @Header("number") Integer num) {
|
public String messageAndHeader(Message<?> message, @Header("number") Integer num) {
|
||||||
return (String) message.getPayload() + "-" + num.toString();
|
return (String) message.getPayload() + "-" + num.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Handler
|
|
||||||
public String twoHeaders(@Header String prop, @Header("number") Integer num) {
|
public String twoHeaders(@Header String prop, @Header("number") Integer num) {
|
||||||
return prop + "-" + num.toString();
|
return prop + "-" + num.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Handler
|
|
||||||
public Integer optionalHeader(@Header(required=false) Integer num) {
|
public Integer optionalHeader(@Header(required=false) Integer num) {
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Handler
|
|
||||||
public Integer requiredHeader(@Header(value="num", required=true) Integer num) {
|
public Integer requiredHeader(@Header(value="num", required=true) Integer num) {
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Handler
|
|
||||||
public String optionalAndRequiredHeader(@Header(required=false) String prop, @Header(value="num", required=true) Integer num) {
|
public String optionalAndRequiredHeader(@Header(required=false) String prop, @Header(value="num", required=true) Integer num) {
|
||||||
return prop + num;
|
return prop + num;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Handler
|
|
||||||
public Properties propertiesMethod(Properties properties) {
|
public Properties propertiesMethod(Properties properties) {
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Handler
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Map mapMethod(Map map) {
|
public Map mapMethod(Map map) {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Handler
|
|
||||||
public Integer integerMethod(Integer i) {
|
public Integer integerMethod(Integer i) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import java.util.Properties;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.integration.annotation.Handler;
|
|
||||||
import org.springframework.integration.annotation.Header;
|
import org.springframework.integration.annotation.Header;
|
||||||
import org.springframework.integration.message.Message;
|
import org.springframework.integration.message.Message;
|
||||||
import org.springframework.integration.message.MessageBuilder;
|
import org.springframework.integration.message.MessageBuilder;
|
||||||
@@ -40,7 +39,7 @@ public class MethodArgumentMessageMapperTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOptionalHeader() throws Exception {
|
public void testOptionalHeader() throws Exception {
|
||||||
Method method = TestHandler.class.getMethod("optionalHeader", Integer.class);
|
Method method = TestService.class.getMethod("optionalHeader", Integer.class);
|
||||||
MethodArgumentMessageMapper<String> mapper = new MethodArgumentMessageMapper<String>(method);
|
MethodArgumentMessageMapper<String> mapper = new MethodArgumentMessageMapper<String>(method);
|
||||||
Object[] args = (Object[]) mapper.mapMessage(new StringMessage("foo"));
|
Object[] args = (Object[]) mapper.mapMessage(new StringMessage("foo"));
|
||||||
assertEquals(1, args.length);
|
assertEquals(1, args.length);
|
||||||
@@ -49,14 +48,14 @@ public class MethodArgumentMessageMapperTests {
|
|||||||
|
|
||||||
@Test(expected=MessageHandlingException.class)
|
@Test(expected=MessageHandlingException.class)
|
||||||
public void testRequiredHeaderNotProvided() throws Exception {
|
public void testRequiredHeaderNotProvided() throws Exception {
|
||||||
Method method = TestHandler.class.getMethod("requiredHeader", Integer.class);
|
Method method = TestService.class.getMethod("requiredHeader", Integer.class);
|
||||||
MethodArgumentMessageMapper<String> mapper = new MethodArgumentMessageMapper<String>(method);
|
MethodArgumentMessageMapper<String> mapper = new MethodArgumentMessageMapper<String>(method);
|
||||||
mapper.mapMessage(new StringMessage("foo"));
|
mapper.mapMessage(new StringMessage("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequiredHeaderProvided() throws Exception {
|
public void testRequiredHeaderProvided() throws Exception {
|
||||||
Method method = TestHandler.class.getMethod("requiredHeader", Integer.class);
|
Method method = TestService.class.getMethod("requiredHeader", Integer.class);
|
||||||
MethodArgumentMessageMapper<String> mapper = new MethodArgumentMessageMapper<String>(method);
|
MethodArgumentMessageMapper<String> mapper = new MethodArgumentMessageMapper<String>(method);
|
||||||
Message<String> message = MessageBuilder.fromPayload("foo")
|
Message<String> message = MessageBuilder.fromPayload("foo")
|
||||||
.setHeader("num", new Integer(123)).build();
|
.setHeader("num", new Integer(123)).build();
|
||||||
@@ -67,7 +66,7 @@ public class MethodArgumentMessageMapperTests {
|
|||||||
|
|
||||||
@Test(expected=MessageHandlingException.class)
|
@Test(expected=MessageHandlingException.class)
|
||||||
public void testOptionalAndRequiredHeaderWithOnlyOptionalHeaderProvided() throws Exception {
|
public void testOptionalAndRequiredHeaderWithOnlyOptionalHeaderProvided() throws Exception {
|
||||||
Method method = TestHandler.class.getMethod("optionalAndRequiredHeader", String.class, Integer.class);
|
Method method = TestService.class.getMethod("optionalAndRequiredHeader", String.class, Integer.class);
|
||||||
MethodArgumentMessageMapper<String> mapper = new MethodArgumentMessageMapper<String>(method);
|
MethodArgumentMessageMapper<String> mapper = new MethodArgumentMessageMapper<String>(method);
|
||||||
Message<String> message = MessageBuilder.fromPayload("foo")
|
Message<String> message = MessageBuilder.fromPayload("foo")
|
||||||
.setHeader("prop", "bar").build();
|
.setHeader("prop", "bar").build();
|
||||||
@@ -76,7 +75,7 @@ public class MethodArgumentMessageMapperTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOptionalAndRequiredHeaderWithOnlyRequiredHeaderProvided() throws Exception {
|
public void testOptionalAndRequiredHeaderWithOnlyRequiredHeaderProvided() throws Exception {
|
||||||
Method method = TestHandler.class.getMethod("optionalAndRequiredHeader", String.class, Integer.class);
|
Method method = TestService.class.getMethod("optionalAndRequiredHeader", String.class, Integer.class);
|
||||||
MethodArgumentMessageMapper<String> mapper = new MethodArgumentMessageMapper<String>(method);
|
MethodArgumentMessageMapper<String> mapper = new MethodArgumentMessageMapper<String>(method);
|
||||||
Message<String> message = MessageBuilder.fromPayload("foo")
|
Message<String> message = MessageBuilder.fromPayload("foo")
|
||||||
.setHeader("num", new Integer(123)).build();
|
.setHeader("num", new Integer(123)).build();
|
||||||
@@ -88,7 +87,7 @@ public class MethodArgumentMessageMapperTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOptionalAndRequiredHeaderWithBothHeadersProvided() throws Exception {
|
public void testOptionalAndRequiredHeaderWithBothHeadersProvided() throws Exception {
|
||||||
Method method = TestHandler.class.getMethod("optionalAndRequiredHeader", String.class, Integer.class);
|
Method method = TestService.class.getMethod("optionalAndRequiredHeader", String.class, Integer.class);
|
||||||
MethodArgumentMessageMapper<String> mapper = new MethodArgumentMessageMapper<String>(method);
|
MethodArgumentMessageMapper<String> mapper = new MethodArgumentMessageMapper<String>(method);
|
||||||
Message<String> message = MessageBuilder.fromPayload("foo")
|
Message<String> message = MessageBuilder.fromPayload("foo")
|
||||||
.setHeader("num", new Integer(123))
|
.setHeader("num", new Integer(123))
|
||||||
@@ -102,7 +101,7 @@ public class MethodArgumentMessageMapperTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPropertiesMethodWithNonPropertiesPayload() throws Exception {
|
public void testPropertiesMethodWithNonPropertiesPayload() throws Exception {
|
||||||
Method method = TestHandler.class.getMethod("propertiesMethod", Properties.class);
|
Method method = TestService.class.getMethod("propertiesMethod", Properties.class);
|
||||||
MethodArgumentMessageMapper<String> mapper = new MethodArgumentMessageMapper<String>(method);
|
MethodArgumentMessageMapper<String> mapper = new MethodArgumentMessageMapper<String>(method);
|
||||||
Message<String> message = MessageBuilder.fromPayload("test")
|
Message<String> message = MessageBuilder.fromPayload("test")
|
||||||
.setHeader("prop1", "foo").setHeader("prop2", "bar").build();
|
.setHeader("prop1", "foo").setHeader("prop2", "bar").build();
|
||||||
@@ -115,7 +114,7 @@ public class MethodArgumentMessageMapperTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPropertiesMethodWithPropertiesPayload() throws Exception {
|
public void testPropertiesMethodWithPropertiesPayload() throws Exception {
|
||||||
Method method = TestHandler.class.getMethod("propertiesMethod", Properties.class);
|
Method method = TestService.class.getMethod("propertiesMethod", Properties.class);
|
||||||
MethodArgumentMessageMapper<Properties> mapper = new MethodArgumentMessageMapper<Properties>(method);
|
MethodArgumentMessageMapper<Properties> mapper = new MethodArgumentMessageMapper<Properties>(method);
|
||||||
Properties payload = new Properties();
|
Properties payload = new Properties();
|
||||||
payload.setProperty("prop1", "foo");
|
payload.setProperty("prop1", "foo");
|
||||||
@@ -132,7 +131,7 @@ public class MethodArgumentMessageMapperTests {
|
|||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testMapMethodWithNonMapPayload() throws Exception {
|
public void testMapMethodWithNonMapPayload() throws Exception {
|
||||||
Method method = TestHandler.class.getMethod("mapMethod", Map.class);
|
Method method = TestService.class.getMethod("mapMethod", Map.class);
|
||||||
MethodArgumentMessageMapper<String> mapper = new MethodArgumentMessageMapper<String>(method);
|
MethodArgumentMessageMapper<String> mapper = new MethodArgumentMessageMapper<String>(method);
|
||||||
Message<String> message = MessageBuilder.fromPayload("test")
|
Message<String> message = MessageBuilder.fromPayload("test")
|
||||||
.setHeader("attrib1", new Integer(123))
|
.setHeader("attrib1", new Integer(123))
|
||||||
@@ -146,7 +145,7 @@ public class MethodArgumentMessageMapperTests {
|
|||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testMapMethodWithMapPayload() throws Exception {
|
public void testMapMethodWithMapPayload() throws Exception {
|
||||||
Method method = TestHandler.class.getMethod("mapMethod", Map.class);
|
Method method = TestService.class.getMethod("mapMethod", Map.class);
|
||||||
MethodArgumentMessageMapper<Map<String,Integer>> mapper = new MethodArgumentMessageMapper<Map<String,Integer>>(method);
|
MethodArgumentMessageMapper<Map<String,Integer>> mapper = new MethodArgumentMessageMapper<Map<String,Integer>>(method);
|
||||||
Map<String, Integer> payload = new HashMap<String, Integer>();
|
Map<String, Integer> payload = new HashMap<String, Integer>();
|
||||||
payload.put("attrib1", new Integer(123));
|
payload.put("attrib1", new Integer(123));
|
||||||
@@ -162,50 +161,41 @@ public class MethodArgumentMessageMapperTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class TestHandler {
|
private static class TestService {
|
||||||
|
|
||||||
@Handler
|
|
||||||
public String messageOnly(Message<?> message) {
|
public String messageOnly(Message<?> message) {
|
||||||
return (String) message.getPayload();
|
return (String) message.getPayload();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Handler
|
|
||||||
public String messageAndHeader(Message<?> message, @Header("number") Integer num) {
|
public String messageAndHeader(Message<?> message, @Header("number") Integer num) {
|
||||||
return (String) message.getPayload() + "-" + num.toString();
|
return (String) message.getPayload() + "-" + num.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Handler
|
|
||||||
public String twoHeaders(@Header String prop, @Header("number") Integer num) {
|
public String twoHeaders(@Header String prop, @Header("number") Integer num) {
|
||||||
return prop + "-" + num.toString();
|
return prop + "-" + num.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Handler
|
|
||||||
public Integer optionalHeader(@Header(required=false) Integer num) {
|
public Integer optionalHeader(@Header(required=false) Integer num) {
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Handler
|
|
||||||
public Integer requiredHeader(@Header(value="num", required=true) Integer num) {
|
public Integer requiredHeader(@Header(value="num", required=true) Integer num) {
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Handler
|
|
||||||
public String optionalAndRequiredHeader(@Header(required=false) String prop, @Header(value="num", required=true) Integer num) {
|
public String optionalAndRequiredHeader(@Header(required=false) String prop, @Header(value="num", required=true) Integer num) {
|
||||||
return prop + num;
|
return prop + num;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Handler
|
|
||||||
public Properties propertiesMethod(Properties properties) {
|
public Properties propertiesMethod(Properties properties) {
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Handler
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Map mapMethod(Map map) {
|
public Map mapMethod(Map map) {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Handler
|
|
||||||
public Integer integerMethod(Integer i) {
|
public Integer integerMethod(Integer i) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user