1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
39
39
import org .springframework .jms .config .MessageListenerTestContainer ;
40
40
import org .springframework .jms .config .MethodJmsListenerEndpoint ;
41
41
import org .springframework .jms .listener .SimpleMessageListenerContainer ;
42
+ import org .springframework .messaging .handler .annotation .Header ;
42
43
import org .springframework .messaging .handler .annotation .SendTo ;
43
44
import org .springframework .stereotype .Component ;
44
45
import org .springframework .transaction .PlatformTransactionManager ;
@@ -73,8 +74,10 @@ public void simpleMessageListener() throws Exception {
73
74
assertEquals ("Wrong endpoint type" , MethodJmsListenerEndpoint .class , endpoint .getClass ());
74
75
MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint ) endpoint ;
75
76
assertEquals (SimpleMessageListenerTestBean .class , methodEndpoint .getBean ().getClass ());
76
- assertEquals (SimpleMessageListenerTestBean .class .getMethod ("handleIt" , String .class ), methodEndpoint .getMethod ());
77
- assertEquals (SimpleMessageListenerTestBean .class .getMethod ("handleIt" , String .class ), methodEndpoint .getMostSpecificMethod ());
77
+ assertEquals (SimpleMessageListenerTestBean .class .getMethod ("handleIt" , String .class ),
78
+ methodEndpoint .getMethod ());
79
+ assertEquals (SimpleMessageListenerTestBean .class .getMethod ("handleIt" , String .class ),
80
+ methodEndpoint .getMostSpecificMethod ());
78
81
79
82
SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer ();
80
83
methodEndpoint .setupListenerContainer (listenerContainer );
@@ -98,8 +101,10 @@ public void metaAnnotationIsDiscovered() throws Exception {
98
101
assertEquals ("Wrong endpoint type" , MethodJmsListenerEndpoint .class , endpoint .getClass ());
99
102
MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint ) endpoint ;
100
103
assertEquals (MetaAnnotationTestBean .class , methodEndpoint .getBean ().getClass ());
101
- assertEquals (MetaAnnotationTestBean .class .getMethod ("handleIt" , String .class ), methodEndpoint .getMethod ());
102
- assertEquals (MetaAnnotationTestBean .class .getMethod ("handleIt" , String .class ), methodEndpoint .getMostSpecificMethod ());
104
+ assertEquals (MetaAnnotationTestBean .class .getMethod ("handleIt" , String .class ),
105
+ methodEndpoint .getMethod ());
106
+ assertEquals (MetaAnnotationTestBean .class .getMethod ("handleIt" , String .class ),
107
+ methodEndpoint .getMostSpecificMethod ());
103
108
assertEquals ("metaTestQueue" , ((AbstractJmsListenerEndpoint ) endpoint ).getDestination ());
104
109
}
105
110
finally {
@@ -108,9 +113,9 @@ public void metaAnnotationIsDiscovered() throws Exception {
108
113
}
109
114
110
115
@ Test
111
- public void sendToAnnotationFoundOnProxy () throws Exception {
116
+ public void sendToAnnotationFoundOnInterfaceProxy () throws Exception {
112
117
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext (
113
- Config .class , ProxyConfig .class , ProxyTestBean .class );
118
+ Config .class , ProxyConfig .class , InterfaceProxyTestBean .class );
114
119
try {
115
120
JmsListenerContainerTestFactory factory = context .getBean (JmsListenerContainerTestFactory .class );
116
121
assertEquals ("one container should have been registered" , 1 , factory .getListenerContainers ().size ());
@@ -120,12 +125,42 @@ public void sendToAnnotationFoundOnProxy() throws Exception {
120
125
MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint ) endpoint ;
121
126
assertTrue (AopUtils .isJdkDynamicProxy (methodEndpoint .getBean ()));
122
127
assertTrue (methodEndpoint .getBean () instanceof SimpleService );
123
- assertEquals (SimpleService .class .getMethod ("handleIt" , String .class ), methodEndpoint .getMethod ());
124
- assertEquals (ProxyTestBean .class .getMethod ("handleIt" , String .class ), methodEndpoint .getMostSpecificMethod ());
128
+ assertEquals (SimpleService .class .getMethod ("handleIt" , String .class , String .class ),
129
+ methodEndpoint .getMethod ());
130
+ assertEquals (InterfaceProxyTestBean .class .getMethod ("handleIt" , String .class , String .class ),
131
+ methodEndpoint .getMostSpecificMethod ());
132
+
133
+ Method method = ReflectionUtils .findMethod (endpoint .getClass (), "getDefaultResponseDestination" );
134
+ ReflectionUtils .makeAccessible (method );
135
+ Object destination = ReflectionUtils .invokeMethod (method , endpoint );
136
+ assertEquals ("SendTo annotation not found on proxy" , "foobar" , destination );
137
+ }
138
+ finally {
139
+ context .close ();
140
+ }
141
+ }
142
+
143
+ @ Test
144
+ public void sendToAnnotationFoundOnCglibProxy () throws Exception {
145
+ ConfigurableApplicationContext context = new AnnotationConfigApplicationContext (
146
+ Config .class , ProxyConfig .class , ClassProxyTestBean .class );
147
+ try {
148
+ JmsListenerContainerTestFactory factory = context .getBean (JmsListenerContainerTestFactory .class );
149
+ assertEquals ("one container should have been registered" , 1 , factory .getListenerContainers ().size ());
125
150
126
- Method m = ReflectionUtils .findMethod (endpoint .getClass (), "getDefaultResponseDestination" );
127
- ReflectionUtils .makeAccessible (m );
128
- Object destination = ReflectionUtils .invokeMethod (m , endpoint );
151
+ JmsListenerEndpoint endpoint = factory .getListenerContainers ().get (0 ).getEndpoint ();
152
+ assertEquals ("Wrong endpoint type" , MethodJmsListenerEndpoint .class , endpoint .getClass ());
153
+ MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint ) endpoint ;
154
+ assertTrue (AopUtils .isCglibProxy (methodEndpoint .getBean ()));
155
+ assertTrue (methodEndpoint .getBean () instanceof ClassProxyTestBean );
156
+ assertEquals (ClassProxyTestBean .class .getMethod ("handleIt" , String .class , String .class ),
157
+ methodEndpoint .getMethod ());
158
+ assertEquals (ClassProxyTestBean .class .getMethod ("handleIt" , String .class , String .class ),
159
+ methodEndpoint .getMostSpecificMethod ());
160
+
161
+ Method method = ReflectionUtils .findMethod (endpoint .getClass (), "getDefaultResponseDestination" );
162
+ ReflectionUtils .makeAccessible (method );
163
+ Object destination = ReflectionUtils .invokeMethod (method , endpoint );
129
164
assertEquals ("SendTo annotation not found on proxy" , "foobar" , destination );
130
165
}
131
166
finally {
@@ -174,8 +209,8 @@ static class Config {
174
209
@ Bean
175
210
public JmsListenerAnnotationBeanPostProcessor postProcessor () {
176
211
JmsListenerAnnotationBeanPostProcessor postProcessor = new JmsListenerAnnotationBeanPostProcessor ();
177
- postProcessor .setEndpointRegistry (jmsListenerEndpointRegistry ());
178
212
postProcessor .setContainerFactoryBeanName ("testFactory" );
213
+ postProcessor .setEndpointRegistry (jmsListenerEndpointRegistry ());
179
214
return postProcessor ;
180
215
}
181
216
@@ -204,18 +239,29 @@ public PlatformTransactionManager transactionManager() {
204
239
205
240
interface SimpleService {
206
241
207
- void handleIt (String body );
242
+ void handleIt (String value , String body );
208
243
}
209
244
210
245
211
246
@ Component
212
- static class ProxyTestBean implements SimpleService {
247
+ static class InterfaceProxyTestBean implements SimpleService {
213
248
214
249
@ Override
215
250
@ Transactional
216
251
@ JmsListener (destination = "testQueue" )
217
252
@ SendTo ("foobar" )
218
- public void handleIt (String body ) {
253
+ public void handleIt (@ Header String value , String body ) {
254
+ }
255
+ }
256
+
257
+
258
+ @ Component
259
+ static class ClassProxyTestBean {
260
+
261
+ @ Transactional
262
+ @ JmsListener (destination = "testQueue" )
263
+ @ SendTo ("foobar" )
264
+ public void handleIt (@ Header String value , String body ) {
219
265
}
220
266
}
221
267
@@ -224,7 +270,7 @@ public void handleIt(String body) {
224
270
static class InvalidProxyTestBean implements SimpleService {
225
271
226
272
@ Override
227
- public void handleIt (String body ) {
273
+ public void handleIt (String value , String body ) {
228
274
}
229
275
230
276
@ Transactional
0 commit comments