Removed SourceEndpoint. Also, MessageExchangeTemplate now wraps any Exception thrown in source.receive() in a MessagingException.
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.message.MessageSource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A channel adapter that retrieves messages from a {@link MessageSource}
|
||||
* and then sends the resulting messages to the provided {@link MessageChannel}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class SourceEndpoint extends AbstractEndpoint {
|
||||
|
||||
public SourceEndpoint(MessageSource<?> source) {
|
||||
Assert.notNull(source, "source must not be null");
|
||||
this.setSource(source);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
if (this.getTarget() == null) {
|
||||
throw new ConfigurationException(
|
||||
"no output has been configured for source endpoint '" + this.getName() + "'");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -223,11 +223,11 @@ public class MessageExchangeTemplate implements InitializingBean {
|
||||
}
|
||||
|
||||
private boolean doReceiveAndForward(PollableSource<?> source, MessageTarget target) {
|
||||
Message<?> message = this.doReceive(source);
|
||||
if (message == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Message<?> message = this.doReceive(source);
|
||||
if (message == null) {
|
||||
return false;
|
||||
}
|
||||
boolean sent = this.doSend(message, target);
|
||||
if (source instanceof MessageDeliveryAware) {
|
||||
if (sent) {
|
||||
|
||||
@@ -30,18 +30,18 @@ import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.channel.PollableChannelAdapter;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.dispatcher.PublishSubscribeChannel;
|
||||
import org.springframework.integration.endpoint.SourceEndpoint;
|
||||
import org.springframework.integration.endpoint.HandlerEndpoint;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.ErrorMessage;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.MessageSource;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.PollableSource;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.scheduling.PollingSchedule;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -193,18 +193,26 @@ public class DefaultMessageBusTests {
|
||||
public void testErrorChannelWithFailedDispatch() throws InterruptedException {
|
||||
MessageBus bus = new DefaultMessageBus();
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
SourceEndpoint sourceEndpoint = new SourceEndpoint(new FailingSource(latch));
|
||||
sourceEndpoint.setTarget(new QueueChannel());
|
||||
sourceEndpoint.setSchedule(new PollingSchedule(1000));
|
||||
sourceEndpoint.setName("testEndpoint");
|
||||
bus.registerEndpoint(sourceEndpoint);
|
||||
PollableChannelAdapter channelAdapter = new PollableChannelAdapter(
|
||||
"testChannel", new FailingSource(latch), null);
|
||||
MessageHandler handler = new MessageHandler() {
|
||||
public Message<?> handle(Message<?> message) {
|
||||
return message;
|
||||
}
|
||||
};
|
||||
HandlerEndpoint endpoint = new HandlerEndpoint(handler);
|
||||
endpoint.setName("testEndpoint");
|
||||
endpoint.setSource(channelAdapter);
|
||||
bus.registerEndpoint(endpoint);
|
||||
bus.start();
|
||||
latch.await(2000, TimeUnit.MILLISECONDS);
|
||||
Message<?> message = ((PollableChannel) bus.getErrorChannel()).receive(5000);
|
||||
bus.stop();
|
||||
assertNotNull("message should not be null", message);
|
||||
assertTrue(message instanceof ErrorMessage);
|
||||
assertEquals("intentional test failure", ((ErrorMessage) message).getPayload().getMessage());
|
||||
bus.stop();
|
||||
Throwable exception = ((ErrorMessage) message).getPayload();
|
||||
assertTrue(exception instanceof MessagingException);
|
||||
assertEquals("intentional test failure", exception.getCause().getMessage());
|
||||
}
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
|
||||
Reference in New Issue
Block a user