|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2016 the original author or authors. |
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -39,6 +39,7 @@ import org.springframework.jms.config.JmsListenerEndpointRegistry; |
|
|
|
import org.springframework.jms.config.MessageListenerTestContainer; |
|
|
|
import org.springframework.jms.config.MessageListenerTestContainer; |
|
|
|
import org.springframework.jms.config.MethodJmsListenerEndpoint; |
|
|
|
import org.springframework.jms.config.MethodJmsListenerEndpoint; |
|
|
|
import org.springframework.jms.listener.SimpleMessageListenerContainer; |
|
|
|
import org.springframework.jms.listener.SimpleMessageListenerContainer; |
|
|
|
|
|
|
|
import org.springframework.messaging.handler.annotation.Header; |
|
|
|
import org.springframework.messaging.handler.annotation.SendTo; |
|
|
|
import org.springframework.messaging.handler.annotation.SendTo; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.transaction.PlatformTransactionManager; |
|
|
|
import org.springframework.transaction.PlatformTransactionManager; |
|
|
|
@ -73,8 +74,10 @@ public class JmsListenerAnnotationBeanPostProcessorTests { |
|
|
|
assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass()); |
|
|
|
assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass()); |
|
|
|
MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint; |
|
|
|
MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint; |
|
|
|
assertEquals(SimpleMessageListenerTestBean.class, methodEndpoint.getBean().getClass()); |
|
|
|
assertEquals(SimpleMessageListenerTestBean.class, methodEndpoint.getBean().getClass()); |
|
|
|
assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMethod()); |
|
|
|
assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class), |
|
|
|
assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMostSpecificMethod()); |
|
|
|
methodEndpoint.getMethod()); |
|
|
|
|
|
|
|
assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class), |
|
|
|
|
|
|
|
methodEndpoint.getMostSpecificMethod()); |
|
|
|
|
|
|
|
|
|
|
|
SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer(); |
|
|
|
SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer(); |
|
|
|
methodEndpoint.setupListenerContainer(listenerContainer); |
|
|
|
methodEndpoint.setupListenerContainer(listenerContainer); |
|
|
|
@ -98,8 +101,10 @@ public class JmsListenerAnnotationBeanPostProcessorTests { |
|
|
|
assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass()); |
|
|
|
assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass()); |
|
|
|
MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint; |
|
|
|
MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint; |
|
|
|
assertEquals(MetaAnnotationTestBean.class, methodEndpoint.getBean().getClass()); |
|
|
|
assertEquals(MetaAnnotationTestBean.class, methodEndpoint.getBean().getClass()); |
|
|
|
assertEquals(MetaAnnotationTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMethod()); |
|
|
|
assertEquals(MetaAnnotationTestBean.class.getMethod("handleIt", String.class), |
|
|
|
assertEquals(MetaAnnotationTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMostSpecificMethod()); |
|
|
|
methodEndpoint.getMethod()); |
|
|
|
|
|
|
|
assertEquals(MetaAnnotationTestBean.class.getMethod("handleIt", String.class), |
|
|
|
|
|
|
|
methodEndpoint.getMostSpecificMethod()); |
|
|
|
assertEquals("metaTestQueue", ((AbstractJmsListenerEndpoint) endpoint).getDestination()); |
|
|
|
assertEquals("metaTestQueue", ((AbstractJmsListenerEndpoint) endpoint).getDestination()); |
|
|
|
} |
|
|
|
} |
|
|
|
finally { |
|
|
|
finally { |
|
|
|
@ -108,9 +113,9 @@ public class JmsListenerAnnotationBeanPostProcessorTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void sendToAnnotationFoundOnProxy() throws Exception { |
|
|
|
public void sendToAnnotationFoundOnInterfaceProxy() throws Exception { |
|
|
|
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext( |
|
|
|
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext( |
|
|
|
Config.class, ProxyConfig.class, ProxyTestBean.class); |
|
|
|
Config.class, ProxyConfig.class, InterfaceProxyTestBean.class); |
|
|
|
try { |
|
|
|
try { |
|
|
|
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class); |
|
|
|
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class); |
|
|
|
assertEquals("one container should have been registered", 1, factory.getListenerContainers().size()); |
|
|
|
assertEquals("one container should have been registered", 1, factory.getListenerContainers().size()); |
|
|
|
@ -120,12 +125,42 @@ public class JmsListenerAnnotationBeanPostProcessorTests { |
|
|
|
MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint; |
|
|
|
MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint; |
|
|
|
assertTrue(AopUtils.isJdkDynamicProxy(methodEndpoint.getBean())); |
|
|
|
assertTrue(AopUtils.isJdkDynamicProxy(methodEndpoint.getBean())); |
|
|
|
assertTrue(methodEndpoint.getBean() instanceof SimpleService); |
|
|
|
assertTrue(methodEndpoint.getBean() instanceof SimpleService); |
|
|
|
assertEquals(SimpleService.class.getMethod("handleIt", String.class), methodEndpoint.getMethod()); |
|
|
|
assertEquals(SimpleService.class.getMethod("handleIt", String.class, String.class), |
|
|
|
assertEquals(ProxyTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMostSpecificMethod()); |
|
|
|
methodEndpoint.getMethod()); |
|
|
|
|
|
|
|
assertEquals(InterfaceProxyTestBean.class.getMethod("handleIt", String.class, String.class), |
|
|
|
|
|
|
|
methodEndpoint.getMostSpecificMethod()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Method method = ReflectionUtils.findMethod(endpoint.getClass(), "getDefaultResponseDestination"); |
|
|
|
|
|
|
|
ReflectionUtils.makeAccessible(method); |
|
|
|
|
|
|
|
Object destination = ReflectionUtils.invokeMethod(method, endpoint); |
|
|
|
|
|
|
|
assertEquals("SendTo annotation not found on proxy", "foobar", destination); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
finally { |
|
|
|
|
|
|
|
context.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void sendToAnnotationFoundOnCglibProxy() throws Exception { |
|
|
|
|
|
|
|
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext( |
|
|
|
|
|
|
|
Config.class, ProxyConfig.class, ClassProxyTestBean.class); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class); |
|
|
|
|
|
|
|
assertEquals("one container should have been registered", 1, factory.getListenerContainers().size()); |
|
|
|
|
|
|
|
|
|
|
|
Method m = ReflectionUtils.findMethod(endpoint.getClass(), "getDefaultResponseDestination"); |
|
|
|
JmsListenerEndpoint endpoint = factory.getListenerContainers().get(0).getEndpoint(); |
|
|
|
ReflectionUtils.makeAccessible(m); |
|
|
|
assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass()); |
|
|
|
Object destination = ReflectionUtils.invokeMethod(m, endpoint); |
|
|
|
MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint; |
|
|
|
|
|
|
|
assertTrue(AopUtils.isCglibProxy(methodEndpoint.getBean())); |
|
|
|
|
|
|
|
assertTrue(methodEndpoint.getBean() instanceof ClassProxyTestBean); |
|
|
|
|
|
|
|
assertEquals(ClassProxyTestBean.class.getMethod("handleIt", String.class, String.class), |
|
|
|
|
|
|
|
methodEndpoint.getMethod()); |
|
|
|
|
|
|
|
assertEquals(ClassProxyTestBean.class.getMethod("handleIt", String.class, String.class), |
|
|
|
|
|
|
|
methodEndpoint.getMostSpecificMethod()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Method method = ReflectionUtils.findMethod(endpoint.getClass(), "getDefaultResponseDestination"); |
|
|
|
|
|
|
|
ReflectionUtils.makeAccessible(method); |
|
|
|
|
|
|
|
Object destination = ReflectionUtils.invokeMethod(method, endpoint); |
|
|
|
assertEquals("SendTo annotation not found on proxy", "foobar", destination); |
|
|
|
assertEquals("SendTo annotation not found on proxy", "foobar", destination); |
|
|
|
} |
|
|
|
} |
|
|
|
finally { |
|
|
|
finally { |
|
|
|
@ -174,8 +209,8 @@ public class JmsListenerAnnotationBeanPostProcessorTests { |
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
public JmsListenerAnnotationBeanPostProcessor postProcessor() { |
|
|
|
public JmsListenerAnnotationBeanPostProcessor postProcessor() { |
|
|
|
JmsListenerAnnotationBeanPostProcessor postProcessor = new JmsListenerAnnotationBeanPostProcessor(); |
|
|
|
JmsListenerAnnotationBeanPostProcessor postProcessor = new JmsListenerAnnotationBeanPostProcessor(); |
|
|
|
postProcessor.setEndpointRegistry(jmsListenerEndpointRegistry()); |
|
|
|
|
|
|
|
postProcessor.setContainerFactoryBeanName("testFactory"); |
|
|
|
postProcessor.setContainerFactoryBeanName("testFactory"); |
|
|
|
|
|
|
|
postProcessor.setEndpointRegistry(jmsListenerEndpointRegistry()); |
|
|
|
return postProcessor; |
|
|
|
return postProcessor; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -204,18 +239,29 @@ public class JmsListenerAnnotationBeanPostProcessorTests { |
|
|
|
|
|
|
|
|
|
|
|
interface SimpleService { |
|
|
|
interface SimpleService { |
|
|
|
|
|
|
|
|
|
|
|
void handleIt(String body); |
|
|
|
void handleIt(String value, String body); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Component |
|
|
|
@Component |
|
|
|
static class ProxyTestBean implements SimpleService { |
|
|
|
static class InterfaceProxyTestBean implements SimpleService { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
@Transactional |
|
|
|
@JmsListener(destination = "testQueue") |
|
|
|
@JmsListener(destination = "testQueue") |
|
|
|
@SendTo("foobar") |
|
|
|
@SendTo("foobar") |
|
|
|
public void handleIt(String body) { |
|
|
|
public void handleIt(@Header String value, String body) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Component |
|
|
|
|
|
|
|
static class ClassProxyTestBean { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional |
|
|
|
|
|
|
|
@JmsListener(destination = "testQueue") |
|
|
|
|
|
|
|
@SendTo("foobar") |
|
|
|
|
|
|
|
public void handleIt(@Header String value, String body) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -224,7 +270,7 @@ public class JmsListenerAnnotationBeanPostProcessorTests { |
|
|
|
static class InvalidProxyTestBean implements SimpleService { |
|
|
|
static class InvalidProxyTestBean implements SimpleService { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void handleIt(String body) { |
|
|
|
public void handleIt(String value, String body) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Transactional |
|
|
|
@Transactional |
|
|
|
|