@@ -71,13 +71,22 @@ protected void service(HttpServletRequest request, HttpServletResponse response)
71
71
super .service (request , response );
72
72
73
73
if (request .getAsyncContext () != null ) {
74
- MockHttpServletRequest mockRequest = WebUtils .getNativeRequest (request , MockHttpServletRequest .class );
75
- Assert .notNull (mockRequest , "Expected MockHttpServletRequest" );
76
- MockAsyncContext mockAsyncContext = ((MockAsyncContext ) mockRequest .getAsyncContext ());
77
- Assert .notNull (mockAsyncContext , "MockAsyncContext not found. Did request wrapper not delegate startAsync?" );
74
+ MockAsyncContext asyncContext ;
75
+ if (request .getAsyncContext () instanceof MockAsyncContext ) {
76
+ asyncContext = (MockAsyncContext ) request .getAsyncContext ();
77
+ }
78
+ else {
79
+ MockHttpServletRequest mockRequest = WebUtils .getNativeRequest (request , MockHttpServletRequest .class );
80
+ Assert .notNull (mockRequest , "Expected MockHttpServletRequest" );
81
+ asyncContext = (MockAsyncContext ) mockRequest .getAsyncContext ();
82
+ Assert .notNull (asyncContext , () ->
83
+ "Outer request wrapper " + request .getClass ().getName () + " has an AsyncContext," +
84
+ "but it is not a MockAsyncContext, while the nested " +
85
+ mockRequest .getClass ().getName () + " does not have an AsyncContext at all." );
86
+ }
78
87
79
88
final CountDownLatch dispatchLatch = new CountDownLatch (1 );
80
- mockAsyncContext .addDispatchHandler (new Runnable () {
89
+ asyncContext .addDispatchHandler (new Runnable () {
81
90
@ Override
82
91
public void run () {
83
92
dispatchLatch .countDown ();
0 commit comments