1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.web.servlet.mvc.method.annotation;
18
19 import java.util.concurrent.Callable;
20
21 import org.springframework.core.MethodParameter;
22 import org.springframework.web.context.request.NativeWebRequest;
23 import org.springframework.web.context.request.async.WebAsyncUtils;
24 import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
25 import org.springframework.web.method.support.ModelAndViewContainer;
26
27
28
29
30
31
32
33 public class CallableMethodReturnValueHandler implements HandlerMethodReturnValueHandler {
34
35 @Override
36 public boolean supportsReturnType(MethodParameter returnType) {
37 return Callable.class.isAssignableFrom(returnType.getParameterType());
38 }
39
40 @Override
41 public void handleReturnValue(Object returnValue, MethodParameter returnType,
42 ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
43
44 if (returnValue == null) {
45 mavContainer.setRequestHandled(true);
46 return;
47 }
48
49 Callable<?> callable = (Callable<?>) returnValue;
50 WebAsyncUtils.getAsyncManager(webRequest).startCallableProcessing(callable, mavContainer);
51 }
52
53 }