diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java b/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java index 19d50236c23a..b4f219b1d212 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java @@ -155,7 +155,7 @@ public void startAsync() { Assert.state(this.state == State.ASYNC, "Cannot start async: [" + this.state + "]"); } - this.asyncContext = getRequest().startAsync(getRequest(), getResponse()); + this.asyncContext = getRequest().startAsync(); this.asyncContext.addListener(this); if (this.timeout != null) { this.asyncContext.setTimeout(this.timeout); diff --git a/spring-web/src/test/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequestTests.java b/spring-web/src/test/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequestTests.java index ec5d773d2dbf..f510aa1755be 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequestTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequestTests.java @@ -18,7 +18,10 @@ import java.util.function.Consumer; +import jakarta.servlet.AsyncContext; import jakarta.servlet.AsyncEvent; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -31,6 +34,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; /** * Tests for {@link StandardServletAsyncWebRequest}. @@ -79,6 +83,20 @@ void startAsync() { assertThat(context.getListeners()).containsExactly(asyncRequest); } + @Test + void startAsyncUsesContainerRequestAndResponse() { + HttpServletRequest request = mock(HttpServletRequest.class); + HttpServletResponse response = mock(HttpServletResponse.class); + AsyncContext asyncContext = mock(AsyncContext.class); + when(request.isAsyncSupported()).thenReturn(true); + when(request.startAsync()).thenReturn(asyncContext); + StandardServletAsyncWebRequest asyncRequest = new StandardServletAsyncWebRequest(request, response); + + asyncRequest.startAsync(); + + verify(request).startAsync(); + } + @Test void startAsyncMultipleTimes() { asyncRequest.startAsync();