use of org.springframework.integration.splitter.AbstractMessageSplitter in project spring-integration by spring-projects.
the class SplitterAnnotationPostProcessor method createHandler.
@Override
protected MessageHandler createHandler(Object bean, Method method, List<Annotation> annotations) {
String applySequence = MessagingAnnotationUtils.resolveAttribute(annotations, "applySequence", String.class);
AbstractMessageSplitter splitter;
if (AnnotatedElementUtils.isAnnotated(method, Bean.class.getName())) {
Object target = this.resolveTargetBeanFromMethodWithBeanAnnotation(method);
splitter = this.extractTypeIfPossible(target, AbstractMessageSplitter.class);
if (splitter == null) {
if (target instanceof MessageHandler) {
Assert.hasText(applySequence, "'applySequence' can be applied to 'AbstractMessageSplitter', but " + "target handler is: " + target.getClass());
return (MessageHandler) target;
} else {
splitter = new MethodInvokingSplitter(target);
}
} else {
checkMessageHandlerAttributes(resolveTargetBeanName(method), annotations);
return splitter;
}
} else {
splitter = new MethodInvokingSplitter(bean, method);
}
if (StringUtils.hasText(applySequence)) {
String applySequenceValue = this.beanFactory.resolveEmbeddedValue(applySequence);
if (StringUtils.hasText(applySequenceValue)) {
splitter.setApplySequence(Boolean.parseBoolean(applySequenceValue));
}
}
this.setOutputChannelIfPresent(annotations, splitter);
return splitter;
}
use of org.springframework.integration.splitter.AbstractMessageSplitter in project spring-integration by spring-projects.
the class SplitterFactoryBean method postProcessReplyProducer.
@Override
protected void postProcessReplyProducer(AbstractMessageProducingHandler handler) {
super.postProcessReplyProducer(handler);
if (!(handler instanceof AbstractMessageSplitter)) {
Assert.isNull(this.applySequence, "Cannot set applySequence if the referenced bean is " + "an AbstractReplyProducingMessageHandler, but not an AbstractMessageSplitter");
Assert.isNull(this.delimiters, "Cannot set delimiters if the referenced bean is not an " + "an AbstractReplyProducingMessageHandler, but not an AbstractMessageSplitter");
} else {
AbstractMessageSplitter splitter = (AbstractMessageSplitter) handler;
if (this.delimiters != null) {
Assert.isInstanceOf(DefaultMessageSplitter.class, splitter, "The 'delimiters' property is only available for a Splitter definition where no 'ref', " + "'expression', or inner bean has been provided.");
((DefaultMessageSplitter) splitter).setDelimiters(this.delimiters);
}
if (this.applySequence != null) {
splitter.setApplySequence(this.applySequence);
}
}
}
use of org.springframework.integration.splitter.AbstractMessageSplitter in project spring-integration by spring-projects.
the class SplitterFactoryBean method createMethodInvokingHandler.
@Override
protected MessageHandler createMethodInvokingHandler(Object targetObject, String targetMethodName) {
Assert.notNull(targetObject, "targetObject must not be null");
AbstractMessageSplitter splitter = this.extractTypeIfPossible(targetObject, AbstractMessageSplitter.class);
if (splitter == null) {
this.checkForIllegalTarget(targetObject, targetMethodName);
splitter = this.createMethodInvokingSplitter(targetObject, targetMethodName);
this.configureSplitter(splitter);
} else {
Assert.isTrue(!StringUtils.hasText(targetMethodName), "target method should not be provided when the target " + "object is an implementation of AbstractMessageSplitter");
this.configureSplitter(splitter);
if (targetObject instanceof MessageHandler) {
return (MessageHandler) targetObject;
}
}
return splitter;
}
use of org.springframework.integration.splitter.AbstractMessageSplitter in project spring-integration by spring-projects.
the class CollectionAndArrayTests method arrayWithSplittingHandler.
@Test
public void arrayWithSplittingHandler() {
AbstractMessageSplitter handler = new AbstractMessageSplitter() {
@Override
protected Object splitMessage(Message<?> message) {
return new String[] { "foo", "bar" };
}
};
QueueChannel channel = new QueueChannel();
Message<?> message = MessageBuilder.withPayload("test").setReplyChannel(channel).build();
handler.handleMessage(message);
Message<?> reply1 = channel.receive(0);
Message<?> reply2 = channel.receive(0);
assertNotNull(reply1);
assertNotNull(reply2);
assertEquals(String.class, reply1.getPayload().getClass());
assertEquals(String.class, reply2.getPayload().getClass());
assertEquals("foo", reply1.getPayload());
assertEquals("bar", reply2.getPayload());
}
use of org.springframework.integration.splitter.AbstractMessageSplitter in project spring-integration by spring-projects.
the class CollectionAndArrayTests method listWithSplittingHandler.
@Test
public void listWithSplittingHandler() {
AbstractMessageSplitter handler = new AbstractMessageSplitter() {
@Override
protected Object splitMessage(Message<?> message) {
return Arrays.asList(new String[] { "foo", "bar" });
}
};
QueueChannel channel = new QueueChannel();
Message<?> message = MessageBuilder.withPayload("test").setReplyChannel(channel).build();
handler.handleMessage(message);
Message<?> reply1 = channel.receive(0);
Message<?> reply2 = channel.receive(0);
assertNotNull(reply1);
assertNotNull(reply2);
assertEquals(String.class, reply1.getPayload().getClass());
assertEquals(String.class, reply2.getPayload().getClass());
assertEquals("foo", reply1.getPayload());
assertEquals("bar", reply2.getPayload());
}
Aggregations