Java Code Examples for org.springframework.web.servlet.DispatcherServlet#WEB_APPLICATION_CONTEXT_ATTRIBUTE

The following examples show how to use org.springframework.web.servlet.DispatcherServlet#WEB_APPLICATION_CONTEXT_ATTRIBUTE . 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: MvcUriComponentsBuilder.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private static WebApplicationContext getWebApplicationContext() {
	RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
	if (requestAttributes == null) {
		logger.debug("No request bound to the current thread: is DispatcherSerlvet used?");
		return null;
	}

	HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
	if (request == null) {
		logger.debug("Request bound to current thread is not an HttpServletRequest");
		return null;
	}

	String attributeName = DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE;
	WebApplicationContext wac = (WebApplicationContext) request.getAttribute(attributeName);
	if (wac == null) {
		logger.debug("No WebApplicationContext found: not in a DispatcherServlet request?");
		return null;
	}
	return wac;
}
 
Example 2
Source File: SpringletsMvcUriComponentsBuilder.java    From springlets with Apache License 2.0 6 votes vote down vote up
private static WebApplicationContext getWebApplicationContext() {
	RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
	if (requestAttributes == null) {
		logger.debug("No request bound to the current thread: is DispatcherSerlvet used?");
		return null;
	}

	HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
	if (request == null) {
		logger.debug("Request bound to current thread is not an HttpServletRequest");
		return null;
	}

	String attributeName = DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE;
	WebApplicationContext wac = (WebApplicationContext) request.getAttribute(attributeName);
	if (wac == null) {
		logger.debug("No WebApplicationContext found: not in a DispatcherServlet request?");
		return null;
	}
	return wac;
}
 
Example 3
Source File: MvcUriComponentsBuilder.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Nullable
private static WebApplicationContext getWebApplicationContext() {
	RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
	if (requestAttributes == null) {
		return null;
	}
	HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
	String attributeName = DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE;
	WebApplicationContext wac = (WebApplicationContext) request.getAttribute(attributeName);
	if (wac == null) {
		return null;
	}
	return wac;
}
 
Example 4
Source File: MvcUriComponentsBuilder.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Nullable
private static WebApplicationContext getWebApplicationContext() {
	RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
	if (requestAttributes == null) {
		return null;
	}
	HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
	String attributeName = DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE;
	WebApplicationContext wac = (WebApplicationContext) request.getAttribute(attributeName);
	if (wac == null) {
		return null;
	}
	return wac;
}