Skip to content

Commit b204437

Browse files
committed
Polishing
1 parent e5122d0 commit b204437

File tree

3 files changed

+96
-81
lines changed

3 files changed

+96
-81
lines changed

spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,17 @@ public abstract class AbstractMethodMessageHandler<T>
8383

8484
protected final Log logger = LogFactory.getLog(getClass());
8585

86-
private final List<HandlerMethodArgumentResolver> customArgumentResolvers = new ArrayList<HandlerMethodArgumentResolver>(4);
86+
private final List<HandlerMethodArgumentResolver> customArgumentResolvers =
87+
new ArrayList<HandlerMethodArgumentResolver>(4);
8788

88-
private final List<HandlerMethodReturnValueHandler> customReturnValueHandlers = new ArrayList<HandlerMethodReturnValueHandler>(4);
89+
private final List<HandlerMethodReturnValueHandler> customReturnValueHandlers =
90+
new ArrayList<HandlerMethodReturnValueHandler>(4);
91+
92+
private final HandlerMethodArgumentResolverComposite argumentResolvers =
93+
new HandlerMethodArgumentResolverComposite();
94+
95+
private final HandlerMethodReturnValueHandlerComposite returnValueHandlers =
96+
new HandlerMethodReturnValueHandlerComposite();
8997

9098
private final Map<T, HandlerMethod> handlerMethods = new LinkedHashMap<T, HandlerMethod>();
9199

@@ -99,10 +107,6 @@ public abstract class AbstractMethodMessageHandler<T>
99107

100108
private Collection<String> destinationPrefixes = new ArrayList<String>();
101109

102-
private HandlerMethodArgumentResolverComposite argumentResolvers = new HandlerMethodArgumentResolverComposite();
103-
104-
private HandlerMethodReturnValueHandlerComposite returnValueHandlers =new HandlerMethodReturnValueHandlerComposite();
105-
106110
private ApplicationContext applicationContext;
107111

