|
2 | 2 |
|
3 | 3 | import java.util.concurrent.Callable; |
4 | 4 |
|
| 5 | +import org.apache.log4j.Logger; |
5 | 6 | import org.baeldung.web.service.AsyncService; |
6 | 7 | import org.springframework.beans.factory.annotation.Autowired; |
7 | 8 | import org.springframework.security.core.context.SecurityContextHolder; |
8 | 9 | import org.springframework.stereotype.Controller; |
9 | 10 | import org.springframework.web.bind.annotation.RequestMapping; |
10 | 11 | import org.springframework.web.bind.annotation.RequestMethod; |
11 | 12 | import org.springframework.web.bind.annotation.ResponseBody; |
12 | | -import org.springframework.web.multipart.MultipartFile; |
13 | 13 |
|
14 | 14 | @Controller |
15 | 15 | public class AsyncController { |
16 | | - |
| 16 | + |
| 17 | + private static final Logger log = Logger.getLogger(AsyncService.class); |
| 18 | + |
17 | 19 | @Autowired |
18 | 20 | private AsyncService asyncService; |
19 | 21 |
|
20 | | - @RequestMapping(method = RequestMethod.POST, value = "/upload") |
21 | | - public Callable<Boolean> processUpload(final MultipartFile file) { |
22 | | - |
23 | | - return new Callable<Boolean>() { |
24 | | - public Boolean call() throws Exception { |
25 | | - // ... |
26 | | - return true; |
27 | | - } |
28 | | - }; |
| 22 | + @RequestMapping(method = RequestMethod.GET, value = "/async") |
| 23 | + @ResponseBody |
| 24 | + public Object standardProcessing() throws Exception { |
| 25 | + log.info("Outside the @Async logic - before the async call: " |
| 26 | + + SecurityContextHolder.getContext().getAuthentication().getPrincipal()); |
| 27 | + asyncService.asyncCall(); |
| 28 | + log.info("Inside the @Async logic - after the async call: " |
| 29 | + + SecurityContextHolder.getContext().getAuthentication().getPrincipal()); |
| 30 | + return SecurityContextHolder.getContext().getAuthentication().getPrincipal(); |
29 | 31 | } |
30 | 32 |
|
31 | | - @RequestMapping(method = RequestMethod.GET, value = "/async") |
| 33 | + @RequestMapping(method = RequestMethod.GET, value = "/async2") |
32 | 34 | @ResponseBody |
33 | | - public Boolean checkIfContextPropagated() throws Exception{ |
34 | | - return asyncService.checkIfPrincipalPropagated().call() && asyncService.checkIfContextPropagated(SecurityContextHolder.getContext()); |
| 35 | + public Callable<Boolean> springMVCAsyncTest() { |
| 36 | + return asyncService.checkIfPrincipalPropagated(); |
35 | 37 | } |
36 | 38 |
|
37 | 39 | } |
0 commit comments