1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
32
32
*/
33
33
public abstract class WebAsyncUtils {
34
34
35
- public static final String WEB_ASYNC_MANAGER_ATTRIBUTE = WebAsyncManager .class .getName () + ".WEB_ASYNC_MANAGER" ;
35
+ public static final String WEB_ASYNC_MANAGER_ATTRIBUTE =
36
+ WebAsyncManager .class .getName () + ".WEB_ASYNC_MANAGER" ;
36
37
37
38
38
39
/**
39
40
* Obtain the {@link WebAsyncManager} for the current request, or if not
40
41
* found, create and associate it with the request.
41
42
*/
42
43
public static WebAsyncManager getAsyncManager (ServletRequest servletRequest ) {
43
- WebAsyncManager asyncManager = (WebAsyncManager ) servletRequest .getAttribute (WEB_ASYNC_MANAGER_ATTRIBUTE );
44
+ WebAsyncManager asyncManager = null ;
45
+ Object asyncManagerAttr = servletRequest .getAttribute (WEB_ASYNC_MANAGER_ATTRIBUTE );
46
+ if (asyncManagerAttr instanceof WebAsyncManager ) {
47
+ asyncManager = (WebAsyncManager ) asyncManagerAttr ;
48
+ }
44
49
if (asyncManager == null ) {
45
50
asyncManager = new WebAsyncManager ();
46
51
servletRequest .setAttribute (WEB_ASYNC_MANAGER_ATTRIBUTE , asyncManager );
@@ -54,7 +59,11 @@ public static WebAsyncManager getAsyncManager(ServletRequest servletRequest) {
54
59
*/
55
60
public static WebAsyncManager getAsyncManager (WebRequest webRequest ) {
56
61
int scope = RequestAttributes .SCOPE_REQUEST ;
57
- WebAsyncManager asyncManager = (WebAsyncManager ) webRequest .getAttribute (WEB_ASYNC_MANAGER_ATTRIBUTE , scope );
62
+ WebAsyncManager asyncManager = null ;
63
+ Object asyncManagerAttr = webRequest .getAttribute (WEB_ASYNC_MANAGER_ATTRIBUTE , scope );
64
+ if (asyncManagerAttr instanceof WebAsyncManager ) {
65
+ asyncManager = (WebAsyncManager ) asyncManagerAttr ;
66
+ }
58
67
if (asyncManager == null ) {
59
68
asyncManager = new WebAsyncManager ();
60
69
webRequest .setAttribute (WEB_ASYNC_MANAGER_ATTRIBUTE , asyncManager , scope );
0 commit comments