Java Code Examples for org.springframework.web.util.WebUtils#isIncludeRequest()

The following examples show how to use org.springframework.web.util.WebUtils#isIncludeRequest() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DispatcherServlet.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Exposes the DispatcherServlet-specific request attributes and delegates to {@link #doDispatch}
 * for the actual dispatching.
 */
@Override
protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception {
	logRequest(request);

	// Keep a snapshot of the request attributes in case of an include,
	// to be able to restore the original attributes after the include.
	// 暂存请求参数
	Map<String, Object> attributesSnapshot = null;
	if (WebUtils.isIncludeRequest(request)) {
		attributesSnapshot = new HashMap<>();
		Enumeration<?> attrNames = request.getAttributeNames();
		while (attrNames.hasMoreElements()) {
			String attrName = (String) attrNames.nextElement();
			if (this.cleanupAfterInclude || attrName.startsWith(DEFAULT_STRATEGIES_PREFIX)) {
				attributesSnapshot.put(attrName, request.getAttribute(attrName));
			}
		}
	}

	// Make framework objects available to handlers and view objects.
	// 使框架对象可用于处理程序和视图对象
	request.setAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE, getWebApplicationContext());
	request.setAttribute(LOCALE_RESOLVER_ATTRIBUTE, this.localeResolver);
	request.setAttribute(THEME_RESOLVER_ATTRIBUTE, this.themeResolver);
	request.setAttribute(THEME_SOURCE_ATTRIBUTE, getThemeSource());

	if (this.flashMapManager != null) {
		FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(request, response);
		if (inputFlashMap != null) {
			request.setAttribute(INPUT_FLASH_MAP_ATTRIBUTE, Collections.unmodifiableMap(inputFlashMap));
		}
		request.setAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
		request.setAttribute(FLASH_MAP_MANAGER_ATTRIBUTE, this.flashMapManager);
	}

	try {
		// 经过前面的准备(属性、辅助变量),进入请求处理过程
		doDispatch(request, response);
	}
	finally {
		if (!WebAsyncUtils.getAsyncManager(request).isConcurrentHandlingStarted()) {
			// Restore the original attribute snapshot, in case of an include.
			// 恢复原始参数
			if (attributesSnapshot != null) {
				restoreAttributesAfterInclude(request, attributesSnapshot);
			}
		}
	}
}
 
Example 2
Source File: DispatcherServlet.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Exposes the DispatcherServlet-specific request attributes and delegates to {@link #doDispatch}
 * for the actual dispatching.
 */
@Override
protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception {
	logRequest(request);

	// Keep a snapshot of the request attributes in case of an include,
	// to be able to restore the original attributes after the include.
	Map<String, Object> attributesSnapshot = null;
	if (WebUtils.isIncludeRequest(request)) {
		attributesSnapshot = new HashMap<>();
		Enumeration<?> attrNames = request.getAttributeNames();
		while (attrNames.hasMoreElements()) {
			String attrName = (String) attrNames.nextElement();
			if (this.cleanupAfterInclude || attrName.startsWith(DEFAULT_STRATEGIES_PREFIX)) {
				attributesSnapshot.put(attrName, request.getAttribute(attrName));
			}
		}
	}

	// Make framework objects available to handlers and view objects.
	request.setAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE, getWebApplicationContext());
	request.setAttribute(LOCALE_RESOLVER_ATTRIBUTE, this.localeResolver);
	request.setAttribute(THEME_RESOLVER_ATTRIBUTE, this.themeResolver);
	request.setAttribute(THEME_SOURCE_ATTRIBUTE, getThemeSource());

	if (this.flashMapManager != null) {
		FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(request, response);
		if (inputFlashMap != null) {
			request.setAttribute(INPUT_FLASH_MAP_ATTRIBUTE, Collections.unmodifiableMap(inputFlashMap));
		}
		request.setAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
		request.setAttribute(FLASH_MAP_MANAGER_ATTRIBUTE, this.flashMapManager);
	}

	try {
		// 核心逻辑
		doDispatch(request, response);
	}
	finally {
		if (!WebAsyncUtils.getAsyncManager(request).isConcurrentHandlingStarted()) {
			// Restore the original attribute snapshot, in case of an include.
			if (attributesSnapshot != null) {
				restoreAttributesAfterInclude(request, attributesSnapshot);
			}
		}
	}
}
 
