1
1
/*
2
- * Copyright 2002-2015 the original author or authors.
2
+ * Copyright 2002-2016 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.
@@ -83,18 +83,10 @@ public abstract class AbstractMethodMessageHandler<T>
83
83
84
84
protected final Log logger = LogFactory .getLog (getClass ());
85
85
86
- private Collection <String > destinationPrefixes = new ArrayList <String >();
87
-
88
86
private final List <HandlerMethodArgumentResolver > customArgumentResolvers = new ArrayList <HandlerMethodArgumentResolver >(4 );
89
87
90
88
private final List <HandlerMethodReturnValueHandler > customReturnValueHandlers = new ArrayList <HandlerMethodReturnValueHandler >(4 );
91
89
92
- private HandlerMethodArgumentResolverComposite argumentResolvers = new HandlerMethodArgumentResolverComposite ();
93
-
94
- private HandlerMethodReturnValueHandlerComposite returnValueHandlers =new HandlerMethodReturnValueHandlerComposite ();
95
-
96
- private ApplicationContext applicationContext ;
97
-
98
90
private final Map <T , HandlerMethod > handlerMethods = new LinkedHashMap <T , HandlerMethod >();
99
91
100
92
private final MultiValueMap <String , T > destinationLookup = new LinkedMultiValueMap <String , T >();
@@ -105,6 +97,20 @@ public abstract class AbstractMethodMessageHandler<T>
105
97
private final Map <MessagingAdviceBean , AbstractExceptionHandlerMethodResolver > exceptionHandlerAdviceCache =
106
98
new LinkedHashMap <MessagingAdviceBean , AbstractExceptionHandlerMethodResolver >(64 );
107
99
100
+ private Collection <String > destinationPrefixes = new ArrayList <String >();
101
+
102
+ private HandlerMethodArgumentResolverComposite argumentResolvers = new HandlerMethodArgumentResolverComposite ();
103
+
104
+ private HandlerMethodReturnValueHandlerComposite returnValueHandlers =new HandlerMethodReturnValueHandlerComposite ();
105
+
106
+ private ApplicationContext applicationContext ;
107
+
108
+ /**
109
+ * Return the configured destination prefixes.
110
+ */
111
+ public Collection <String > getDestinationPrefixes () {
112
+ return this .destinationPrefixes ;
113
+ }
108
114
109
115
/**
110
116
* When this property is configured only messages to destinations matching
@@ -125,10 +131,10 @@ public void setDestinationPrefixes(Collection<String> prefixes) {
125
131
}
126
132
127
133
/**
128
- * Return the configured destination prefixes .
134
+ * Return the configured custom argument resolvers, if any .
129
135
*/
130
- public Collection < String > getDestinationPrefixes () {
131
- return this .destinationPrefixes ;
136
+ public List < HandlerMethodArgumentResolver > getCustomArgumentResolvers () {
137
+ return this .customArgumentResolvers ;
132
138
}
133
139
134
140
/**
@@ -144,10 +150,10 @@ public void setCustomArgumentResolvers(List<HandlerMethodArgumentResolver> custo
144
150
}
145
151
146
152
/**
147
- * Return the configured custom argument resolvers , if any.
153
+ * Return the configured custom return value handlers , if any.
148
154
*/
149
- public List <HandlerMethodArgumentResolver > getCustomArgumentResolvers () {
150
- return this .customArgumentResolvers ;
155
+ public List <HandlerMethodReturnValueHandler > getCustomReturnValueHandlers () {
156
+ return this .customReturnValueHandlers ;
151
157
}
152
158
153
159
/**
@@ -162,11 +168,8 @@ public void setCustomReturnValueHandlers(List<HandlerMethodReturnValueHandler> c
162
168
}
163
169
}
164
170
165
- /**
166
- * Return the configured custom return value handlers, if any.
167
- */
168
- public List <HandlerMethodReturnValueHandler > getCustomReturnValueHandlers () {
169
- return this .customReturnValueHandlers ;
171
+ public List <HandlerMethodArgumentResolver > getArgumentResolvers () {
172
+ return this .argumentResolvers .getResolvers ();
170
173
}
171
174
172
175
/**
@@ -182,8 +185,8 @@ public void setArgumentResolvers(List<HandlerMethodArgumentResolver> argumentRes
182
185
this .argumentResolvers .addResolvers (argumentResolvers );
183
186
}
184
187
185
- public List <HandlerMethodArgumentResolver > getArgumentResolvers () {
186
- return this .argumentResolvers . getResolvers ();
188
+ public List <HandlerMethodReturnValueHandler > getReturnValueHandlers () {
189
+ return this .returnValueHandlers . getReturnValueHandlers ();
187
190
}
188
191
189
192
/**
@@ -199,26 +202,21 @@ public void setReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnV
199
202
this .returnValueHandlers .addHandlers (returnValueHandlers );
200
203
}
201
204
202
- public List <HandlerMethodReturnValueHandler > getReturnValueHandlers () {
203
- return this .returnValueHandlers .getReturnValueHandlers ();
204
- }
205
-
206
205
/**
207
206
* Return a map with all handler methods and their mappings.
208
207
*/
209
208
public Map <T , HandlerMethod > getHandlerMethods () {
210
209
return Collections .unmodifiableMap (this .handlerMethods );
211
210
}
212
211
213
- @ Override
214
- public void setApplicationContext (ApplicationContext applicationContext ) {
215
- this .applicationContext = applicationContext ;
216
- }
217
-
218
212
public ApplicationContext getApplicationContext () {
219
213
return this .applicationContext ;
220
214
}
221
215
216
+ @ Override
217
+ public void setApplicationContext (ApplicationContext applicationContext ) {
218
+ this .applicationContext = applicationContext ;
219
+ }
222
220
223
221
@ Override
224
222
public void afterPropertiesSet () {
@@ -434,7 +432,7 @@ protected void handleMessageInternal(Message<?> message, String lookupDestinatio
434
432
Collections .sort (matches , comparator );
435
433
436
434
if (logger .isTraceEnabled ()) {
437
- logger .trace ("Found " + matches .size () + " methods: " + matches );
435
+ logger .trace ("Found " + matches .size () + " handler methods: " + matches );
438
436
}
439
437
440
438
Match bestMatch = matches .get (0 );
@@ -472,7 +470,7 @@ private void addMatchesToCollection(Collection<T> mappingsToCheck, Message<?> me
472
470
473
471
474
472
protected void handleNoMatch (Set <T > ts , String lookupDestination , Message <?> message ) {
475
- logger .debug ("No matching methods." );
473
+ logger .debug ("No matching message handler methods." );
476
474
}
477
475
478
476
/**
@@ -520,7 +518,7 @@ protected void handleMatch(T mapping, HandlerMethod handlerMethod, String lookup
520
518
protected void processHandlerMethodException (HandlerMethod handlerMethod , Exception ex , Message <?> message ) {
521
519
InvocableHandlerMethod invocable = getExceptionHandlerMethod (handlerMethod , ex );
522
520
if (invocable == null ) {
523
- logger .error ("Unhandled exception" , ex );
521
+ logger .error ("Unhandled exception from message handler method " , ex );
524
522
return ;
525
523
}
526
524
invocable .setMessageMethodArgumentResolvers (this .argumentResolvers );
@@ -598,7 +596,7 @@ private class Match {
598
596
599
597
private final HandlerMethod handlerMethod ;
600
598
601
- private Match (T mapping , HandlerMethod handlerMethod ) {
599
+ public Match (T mapping , HandlerMethod handlerMethod ) {
602
600
this .mapping = mapping ;
603
601
this .handlerMethod = handlerMethod ;
604
602
}
@@ -631,7 +629,6 @@ private class ReturnValueListenableFutureCallback implements ListenableFutureCal
631
629
632
630
private final Message <?> message ;
633
631
634
-
635
632
public ReturnValueListenableFutureCallback (InvocableHandlerMethod handlerMethod , Message <?> message ) {
636
633
this .handlerMethod = handlerMethod ;
637
634
this .message = message ;
@@ -654,7 +651,7 @@ public void onFailure(Throwable ex) {
654
651
}
655
652
656
653
private void handleFailure (Throwable ex ) {
657
- Exception cause = (ex instanceof Exception ? (Exception ) ex : new RuntimeException (ex ));
654
+ Exception cause = (ex instanceof Exception ? (Exception ) ex : new IllegalStateException (ex ));
658
655
processHandlerMethodException (this .handlerMethod , cause , this .message );
659
656
}
660
657
}
0 commit comments