@@ -136,8 +136,8 @@ public void setTaskExecutor(AsyncTaskExecutor taskExecutor) {
136
136
}
137
137
138
138
/**
139
- * Whether the selected handler for the current request chose to handle the
140
- * request asynchronously. A return value of "true" indicates concurrent
139
+ * Return whether the selected handler for the current request chose to handle
140
+ * the request asynchronously. A return value of "true" indicates concurrent
141
141
* handling is under way and the response will remain open. A return value
142
142
* of "false" means concurrent handling was either not started or possibly
143
143
* that it has completed and the request was dispatched for further
@@ -148,16 +148,16 @@ public boolean isConcurrentHandlingStarted() {
148
148
}
149
149
150
150
/**
151
- * Whether a result value exists as a result of concurrent handling.
151
+ * Return whether a result value exists as a result of concurrent handling.
152
152
*/
153
153
public boolean hasConcurrentResult () {
154
154
return (this .concurrentResult != RESULT_NONE );
155
155
}
156
156
157
157
/**
158
- * Provides access to the result from concurrent handling.
158
+ * Get the result from concurrent handling.
159
159
* @return an Object, possibly an {@code Exception} or {@code Throwable} if
160
- * concurrent handling raised one.
160
+ * concurrent handling raised one
161
161
* @see #clearConcurrentResult()
162
162
*/
163
163
@ Nullable
@@ -166,8 +166,7 @@ public Object getConcurrentResult() {
166
166
}
167
167
168
168
/**
169
- * Provides access to additional processing context saved at the start of
170
- * concurrent handling.
169
+ * Get the additional processing context saved at the start of concurrent handling.
171
170
* @see #clearConcurrentResult()
172
171
*/
173
172
@ Nullable
@@ -208,7 +207,7 @@ public void registerCallableInterceptor(Object key, CallableProcessingIntercepto
208
207
209
208
/**
210
209
* Register a {@link CallableProcessingInterceptor} without a key.
211
- * The key is derived from the class name and hashcode .
210
+ * The key is derived from the class name and hash code .
212
211
* @param interceptors one or more interceptors to register
213
212
*/
214
213
public void registerCallableInterceptors (CallableProcessingInterceptor ... interceptors ) {
@@ -231,8 +230,8 @@ public void registerDeferredResultInterceptor(Object key, DeferredResultProcessi
231
230
}
232
231
233
232
/**
234
- * Register one or more {@link DeferredResultProcessingInterceptor DeferredResultProcessingInterceptors} without a specified key.
235
- * The default key is derived from the interceptor class name and hash code.
233
+ * Register one or more {@link DeferredResultProcessingInterceptor DeferredResultProcessingInterceptors}
234
+ * without a specified key. The default key is derived from the interceptor class name and hash code.
236
235
* @param interceptors one or more interceptors to register
237
236
*/
238
237
public void registerDeferredResultInterceptors (DeferredResultProcessingInterceptor ... interceptors ) {
@@ -298,7 +297,7 @@ public void startCallableProcessing(final WebAsyncTask<?> webAsyncTask, Object..
298
297
this .taskExecutor = executor ;
299
298
}
300
299
else {
301
- logExecutorWarning ();
300
+ logExecutorWarning (this . asyncWebRequest );
302
301
}
303
302
304
303
List <CallableProcessingInterceptor > interceptors = new ArrayList <>();
@@ -311,7 +310,7 @@ public void startCallableProcessing(final WebAsyncTask<?> webAsyncTask, Object..
311
310
312
311
this .asyncWebRequest .addTimeoutHandler (() -> {
313
312
if (logger .isDebugEnabled ()) {
314
- logger .debug ("Async request timeout for " + formatRequestUri ( ));
313
+ logger .debug ("Async request timeout for " + formatUri ( this . asyncWebRequest ));
315
314
}
316
315
Object result = interceptorChain .triggerAfterTimeout (this .asyncWebRequest , callable );
317
316
if (result != CallableProcessingInterceptor .RESULT_NONE ) {
@@ -322,7 +321,7 @@ public void startCallableProcessing(final WebAsyncTask<?> webAsyncTask, Object..
322
321
this .asyncWebRequest .addErrorHandler (ex -> {
323
322
if (!this .errorHandlingInProgress ) {
324
323
if (logger .isDebugEnabled ()) {
325
- logger .debug ("Async request error for " + formatRequestUri ( ) + ": " + ex );
324
+ logger .debug ("Async request error for " + formatUri ( this . asyncWebRequest ) + ": " + ex );
326
325
}
327
326
Object result = interceptorChain .triggerAfterError (this .asyncWebRequest , callable , ex );
328
327
result = (result != CallableProcessingInterceptor .RESULT_NONE ? result : ex );
@@ -359,7 +358,7 @@ public void startCallableProcessing(final WebAsyncTask<?> webAsyncTask, Object..
359
358
}
360
359
}
361
360
362
- private void logExecutorWarning () {
361
+ private void logExecutorWarning (AsyncWebRequest asyncWebRequest ) {
363
362
if (taskExecutorWarning && logger .isWarnEnabled ()) {
364
363
synchronized (DEFAULT_TASK_EXECUTOR ) {
365
364
AsyncTaskExecutor executor = this .taskExecutor ;
@@ -371,19 +370,14 @@ private void logExecutorWarning() {
371
370
"Please, configure a TaskExecutor in the MVC config under \" async support\" .\n " +
372
371
"The " + executorTypeName + " currently in use is not suitable under load.\n " +
373
372
"-------------------------------\n " +
374
- "Request URI: '" + formatRequestUri ( ) + "'\n " +
373
+ "Request URI: '" + formatUri ( asyncWebRequest ) + "'\n " +
375
374
"!!!" );
376
375
taskExecutorWarning = false ;
377
376
}
378
377
}
379
378
}
380
379
}
381
380
382
- private String formatRequestUri () {
383
- HttpServletRequest request = this .asyncWebRequest .getNativeRequest (HttpServletRequest .class );
384
- return request != null ? request .getRequestURI () : "servlet container" ;
385
- }
386
-
387
381
private void setConcurrentResultAndDispatch (@ Nullable Object result ) {
388
382
synchronized (WebAsyncManager .this ) {
389
383
if (this .concurrentResult != RESULT_NONE ) {
@@ -393,16 +387,18 @@ private void setConcurrentResultAndDispatch(@Nullable Object result) {
393
387
this .errorHandlingInProgress = (result instanceof Throwable );
394
388
}
395
389
390
+ Assert .state (this .asyncWebRequest != null , "AsyncWebRequest must not be null" );
396
391
if (this .asyncWebRequest .isAsyncComplete ()) {
397
392
if (logger .isDebugEnabled ()) {
398
- logger .debug ("Async result set but request already complete: " + formatRequestUri ( ));
393
+ logger .debug ("Async result set but request already complete: " + formatUri ( this . asyncWebRequest ));
399
394
}
400
395
return ;
401
396
}
402
397
403
398
if (logger .isDebugEnabled ()) {
404
399
boolean isError = result instanceof Throwable ;
405
- logger .debug ("Async " + (isError ? "error" : "result set" ) + ", dispatch to " + formatRequestUri ());
400
+ logger .debug ("Async " + (isError ? "error" : "result set" ) +
401
+ ", dispatch to " + formatUri (this .asyncWebRequest ));
406
402
}
407
403
this .asyncWebRequest .dispatch ();
408
404
}
@@ -462,8 +458,8 @@ public void startDeferredResultProcessing(
462
458
}
463
459
});
464
460
465
- this .asyncWebRequest .addCompletionHandler (()
466
- -> interceptorChain .triggerAfterCompletion (this .asyncWebRequest , deferredResult ));
461
+ this .asyncWebRequest .addCompletionHandler (() ->
462
+ interceptorChain .triggerAfterCompletion (this .asyncWebRequest , deferredResult ));
467
463
468
464
interceptorChain .applyBeforeConcurrentHandling (this .asyncWebRequest , deferredResult );
469
465
startAsyncProcessing (processingContext );
@@ -486,11 +482,17 @@ private void startAsyncProcessing(Object[] processingContext) {
486
482
this .concurrentResultContext = processingContext ;
487
483
this .errorHandlingInProgress = false ;
488
484
}
489
- this .asyncWebRequest .startAsync ();
490
485
486
+ Assert .state (this .asyncWebRequest != null , "AsyncWebRequest must not be null" );
487
+ this .asyncWebRequest .startAsync ();
491
488
if (logger .isDebugEnabled ()) {
492
489
logger .debug ("Started async request" );
493
490
}
494
491
}
495
492
493
+ private static String formatUri (AsyncWebRequest asyncWebRequest ) {
494
+ HttpServletRequest request = asyncWebRequest .getNativeRequest (HttpServletRequest .class );
495
+ return (request != null ? request .getRequestURI () : "servlet container" );
496
+ }
497
+
496
498
}
0 commit comments