Example 3
Source File: DispatcherServlet.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Exposes the DispatcherServlet-specific request attributes and delegates to {@link #doDispatch}
 * for the actual dispatching.
 */
@Override
protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception {
	if (logger.isDebugEnabled()) {
		String resumed = WebAsyncUtils.getAsyncManager(request).hasConcurrentResult() ? " resumed" : "";
		logger.debug("DispatcherServlet with name '" + getServletName() + "'" + resumed +
				" processing " + request.getMethod() + " request for [" + getRequestUri(request) + "]");
	}

	// Keep a snapshot of the request attributes in case of an include,
	// to be able to restore the original attributes after the include.
	Map<String, Object> attributesSnapshot = null;
	if (WebUtils.isIncludeRequest(request)) {
		attributesSnapshot = new HashMap<String, Object>();
		Enumeration<?> attrNames = request.getAttributeNames();
		while (attrNames.hasMoreElements()) {
			String attrName = (String) attrNames.nextElement();
			if (this.cleanupAfterInclude || attrName.startsWith(DEFAULT_STRATEGIES_PREFIX)) {
				attributesSnapshot.put(attrName, request.getAttribute(attrName));
			}
		}
	}

	// Make framework objects available to handlers and view objects.
	request.setAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE, getWebApplicationContext());
	request.setAttribute(LOCALE_RESOLVER_ATTRIBUTE, this.localeResolver);
	request.setAttribute(THEME_RESOLVER_ATTRIBUTE, this.themeResolver);
	request.setAttribute(THEME_SOURCE_ATTRIBUTE, getThemeSource());

	FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(request, response);
	if (inputFlashMap != null) {
		request.setAttribute(INPUT_FLASH_MAP_ATTRIBUTE, Collections.unmodifiableMap(inputFlashMap));
	}
	request.setAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
	request.setAttribute(FLASH_MAP_MANAGER_ATTRIBUTE, this.flashMapManager);

	try {
		doDispatch(request, response);
	}
	finally {
		if (!WebAsyncUtils.getAsyncManager(request).isConcurrentHandlingStarted()) {
			// Restore the original attribute snapshot, in case of an include.
			if (attributesSnapshot != null) {
				restoreAttributesAfterInclude(request, attributesSnapshot);
			}
		}
	}
}
 
Example 4
Source File: DispatcherServlet.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Exposes the DispatcherServlet-specific request attributes and delegates to {@link #doDispatch}
 * for the actual dispatching.
 */
@Override
protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception {
	if (logger.isDebugEnabled()) {
		String resumed = WebAsyncUtils.getAsyncManager(request).hasConcurrentResult() ? " resumed" : "";
		logger.debug("DispatcherServlet with name '" + getServletName() + "'" + resumed +
				" processing " + request.getMethod() + " request for [" + getRequestUri(request) + "]");
	}

	// Keep a snapshot of the request attributes in case of an include,
	// to be able to restore the original attributes after the include.
	Map<String, Object> attributesSnapshot = null;
	if (WebUtils.isIncludeRequest(request)) {
		attributesSnapshot = new HashMap<String, Object>();
		Enumeration<?> attrNames = request.getAttributeNames();
		while (attrNames.hasMoreElements()) {
			String attrName = (String) attrNames.nextElement();
			if (this.cleanupAfterInclude || attrName.startsWith("org.springframework.web.servlet")) {
				attributesSnapshot.put(attrName, request.getAttribute(attrName));
			}
		}
	}

	// Make framework objects available to handlers and view objects.
	request.setAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE, getWebApplicationContext());
	request.setAttribute(LOCALE_RESOLVER_ATTRIBUTE, this.localeResolver);
	request.setAttribute(THEME_RESOLVER_ATTRIBUTE, this.themeResolver);
	request.setAttribute(THEME_SOURCE_ATTRIBUTE, getThemeSource());

	FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(request, response);
	if (inputFlashMap != null) {
		request.setAttribute(INPUT_FLASH_MAP_ATTRIBUTE, Collections.unmodifiableMap(inputFlashMap));
	}
	request.setAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
	request.setAttribute(FLASH_MAP_MANAGER_ATTRIBUTE, this.flashMapManager);

	try {
		doDispatch(request, response);
	}
	finally {
		if (!WebAsyncUtils.getAsyncManager(request).isConcurrentHandlingStarted()) {
			// Restore the original attribute snapshot, in case of an include.
			if (attributesSnapshot != null) {
				restoreAttributesAfterInclude(request, attributesSnapshot);
			}
		}
	}
}
 
Example 5
Source File: SimpleMappingExceptionResolver.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * Apply the specified HTTP status code to the given response, if possible (that is,
 * if not executing within an include request).
 * @param request current HTTP request
 * @param response current HTTP response
 * @param statusCode the status code to apply
 * @see #determineStatusCode
 * @see #setDefaultStatusCode
 * @see HttpServletResponse#setStatus
 */
protected void applyStatusCodeIfPossible(HttpServletRequest request, HttpServletResponse response, int statusCode) {
	if (!WebUtils.isIncludeRequest(request)) {
		if (logger.isDebugEnabled()) {
			logger.debug("Applying HTTP status " + statusCode);
		}
		response.setStatus(statusCode);
		request.setAttribute(WebUtils.ERROR_STATUS_CODE_ATTRIBUTE, statusCode);
	}
}
 
