HttpServletResponse response) {
assertInitialized();
// 异步请求(dispatcherType == ASYNC)开始时,如果已经存在request context,则直接取得并返回之。
boolean asyncDispatcher = request_isDispatcherType(request, DISPATCHER_TYPE_ASYNC);
RequestContext requestContext = null;
if (asyncDispatcher) {
requestContext = RequestContextUtil.getRequestContext(request);
}
if (requestContext == null) {
SimpleRequestContext innerReuestContext = new SimpleRequestContext(servletContext, request, response, this);
requestContext = innerReuestContext;
// 将requestContext放入request中,以便今后只需要用request就可以取得requestContext。
// 及早设置setRequestContext,以便随后的prepareRequestContext就能使用。
RequestContextUtil.setRequestContext(requestContext);
for (RequestContextFactory<?> factory : factories) {
requestContext = factory.getRequestContextWrapper(requestContext);
// 调用<code>requestContext.prepare()</code>方法
prepareRequestContext(requestContext);
// 将requestContext放入request中,以便今后只需要用request就可以取得requestContext。
RequestContextUtil.setRequestContext(requestContext);
}
innerReuestContext.setTopRequestContext(requestContext);
getLogger().debug("Created a new request context: {}", requestContext);
}
// 无论是否是从async恢复,都需要重新设置thread的上下文环境。
bind(requestContext.getRequest());
return requestContext;
}