|
25 | 25 | import java.util.List; |
26 | 26 | import java.util.concurrent.CountDownLatch; |
27 | 27 |
|
| 28 | +import jakarta.servlet.AsyncContext; |
28 | 29 | import jakarta.servlet.Filter; |
29 | 30 | import jakarta.servlet.FilterChain; |
30 | 31 | import jakarta.servlet.FilterConfig; |
|
49 | 50 | import org.springframework.util.ObjectUtils; |
50 | 51 | import org.springframework.util.StringUtils; |
51 | 52 | import org.springframework.web.context.ConfigurableWebApplicationContext; |
52 | | -import org.springframework.web.context.request.async.WebAsyncManager; |
53 | | -import org.springframework.web.context.request.async.WebAsyncUtils; |
54 | 53 | import org.springframework.web.servlet.DispatcherServlet; |
55 | 54 |
|
56 | 55 | /** |
@@ -143,15 +142,25 @@ public void service(HttpServletRequest request, HttpServletResponse response) th |
143 | 142 |
|
144 | 143 |
|
145 | 144 | public void service(HttpServletRequest request, HttpServletResponse response, CountDownLatch latch) throws Exception { |
| 145 | + ((ProxyHttpServletRequest) request).setAsyncStarted(true); |
| 146 | + |
146 | 147 | ProxyFilterChain filterChain = new ProxyFilterChain(this.dispatcher); |
147 | 148 | filterChain.doFilter(request, response); |
148 | 149 |
|
149 | | - WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request); |
150 | | - if (asyncManager.isConcurrentHandlingStarted()) { |
151 | | - this.dispatcher.service(request, response); |
| 150 | + AsyncContext asyncContext = request.getAsyncContext(); |
| 151 | + if (asyncContext != null) { |
| 152 | + filterChain = new ProxyFilterChain(this.dispatcher); |
| 153 | + ((ProxyAsyncContext) asyncContext).addDispatchHandler(() -> { |
| 154 | + try { |
| 155 | + new ProxyFilterChain(this.dispatcher).doFilter(request, response); |
| 156 | + asyncContext.complete(); |
| 157 | + } |
| 158 | + catch (Exception e) { |
| 159 | + throw new IllegalStateException(e); |
| 160 | + } |
| 161 | + }); |
152 | 162 | } |
153 | 163 |
|
154 | | - |
155 | 164 | if (latch != null) { |
156 | 165 | latch.countDown(); |
157 | 166 | } |
|
0 commit comments