Example 6
Source File: SimpleMappingExceptionResolver.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Apply the specified HTTP status code to the given response, if possible (that is,
 * if not executing within an include request).
 * @param request current HTTP request
 * @param response current HTTP response
 * @param statusCode the status code to apply
 * @see #determineStatusCode
 * @see #setDefaultStatusCode
 * @see HttpServletResponse#setStatus
 */
protected void applyStatusCodeIfPossible(HttpServletRequest request, HttpServletResponse response, int statusCode) {
	if (!WebUtils.isIncludeRequest(request)) {
		if (logger.isDebugEnabled()) {
			logger.debug("Applying HTTP status " + statusCode);
		}
		response.setStatus(statusCode);
		request.setAttribute(WebUtils.ERROR_STATUS_CODE_ATTRIBUTE, statusCode);
	}
}
 
Example 7
Source File: SimpleMappingExceptionResolver.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Apply the specified HTTP status code to the given response, if possible (that is,
 * if not executing within an include request).
 * @param request current HTTP request
 * @param response current HTTP response
 * @param statusCode the status code to apply
 * @see #determineStatusCode
 * @see #setDefaultStatusCode
 * @see HttpServletResponse#setStatus
 */
protected void applyStatusCodeIfPossible(HttpServletRequest request, HttpServletResponse response, int statusCode) {
	if (!WebUtils.isIncludeRequest(request)) {
		if (logger.isDebugEnabled()) {
			logger.debug("Applying HTTP status code " + statusCode);
		}
		response.setStatus(statusCode);
		request.setAttribute(WebUtils.ERROR_STATUS_CODE_ATTRIBUTE, statusCode);
	}
}
 
Example 8
Source File: SimpleMappingExceptionResolver.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Apply the specified HTTP status code to the given response, if possible (that is,
 * if not executing within an include request).
 * @param request current HTTP request
 * @param response current HTTP response
 * @param statusCode the status code to apply
 * @see #determineStatusCode
 * @see #setDefaultStatusCode
 * @see HttpServletResponse#setStatus
 */
protected void applyStatusCodeIfPossible(HttpServletRequest request, HttpServletResponse response, int statusCode) {
	if (!WebUtils.isIncludeRequest(request)) {
		if (logger.isDebugEnabled()) {
			logger.debug("Applying HTTP status code " + statusCode);
		}
		response.setStatus(statusCode);
		request.setAttribute(WebUtils.ERROR_STATUS_CODE_ATTRIBUTE, statusCode);
	}
}
 
Example 9
Source File: InternalResourceView.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Determine whether to use RequestDispatcher's {@code include} or
 * {@code forward} method.
 * <p>Performs a check whether an include URI attribute is found in the request,
 * indicating an include request, and whether the response has already been committed.
 * In both cases, an include will be performed, as a forward is not possible anymore.
 * @param request current HTTP request
 * @param response current HTTP response
 * @return {@code true} for include, {@code false} for forward
 * @see javax.servlet.RequestDispatcher#forward
 * @see javax.servlet.RequestDispatcher#include
 * @see javax.servlet.ServletResponse#isCommitted
 * @see org.springframework.web.util.WebUtils#isIncludeRequest
 */
protected boolean useInclude(HttpServletRequest request, HttpServletResponse response) {
	return (this.alwaysInclude || WebUtils.isIncludeRequest(request) || response.isCommitted());
}
 
Example 10
Source File: ServletForwardingController.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Determine whether to use RequestDispatcher's {@code include} or
 * {@code forward} method.
 * <p>Performs a check whether an include URI attribute is found in the request,
 * indicating an include request, and whether the response has already been committed.
 * In both cases, an include will be performed, as a forward is not possible anymore.
 * @param request current HTTP request
 * @param response current HTTP response
 * @return {@code true} for include, {@code false} for forward
 * @see javax.servlet.RequestDispatcher#forward
 * @see javax.servlet.RequestDispatcher#include
 * @see javax.servlet.ServletResponse#isCommitted
 * @see org.springframework.web.util.WebUtils#isIncludeRequest
 */
protected boolean useInclude(HttpServletRequest request, HttpServletResponse response) {
	return (WebUtils.isIncludeRequest(request) || response.isCommitted());
}
 
Example 11
Source File: InternalResourceView.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Determine whether to use RequestDispatcher's {@code include} or
 * {@code forward} method.
 * <p>Performs a check whether an include URI attribute is found in the request,
 * indicating an include request, and whether the response has already been committed.
 * In both cases, an include will be performed, as a forward is not possible anymore.
 * @param request current HTTP request
 * @param response current HTTP response
 * @return {@code true} for include, {@code false} for forward
 * @see javax.servlet.RequestDispatcher#forward
 * @see javax.servlet.RequestDispatcher#include
 * @see javax.servlet.ServletResponse#isCommitted
 * @see org.springframework.web.util.WebUtils#isIncludeRequest
 */
