Clean up async execution logic in ProxyMVC
This commit is contained in:
@@ -634,6 +634,7 @@ public class ProxyHttpServletRequest implements HttpServletRequest {
|
|||||||
@Override
|
@Override
|
||||||
public AsyncContext startAsync(ServletRequest request, @Nullable ServletResponse response) {
|
public AsyncContext startAsync(ServletRequest request, @Nullable ServletResponse response) {
|
||||||
Assert.state(this.asyncSupported, "Async not supported");
|
Assert.state(this.asyncSupported, "Async not supported");
|
||||||
|
this.dispatcherType = DispatcherType.ASYNC;
|
||||||
this.asyncStarted = true;
|
this.asyncStarted = true;
|
||||||
this.asyncContext = this.asyncContext == null ? new ProxyAsyncContext(request, response) : this.asyncContext;
|
this.asyncContext = this.asyncContext == null ? new ProxyAsyncContext(request, response) : this.asyncContext;
|
||||||
return this.asyncContext;
|
return this.asyncContext;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
|
import jakarta.servlet.AsyncContext;
|
||||||
import jakarta.servlet.Filter;
|
import jakarta.servlet.Filter;
|
||||||
import jakarta.servlet.FilterChain;
|
import jakarta.servlet.FilterChain;
|
||||||
import jakarta.servlet.FilterConfig;
|
import jakarta.servlet.FilterConfig;
|
||||||
@@ -49,8 +50,6 @@ import org.springframework.util.Assert;
|
|||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.context.ConfigurableWebApplicationContext;
|
import org.springframework.web.context.ConfigurableWebApplicationContext;
|
||||||
import org.springframework.web.context.request.async.WebAsyncManager;
|
|
||||||
import org.springframework.web.context.request.async.WebAsyncUtils;
|
|
||||||
import org.springframework.web.servlet.DispatcherServlet;
|
import org.springframework.web.servlet.DispatcherServlet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -143,15 +142,25 @@ public final class ProxyMvc {
|
|||||||
|
|
||||||
|
|
||||||
public void service(HttpServletRequest request, HttpServletResponse response, CountDownLatch latch) throws Exception {
|
public void service(HttpServletRequest request, HttpServletResponse response, CountDownLatch latch) throws Exception {
|
||||||
|
((ProxyHttpServletRequest) request).setAsyncStarted(true);
|
||||||
|
|
||||||
ProxyFilterChain filterChain = new ProxyFilterChain(this.dispatcher);
|
ProxyFilterChain filterChain = new ProxyFilterChain(this.dispatcher);
|
||||||
filterChain.doFilter(request, response);
|
filterChain.doFilter(request, response);
|
||||||
|
|
||||||
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
|
AsyncContext asyncContext = request.getAsyncContext();
|
||||||
if (asyncManager.isConcurrentHandlingStarted()) {
|
if (asyncContext != null) {
|
||||||
this.dispatcher.service(request, response);
|
filterChain = new ProxyFilterChain(this.dispatcher);
|
||||||
|
((ProxyAsyncContext) asyncContext).addDispatchHandler(() -> {
|
||||||
|
try {
|
||||||
|
new ProxyFilterChain(this.dispatcher).doFilter(request, response);
|
||||||
|
asyncContext.complete();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (latch != null) {
|
if (latch != null) {
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user