Search in sources :

Example 6 with DestinationResolutionException

use of org.springframework.messaging.core.DestinationResolutionException in project spring-integration by spring-projects.

the class ReturnAddressTests method returnAddressFallbackButNotAvailable.

@Test
public void returnAddressFallbackButNotAvailable() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("returnAddressTests.xml", this.getClass());
    MessageChannel channel3 = (MessageChannel) context.getBean("channel3");
    context.start();
    GenericMessage<String> message = new GenericMessage<String>("*");
    try {
        channel3.send(message);
    } catch (MessagingException e) {
        assertTrue(e.getCause() instanceof DestinationResolutionException);
    }
    context.close();
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageChannel(org.springframework.messaging.MessageChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MessagingException(org.springframework.messaging.MessagingException) DestinationResolutionException(org.springframework.messaging.core.DestinationResolutionException) Test(org.junit.Test)

Example 7 with DestinationResolutionException

use of org.springframework.messaging.core.DestinationResolutionException in project spring-integration by spring-projects.

the class AbstractMethodAnnotationPostProcessor method createEndpoint.

protected AbstractEndpoint createEndpoint(MessageHandler handler, Method method, List<Annotation> annotations) {
    AbstractEndpoint endpoint = null;
    String inputChannelName = MessagingAnnotationUtils.resolveAttribute(annotations, getInputChannelAttribute(), String.class);
    if (StringUtils.hasText(inputChannelName)) {
        MessageChannel inputChannel;
        try {
            inputChannel = this.channelResolver.resolveDestination(inputChannelName);
        } catch (DestinationResolutionException e) {
            if (e.getCause() instanceof NoSuchBeanDefinitionException) {
                inputChannel = new DirectChannel();
                this.beanFactory.registerSingleton(inputChannelName, inputChannel);
                inputChannel = (MessageChannel) this.beanFactory.initializeBean(inputChannel, inputChannelName);
            } else {
                throw e;
            }
        }
        Assert.notNull(inputChannel, "failed to resolve inputChannel '" + inputChannelName + "'");
        endpoint = doCreateEndpoint(handler, inputChannel, annotations);
    }
    return endpoint;
}
Also used : AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) MessageChannel(org.springframework.messaging.MessageChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) DestinationResolutionException(org.springframework.messaging.core.DestinationResolutionException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Aggregations

DestinationResolutionException (org.springframework.messaging.core.DestinationResolutionException)7 Test (org.junit.Test)5 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)4 MessageChannel (org.springframework.messaging.MessageChannel)4 DirectChannel (org.springframework.integration.channel.DirectChannel)3 BeanFactory (org.springframework.beans.factory.BeanFactory)2 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)2 ProducerProperties (org.springframework.cloud.stream.binder.ProducerProperties)2 BindingServiceProperties (org.springframework.cloud.stream.config.BindingServiceProperties)2 BeanFactoryChannelResolver (org.springframework.integration.support.channel.BeanFactoryChannelResolver)2 Properties (java.util.Properties)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 ConsumerProperties (org.springframework.cloud.stream.binder.ConsumerProperties)1 DefaultBinderFactory (org.springframework.cloud.stream.binder.DefaultBinderFactory)1 ExtendedProducerProperties (org.springframework.cloud.stream.binder.ExtendedProducerProperties)1 ExtendedPropertiesBinder (org.springframework.cloud.stream.binder.ExtendedPropertiesBinder)1 BindingProperties (org.springframework.cloud.stream.config.BindingProperties)1