use of org.springframework.web.context.request.RequestAttributes in project com.revolsys.open by revolsys.
the class PathAliasController method getOriginalPrefix.
public static String getOriginalPrefix() {
final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
final String prefix = (String) requestAttributes.getAttribute(PATH_PREFIX, RequestAttributes.SCOPE_REQUEST);
if (Property.hasValue(prefix)) {
return prefix;
} else {
return "";
}
}
use of org.springframework.web.context.request.RequestAttributes in project com.revolsys.open by revolsys.
the class WebAnnotationMethodHandlerAdapter method invokeHandlerMethod.
protected ModelAndView invokeHandlerMethod(final HttpServletRequest request, final HttpServletResponse response, final Object handler) throws Exception {
final AnnotationHandlerMethodResolver methodResolver = getMethodResolver(handler);
final WebMethodHandler handlerMethod = methodResolver.resolveHandlerMethod(request);
final ServletWebRequest webRequest = new ServletWebRequest(request, response);
final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
try {
RequestContextHolder.setRequestAttributes(webRequest);
final ExtendedModelMap implicitModel = new BindingAwareModelMap();
final Object result = handlerMethod.invokeMethod(handler, request, response);
if (result == null) {
return null;
} else {
final ModelAndView mav = getModelAndView(handlerMethod.getMethod(), handler.getClass(), result, implicitModel, webRequest);
return mav;
}
} finally {
RequestContextHolder.setRequestAttributes(requestAttributes);
}
}
use of org.springframework.web.context.request.RequestAttributes in project spring-security by spring-projects.
the class ServletOAuth2AuthorizedClientExchangeFilterFunction method populateDefaultRequestResponse.
private void populateDefaultRequestResponse(Map<String, Object> attrs) {
if (attrs.containsKey(HTTP_SERVLET_REQUEST_ATTR_NAME) && attrs.containsKey(HTTP_SERVLET_RESPONSE_ATTR_NAME)) {
return;
}
RequestAttributes context = RequestContextHolder.getRequestAttributes();
if (context instanceof ServletRequestAttributes) {
attrs.putIfAbsent(HTTP_SERVLET_REQUEST_ATTR_NAME, ((ServletRequestAttributes) context).getRequest());
attrs.putIfAbsent(HTTP_SERVLET_RESPONSE_ATTR_NAME, ((ServletRequestAttributes) context).getResponse());
}
}
use of org.springframework.web.context.request.RequestAttributes in project spring-framework by spring-projects.
the class ServletUriComponentsBuilder method getCurrentRequest.
/**
* Obtain current request through {@link RequestContextHolder}.
*/
protected static HttpServletRequest getCurrentRequest() {
RequestAttributes attrs = RequestContextHolder.getRequestAttributes();
Assert.state(attrs instanceof ServletRequestAttributes, "No current ServletRequestAttributes");
return ((ServletRequestAttributes) attrs).getRequest();
}
use of org.springframework.web.context.request.RequestAttributes in project spring-framework by spring-projects.
the class MvcUriComponentsBuilder method getWebApplicationContext.
@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;
}
Aggregations