108112
/**
@@ -140,7 +144,6 @@ public List<HandlerMethodArgumentResolver> getCustomArgumentResolvers() {
140144
/**
141145
* Sets the list of custom {@code HandlerMethodArgumentResolver}s that will be used
142146
* after resolvers for supported argument type.
143-
* @param customArgumentResolvers the list of resolvers; never {@code null}.
144147
*/
145148
public void setCustomArgumentResolvers(List<HandlerMethodArgumentResolver> customArgumentResolvers) {
146149
this.customArgumentResolvers.clear();
@@ -159,7 +162,6 @@ public List<HandlerMethodReturnValueHandler> getCustomReturnValueHandlers() {
159162
/**
160163
* Set the list of custom {@code HandlerMethodReturnValueHandler}s that will be used
161164
* after return value handlers for known types.
162-
* @param customReturnValueHandlers the list of custom return value handlers, never {@code null}.
163165
*/
164166
public void setCustomReturnValueHandlers(List<HandlerMethodReturnValueHandler> customReturnValueHandlers) {
165167
this.customReturnValueHandlers.clear();
@@ -168,13 +170,16 @@ public void setCustomReturnValueHandlers(List<HandlerMethodReturnValueHandler> c
168170
}
169171
}
170172

173+
/**
174+
* Return the complete list of argument resolvers.
175+
*/
171176
public List<HandlerMethodArgumentResolver> getArgumentResolvers() {
172177
return this.argumentResolvers.getResolvers();
173178
}
174179

175180
/**
176-
* Configure the complete list of supported argument types effectively overriding
177-
* the ones configured by default. This is an advanced option. For most use cases
181+
* Configure the complete list of supported argument types, effectively overriding
182+
* the ones configured by default. This is an advanced option; for most use cases
178183
* it should be sufficient to use {@link #setCustomArgumentResolvers}.
179184
*/
180185
public void setArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
@@ -185,13 +190,16 @@ public void setArgumentResolvers(List<HandlerMethodArgumentResolver> argumentRes
185190
this.argumentResolvers.addResolvers(argumentResolvers);
186191
}
187192

193+
/**
194+
* Return the complete list of return value handlers.
195+
*/
188196
public List<HandlerMethodReturnValueHandler> getReturnValueHandlers() {
189197
return this.returnValueHandlers.getReturnValueHandlers();
190198
}
191199

192200
/**
193-
* Configure the complete list of supported return value types effectively overriding
194-
* the ones configured by default. This is an advanced option. For most use cases
201+
* Configure the complete list of supported return value types, effectively overriding
202+
* the ones configured by default. This is an advanced option; for most use cases
195203
* it should be sufficient to use {@link #setCustomReturnValueHandlers}.
196204
*/
197205
public void setReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
@@ -202,13 +210,6 @@ public void setReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnV
202210
this.returnValueHandlers.addHandlers(returnValueHandlers);
203211
}
204212

205-
/**
206-
* Return a map with all handler methods and their mappings.
207-
*/
208-
public Map<T, HandlerMethod> getHandlerMethods() {
209-
return Collections.unmodifiableMap(this.handlerMethods);
210-
}
211-
212213
public ApplicationContext getApplicationContext() {
213214
return this.applicationContext;
214215
}
@@ -360,10 +361,19 @@ protected HandlerMethod createHandlerMethod(Object handler, Method method) {
360361
* (e.g. to support "global" {@code @MessageExceptionHandler}).
361362
* @since 4.2
362363
*/
363-
protected void registerExceptionHandlerAdvice(MessagingAdviceBean bean, AbstractExceptionHandlerMethodResolver resolver) {
364+
protected void registerExceptionHandlerAdvice(
365+
MessagingAdviceBean bean, AbstractExceptionHandlerMethodResolver resolver) {
366+
364367
this.exceptionHandlerAdviceCache.put(bean, resolver);
365368
}
366369

370+
/**
371+
* Return a map with all handler methods and their mappings.
372+
*/
373+
public Map<T, HandlerMethod> getHandlerMethods() {
374+
return Collections.unmodifiableMap(this.handlerMethods);
375+
}
376+
367377

368378
@Override
369379
public void handleMessage(Message<?> message) throws MessagingException {
@@ -425,7 +435,7 @@ protected void handleMessageInternal(Message<?> message, String lookupDestinatio
425435
addMatchesToCollection(allMappings, message, matches);
426436
}
427437
if (matches.isEmpty()) {
428-
handleNoMatch(handlerMethods.keySet(), lookupDestination, message);
438+
handleNoMatch(this.handlerMethods.keySet(), lookupDestination, message);
429439
return;
430440
}
431441
Comparator<Match> comparator = new MatchComparator(getMappingComparator(message));
@@ -449,7 +459,6 @@ protected void handleMessageInternal(Message<?> message, String lookupDestinatio
449459
handleMatch(bestMatch.mapping, bestMatch.handlerMethod, lookupDestination, message);
450460
}
451461

452-
453462
private void addMatchesToCollection(Collection<T> mappingsToCheck, Message<?> message, List<Match> matches) {
454463
for (T mapping : mappingsToCheck) {
455464
T match = getMatchingMapping(mapping, message);
@@ -468,7 +477,6 @@ private void addMatchesToCollection(Collection<T> mappingsToCheck, Message<?> me
468477
*/
469478
protected abstract T getMatchingMapping(T mapping, Message<?> message);
470479

471-
472480
protected void handleNoMatch(Set<T> ts, String lookupDestination, Message<?> message) {
473481
logger.debug("No matching message handler methods.");
474482
}
@@ -481,7 +489,6 @@ protected void handleNoMatch(Set<T> ts, String lookupDestination, Message<?> mes
481489
*/
482490
protected abstract Comparator<T> getMappingComparator(Message<?> message);
483491

484-
485492
protected void handleMatch(T mapping, HandlerMethod handlerMethod, String lookupDestination, Message<?> message) {
486493
if (logger.isDebugEnabled()) {
487494
logger.debug("Invoking " + handlerMethod.getShortLogMessage());
@@ -579,6 +586,7 @@ protected InvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handler
579586
protected abstract AbstractExceptionHandlerMethodResolver createExceptionHandlerMethodResolverFor(
580587
Class<?> beanType);
581588

589+
582590
@Override
583591
public String toString() {
584592
return getClass().getSimpleName() + "[prefixes=" + getDestinationPrefixes() + "]";

spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,7 @@ private void ports(UriComponents uriComponents, MockHttpServletRequest request)
427427

428428
private UriComponents uriComponents() {
429429
URL url = this.webRequest.getUrl();
430-
UriComponentsBuilder uriBldr = UriComponentsBuilder.fromUriString(url.toExternalForm());
431-
return uriBldr.build();
430+
return UriComponentsBuilder.fromUriString(url.toExternalForm()).build();
432431
}
433432

434433
@Override
@@ -455,13 +454,14 @@ private CookieManager getCookieManager() {
455454
return this.webClient.getCookieManager();
456455
}
457456

457+
458458
/**
459-
* An extension to {@link MockHttpServletRequest} that ensures that
460-
* when a new {@link HttpSession} is created, it is added to the managed sessions.
459+
* An extension to {@link MockHttpServletRequest} that ensures that when a
460+
* new {@link HttpSession} is created, it is added to the managed sessions.
461461
*/
462462
private final class HtmlUnitMockHttpServletRequest extends MockHttpServletRequest {
463463

464-
private HtmlUnitMockHttpServletRequest(ServletContext servletContext, String method, String requestURI) {
464+
public HtmlUnitMockHttpServletRequest(ServletContext servletContext, String method, String requestURI) {
465465
super(servletContext, method, requestURI);
466466
}
467467

@@ -490,16 +490,17 @@ public void setSession(HttpSession session) {
490490
}
491491
}
492492

493+
493494
/**
494495
* An extension to {@link MockHttpSession} that ensures when
495-
* {@link #invalidate()} is called that the {@link HttpSession} is
496-
* removed from the managed sessions.
496+
* {@link #invalidate()} is called that the {@link HttpSession}
497+
* is removed from the managed sessions.
497498
*/
498499
private final class HtmlUnitMockHttpSession extends MockHttpSession {
499500

500501
private final MockHttpServletRequest request;
501502

502-
private HtmlUnitMockHttpSession(MockHttpServletRequest request) {
503+
public HtmlUnitMockHttpSession(MockHttpServletRequest request) {
503504
super(request.getServletContext());
504505
this.request = request;
505506
}

0 commit comments

Comments
 (0)