Skip to content

Commit a67d80b

Browse files
committed
Clean up async execution logic in ProxyMVC
1 parent 7a1980d commit a67d80b

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

spring-cloud-function-adapters/spring-cloud-function-serverless-web/src/main/java/org/springframework/cloud/function/serverless/web/ProxyHttpServletRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ public AsyncContext startAsync() {
634634
@Override
635635
public AsyncContext startAsync(ServletRequest request, @Nullable ServletResponse response) {
636636
Assert.state(this.asyncSupported, "Async not supported");
637+
this.dispatcherType = DispatcherType.ASYNC;
637638
this.asyncStarted = true;
638639
this.asyncContext = this.asyncContext == null ? new ProxyAsyncContext(request, response) : this.asyncContext;
639640
return this.asyncContext;

spring-cloud-function-adapters/spring-cloud-function-serverless-web/src/main/java/org/springframework/cloud/function/serverless/web/ProxyMvc.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.List;
2626
import java.util.concurrent.CountDownLatch;
2727

28+
import jakarta.servlet.AsyncContext;
2829
import jakarta.servlet.Filter;
2930
import jakarta.servlet.FilterChain;
3031
import jakarta.servlet.FilterConfig;
@@ -49,8 +50,6 @@
4950
import org.springframework.util.ObjectUtils;
5051
import org.springframework.util.StringUtils;
5152
import org.springframework.web.context.ConfigurableWebApplicationContext;
52-
import org.springframework.web.context.request.async.WebAsyncManager;
53-
import org.springframework.web.context.request.async.WebAsyncUtils;
5453
import org.springframework.web.servlet.DispatcherServlet;
5554

5655
/**
@@ -143,15 +142,25 @@ public void service(HttpServletRequest request, HttpServletResponse response) th
143142

144143

145144
public void service(HttpServletRequest request, HttpServletResponse response, CountDownLatch latch) throws Exception {
145+
((ProxyHttpServletRequest) request).setAsyncStarted(true);
146+
146147
ProxyFilterChain filterChain = new ProxyFilterChain(this.dispatcher);
147148
filterChain.doFilter(request, response);
148149

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+
});
152162
}
153163

154-
155164
if (latch != null) {
156165
latch.countDown();
157166
}

0 commit comments

Comments
 (0)