Skip to content

Commit 90ae073

Browse files
committed
Relaxed final declarations and protected doInvoke methods
Issue: SPR-12484 (cherry picked from commit 2496d68)
1 parent 50c578c commit 90ae073

File tree

3 files changed

+49
-44
lines changed

3 files changed

+49
-44
lines changed

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

+10-6
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@
2929
import org.springframework.util.ReflectionUtils;
3030

3131
/**
32-
* Invokes the handler method for a given message after resolving
33-
* its method argument values through registered {@link HandlerMethodArgumentResolver}s.
32+
* Invokes the handler method for a given message after resolving its method argument
33+
* values through registered {@link HandlerMethodArgumentResolver}s.
3434
*
3535
* <p>Use {@link #setMessageMethodArgumentResolvers(HandlerMethodArgumentResolverComposite)}
3636
* to customize the list of argument resolvers.
3737
*
3838
* @author Rossen Stoyanchev
39+
* @author Juergen Hoeller
3940
* @since 4.0
4041
*/
4142
public class InvocableHandlerMethod extends HandlerMethod {
@@ -66,7 +67,9 @@ public InvocableHandlerMethod(Object bean, Method method) {
6667
* @param parameterTypes the method parameter types
6768
* @throws NoSuchMethodException when the method cannot be found
6869
*/
69-
public InvocableHandlerMethod(Object bean, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException {
70+
public InvocableHandlerMethod(Object bean, String methodName, Class<?>... parameterTypes)
71+
throws NoSuchMethodException {
72+
7073
super(bean, methodName, parameterTypes);
7174
}
7275

@@ -93,7 +96,7 @@ public void setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDisc
9396
* @throws Exception raised if no suitable argument resolver can be found,
9497
* or the method raised an exception
9598
*/
96-
public final Object invoke(Message<?> message, Object... providedArgs) throws Exception {
99+
public Object invoke(Message<?> message, Object... providedArgs) throws Exception {
97100
Object[] args = getMethodArgumentValues(message, providedArgs);
98101
if (logger.isTraceEnabled()) {
99102
StringBuilder sb = new StringBuilder("Invoking [");
@@ -102,7 +105,7 @@ public final Object invoke(Message<?> message, Object... providedArgs) throws Ex
102105
sb.append(Arrays.asList(args));
103106
logger.trace(sb.toString());
104107
}
105-
Object returnValue = invoke(args);
108+
Object returnValue = doInvoke(args);
106109
if (logger.isTraceEnabled()) {
107110
logger.trace("Method [" + getMethod().getName() + "] returned [" + returnValue + "]");
108111
}
@@ -176,10 +179,11 @@ private Object resolveProvidedArgument(MethodParameter parameter, Object... prov
176179
return null;
177180
}
178181

182+
179183
/**
180184
* Invoke the handler method with the given argument values.
181185
*/
182-
private Object invoke(Object... args) throws Exception {
186+
protected Object doInvoke(Object... args) throws Exception {
183187
ReflectionUtils.makeAccessible(getBridgedMethod());
184188
try {
185189
return getBridgedMethod().invoke(getBean(), args);

spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java

+23-17
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,18 @@
3232
import org.springframework.web.method.HandlerMethod;
3333

3434
/**
35-
* Provides a method for invoking the handler method for a given request after resolving its method argument
36-
* values through registered {@link HandlerMethodArgumentResolver}s.
35+
* Provides a method for invoking the handler method for a given request after resolving its
36+
* method argument values through registered {@link HandlerMethodArgumentResolver}s.
3737
*
38-
* <p>Argument resolution often requires a {@link WebDataBinder} for data binding or for type conversion.
39-
* Use the {@link #setDataBinderFactory(WebDataBinderFactory)} property to supply a binder factory to pass to
40-
* argument resolvers.
38+
* <p>Argument resolution often requires a {@link WebDataBinder} for data binding or for type
39+
* conversion. Use the {@link #setDataBinderFactory(WebDataBinderFactory)} property to supply
40+
* a binder factory to pass to argument resolvers.
4141
*
42-
* <p>Use {@link #setHandlerMethodArgumentResolvers(HandlerMethodArgumentResolverComposite)} to customize
43-
* the list of argument resolvers.
42+
* <p>Use {@link #setHandlerMethodArgumentResolvers(HandlerMethodArgumentResolverComposite)}
43+
* to customize the list of argument resolvers.
4444
*
4545
* @author Rossen Stoyanchev
46+
* @author Juergen Hoeller
4647
* @since 3.1
4748
*/
4849
public class InvocableHandlerMethod extends HandlerMethod {
@@ -75,7 +76,9 @@ public InvocableHandlerMethod(HandlerMethod handlerMethod) {
7576
* @param parameterTypes the method parameter types
7677
* @throws NoSuchMethodException when the method cannot be found
7778
*/
78-
public InvocableHandlerMethod(Object bean, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException {
79+
public InvocableHandlerMethod(Object bean, String methodName, Class<?>... parameterTypes)
80+
throws NoSuchMethodException {
81+
7982
super(bean, methodName, parameterTypes);
8083
}
8184

@@ -107,18 +110,20 @@ public void setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDisc
107110

108111

109112
/**
110-
* Invoke the method after resolving its argument values in the context of the given request. <p>Argument
111-
* values are commonly resolved through {@link HandlerMethodArgumentResolver}s. The {@code provideArgs}
112-
* parameter however may supply argument values to be used directly, i.e. without argument resolution.
113-
* Examples of provided argument values include a {@link WebDataBinder}, a {@link SessionStatus}, or
114-
* a thrown exception instance. Provided argument values are checked before argument resolvers.
113+
* Invoke the method after resolving its argument values in the context of the given request.
114+
* <p>Argument values are commonly resolved through {@link HandlerMethodArgumentResolver}s.
115+
* The {@code provideArgs} parameter however may supply argument values to be used directly,
116+
* i.e. without argument resolution. Examples of provided argument values include a
117+
* {@link WebDataBinder}, a {@link SessionStatus}, or a thrown exception instance.
118+
* Provided argument values are checked before argument resolvers.
115119
* @param request the current request
116120
* @param mavContainer the ModelAndViewContainer for this request
117121
* @param providedArgs "given" arguments matched by type, not resolved
118122
* @return the raw value returned by the invoked method
119-
* @exception Exception raised if no suitable argument resolver can be found, or the method raised an exception
123+
* @exception Exception raised if no suitable argument resolver can be found,
124+
* or if the method raised an exception
120125
*/
121-
public final Object invokeForRequest(NativeWebRequest request, ModelAndViewContainer mavContainer,
126+
public Object invokeForRequest(NativeWebRequest request, ModelAndViewContainer mavContainer,
122127
Object... providedArgs) throws Exception {
123128

124129
Object[] args = getMethodArgumentValues(request, mavContainer, providedArgs);
@@ -129,7 +134,7 @@ public final Object invokeForRequest(NativeWebRequest request, ModelAndViewConta
129134
sb.append(Arrays.asList(args));
130135
logger.trace(sb.toString());
131136
}
132-
Object returnValue = invoke(args);
137+
Object returnValue = doInvoke(args);
133138
if (logger.isTraceEnabled()) {
134139
logger.trace("Method [" + getMethod().getName() + "] returned [" + returnValue + "]");
135140
}
@@ -206,10 +211,11 @@ private Object resolveProvidedArgument(MethodParameter parameter, Object... prov
206211
return null;
207212
}
208213

214+
209215
/**
210216
* Invoke the handler method with the given argument values.
211217
*/
212-
private Object invoke(Object... args) throws Exception {
218+
protected Object doInvoke(Object... args) throws Exception {
213219
ReflectionUtils.makeAccessible(getBridgedMethod());
214220
try {
215221
return getBridgedMethod().invoke(getBean(), args);

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java

+16-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -75,13 +75,14 @@ public ServletInvocableHandlerMethod(HandlerMethod handlerMethod) {
7575
}
7676

7777
private void initResponseStatus() {
78-
ResponseStatus annot = getMethodAnnotation(ResponseStatus.class);
79-
if (annot != null) {
80-
this.responseStatus = annot.value();
81-
this.responseReason = annot.reason();
78+
ResponseStatus annotation = getMethodAnnotation(ResponseStatus.class);
79+
if (annotation != null) {
80+
this.responseStatus = annotation.value();
81+
this.responseReason = annotation.reason();
8282
}
8383
}
8484

85+
8586
/**
8687
* Register {@link HandlerMethodReturnValueHandler} instances to use to
8788
* handle return values.
@@ -91,18 +92,16 @@ public void setHandlerMethodReturnValueHandlers(HandlerMethodReturnValueHandlerC
9192
}
9293

9394
/**
94-
* Invokes the method and handles the return value through a registered
95-
* {@link HandlerMethodReturnValueHandler}.
96-
*
95+
* Invokes the method and handles the return value through one of the
96+
* configured {@link HandlerMethodReturnValueHandler}s.
9797
* @param webRequest the current request
9898
* @param mavContainer the ModelAndViewContainer for this request
99-
* @param providedArgs "given" arguments matched by type, not resolved
99+
* @param providedArgs "given" arguments matched by type (not resolved)
100100
*/
101-
public final void invokeAndHandle(ServletWebRequest webRequest,
101+
public void invokeAndHandle(ServletWebRequest webRequest,
102102
ModelAndViewContainer mavContainer, Object... providedArgs) throws Exception {
103103

104104
Object returnValue = invokeForRequest(webRequest, mavContainer, providedArgs);
105-
106105
setResponseStatus(webRequest);
107106

108107
if (returnValue == null) {
@@ -117,9 +116,9 @@ else if (StringUtils.hasText(this.responseReason)) {
117116
}
118117

119118
mavContainer.setRequestHandled(false);
120-
121119
try {
122-
this.returnValueHandlers.handleReturnValue(returnValue, getReturnValueType(returnValue), mavContainer, webRequest);
120+
this.returnValueHandlers.handleReturnValue(
121+
returnValue, getReturnValueType(returnValue), mavContainer, webRequest);
123122
}
124123
catch (Exception ex) {
125124
if (logger.isTraceEnabled()) {
@@ -136,14 +135,12 @@ private void setResponseStatus(ServletWebRequest webRequest) throws IOException
136135
if (this.responseStatus == null) {
137136
return;
138137
}
139-
140138
if (StringUtils.hasText(this.responseReason)) {
141139
webRequest.getResponse().sendError(this.responseStatus.value(), this.responseReason);
142140
}
143141
else {
144142
webRequest.getResponse().setStatus(this.responseStatus.value());
145143
}
146-
147144
// to be picked up by the RedirectView
148145
webRequest.getRequest().setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, this.responseStatus);
149146
}
@@ -161,15 +158,15 @@ private boolean isRequestNotModified(ServletWebRequest webRequest) {
161158
* Does this method have the response status instruction?
162159
*/
163160
private boolean hasResponseStatus() {
164-
return responseStatus != null;
161+
return (this.responseStatus != null);
165162
}
166163

167164
private String getReturnValueHandlingErrorMessage(String message, Object returnValue) {
168165
StringBuilder sb = new StringBuilder(message);
169166
if (returnValue != null) {
170-
sb.append(" [type=" + returnValue.getClass().getName() + "] ");
167+
sb.append(" [type=").append(returnValue.getClass().getName()).append("]");
171168
}
172-
sb.append("[value=" + returnValue + "]");
169+
sb.append(" [value=").append(returnValue).append("]");
173170
return getDetailedErrorMessage(sb.toString());
174171
}
175172

@@ -180,9 +177,7 @@ private String getReturnValueHandlingErrorMessage(String message, Object returnV
180177
* exception is raised if the async result value itself is an Exception.
181178
*/
182179
ServletInvocableHandlerMethod wrapConcurrentResult(final Object result) {
183-
184180
return new CallableHandlerMethod(new Callable<Object>() {
185-
186181
@Override
187182
public Object call() throws Exception {
188183
if (result instanceof Exception) {
@@ -209,7 +204,7 @@ private class CallableHandlerMethod extends ServletInvocableHandlerMethod {
209204

210205
public CallableHandlerMethod(Callable<?> callable) {
211206
super(callable, ClassUtils.getMethod(callable.getClass(), "call"));
212-
this.setHandlerMethodReturnValueHandlers(ServletInvocableHandlerMethod.this.returnValueHandlers);
207+
setHandlerMethodReturnValueHandlers(ServletInvocableHandlerMethod.this.returnValueHandlers);
213208
}
214209

215210
/**

0 commit comments

Comments
 (0)