Skip to content

Commit

Permalink
Cache constructor instance in WebAsyncUtils
Browse files Browse the repository at this point in the history
Issue: SPR-10673
  • Loading branch information
rstoyanchev committed Jul 18, 2013
1 parent 860e56e commit 9af1984
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public abstract class WebAsyncUtils {

public static final String WEB_ASYNC_MANAGER_ATTRIBUTE = WebAsyncManager.class.getName() + ".WEB_ASYNC_MANAGER";

private static Constructor<?> standardAsyncRequestConstructor;


/**
* Obtain the {@link WebAsyncManager} for the current request, or if not
* found, create and associate it with the request.
Expand Down Expand Up @@ -80,10 +83,12 @@ public static AsyncWebRequest createAsyncWebRequest(HttpServletRequest request,

private static AsyncWebRequest createStandardServletAsyncWebRequest(HttpServletRequest request, HttpServletResponse response) {
try {
String className = "org.springframework.web.context.request.async.StandardServletAsyncWebRequest";
Class<?> clazz = ClassUtils.forName(className, WebAsyncUtils.class.getClassLoader());
Constructor<?> constructor = clazz.getConstructor(HttpServletRequest.class, HttpServletResponse.class);
return (AsyncWebRequest) BeanUtils.instantiateClass(constructor, request, response);
if (standardAsyncRequestConstructor == null) {
String className = "org.springframework.web.context.request.async.StandardServletAsyncWebRequest";
Class<?> clazz = ClassUtils.forName(className, WebAsyncUtils.class.getClassLoader());
standardAsyncRequestConstructor = clazz.getConstructor(HttpServletRequest.class, HttpServletResponse.class);
}
return (AsyncWebRequest) BeanUtils.instantiateClass(standardAsyncRequestConstructor, request, response);
}
catch (Throwable t) {
throw new IllegalStateException("Failed to instantiate StandardServletAsyncWebRequest", t);
Expand Down

0 comments on commit 9af1984

Please sign in to comment.