protected boolean useInclude(HttpServletRequest request, HttpServletResponse response) {
	return (this.alwaysInclude || WebUtils.isIncludeRequest(request) || response.isCommitted());
}
 
Example 12
Source File: ServletForwardingController.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Determine whether to use RequestDispatcher's {@code include} or
 * {@code forward} method.
 * <p>Performs a check whether an include URI attribute is found in the request,
 * indicating an include request, and whether the response has already been committed.
 * In both cases, an include will be performed, as a forward is not possible anymore.
 * @param request current HTTP request
 * @param response current HTTP response
 * @return {@code true} for include, {@code false} for forward
 * @see javax.servlet.RequestDispatcher#forward
 * @see javax.servlet.RequestDispatcher#include
 * @see javax.servlet.ServletResponse#isCommitted
 * @see org.springframework.web.util.WebUtils#isIncludeRequest
 */
protected boolean useInclude(HttpServletRequest request, HttpServletResponse response) {
	return (WebUtils.isIncludeRequest(request) || response.isCommitted());
}
 
Example 13
Source File: InternalResourceView.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Determine whether to use RequestDispatcher's {@code include} or
 * {@code forward} method.
 * <p>Performs a check whether an include URI attribute is found in the request,
 * indicating an include request, and whether the response has already been committed.
 * In both cases, an include will be performed, as a forward is not possible anymore.
 * @param request current HTTP request
 * @param response current HTTP response
 * @return {@code true} for include, {@code false} for forward
 * @see javax.servlet.RequestDispatcher#forward
 * @see javax.servlet.RequestDispatcher#include
 * @see javax.servlet.ServletResponse#isCommitted
 * @see org.springframework.web.util.WebUtils#isIncludeRequest
 */
protected boolean useInclude(HttpServletRequest request, HttpServletResponse response) {
	return (this.alwaysInclude || WebUtils.isIncludeRequest(request) || response.isCommitted());
}
 
Example 14
Source File: ServletForwardingController.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Determine whether to use RequestDispatcher's {@code include} or
 * {@code forward} method.
 * <p>Performs a check whether an include URI attribute is found in the request,
 * indicating an include request, and whether the response has already been committed.
 * In both cases, an include will be performed, as a forward is not possible anymore.
 * @param request current HTTP request
 * @param response current HTTP response
 * @return {@code true} for include, {@code false} for forward
 * @see javax.servlet.RequestDispatcher#forward
 * @see javax.servlet.RequestDispatcher#include
 * @see javax.servlet.ServletResponse#isCommitted
 * @see org.springframework.web.util.WebUtils#isIncludeRequest
 */
protected boolean useInclude(HttpServletRequest request, HttpServletResponse response) {
	return (WebUtils.isIncludeRequest(request) || response.isCommitted());
}
 
Example 15
Source File: InternalResourceView.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Determine whether to use RequestDispatcher's {@code include} or
 * {@code forward} method.
 * <p>Performs a check whether an include URI attribute is found in the request,
 * indicating an include request, and whether the response has already been committed.
 * In both cases, an include will be performed, as a forward is not possible anymore.
 * @param request current HTTP request
 * @param response current HTTP response
 * @return {@code true} for include, {@code false} for forward
 * @see javax.servlet.RequestDispatcher#forward
 * @see javax.servlet.RequestDispatcher#include
 * @see javax.servlet.ServletResponse#isCommitted
 * @see org.springframework.web.util.WebUtils#isIncludeRequest
 */
protected boolean useInclude(HttpServletRequest request, HttpServletResponse response) {
	return (this.alwaysInclude || WebUtils.isIncludeRequest(request) || response.isCommitted());
}
 
Example 16
Source File: ServletForwardingController.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Determine whether to use RequestDispatcher's {@code include} or
 * {@code forward} method.
 * <p>Performs a check whether an include URI attribute is found in the request,
 * indicating an include request, and whether the response has already been committed.
 * In both cases, an include will be performed, as a forward is not possible anymore.
 * @param request current HTTP request
 * @param response current HTTP response
 * @return {@code true} for include, {@code false} for forward
 * @see javax.servlet.RequestDispatcher#forward
 * @see javax.servlet.RequestDispatcher#include
 * @see javax.servlet.ServletResponse#isCommitted
 * @see org.springframework.web.util.WebUtils#isIncludeRequest
 */
protected boolean useInclude(HttpServletRequest request, HttpServletResponse response) {
	return (WebUtils.isIncludeRequest(request) || response.isCommitted());
}