use of org.springframework.web.context.request.RequestAttributes in project spring-framework by spring-projects.
the class TilesView method checkResource.
@Override
public boolean checkResource(final Locale locale) throws Exception {
HttpServletRequest servletRequest = null;
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes instanceof ServletRequestAttributes) {
servletRequest = ((ServletRequestAttributes) requestAttributes).getRequest();
}
Request request = new ServletRequest(this.applicationContext, servletRequest, null) {
@Override
public Locale getRequestLocale() {
return locale;
}
};
return this.renderer.isRenderable(getUrl(), request);
}
use of org.springframework.web.context.request.RequestAttributes in project spring-framework by spring-projects.
the class ContentNegotiatingViewResolver method resolveViewName.
@Override
public View resolveViewName(String viewName, Locale locale) throws Exception {
RequestAttributes attrs = RequestContextHolder.getRequestAttributes();
Assert.state(attrs instanceof ServletRequestAttributes, "No current ServletRequestAttributes");
List<MediaType> requestedMediaTypes = getMediaTypes(((ServletRequestAttributes) attrs).getRequest());
if (requestedMediaTypes != null) {
List<View> candidateViews = getCandidateViews(viewName, locale, requestedMediaTypes);
View bestView = getBestView(candidateViews, requestedMediaTypes, attrs);
if (bestView != null) {
return bestView;
}
}
if (this.useNotAcceptableStatusCode) {
if (logger.isDebugEnabled()) {
logger.debug("No acceptable view found; returning 406 (Not Acceptable) status code");
}
return NOT_ACCEPTABLE_VIEW;
} else {
logger.debug("No acceptable view found; returning null");
return null;
}
}
use of org.springframework.web.context.request.RequestAttributes in project cuba by cuba-platform.
the class PortalUserSessionSource method getUserSessionFromMiddleware.
protected UserSession getUserSessionFromMiddleware(UUID sessionId) {
UserSession userSession = null;
HttpServletRequest request = null;
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes instanceof ServletRequestAttributes) {
request = ((ServletRequestAttributes) requestAttributes).getRequest();
}
if (request != null) {
userSession = (UserSession) request.getAttribute(REQUEST_ATTR);
}
if (userSession != null) {
return userSession;
}
userSession = userSessionService.getUserSession(sessionId);
if (request != null) {
request.setAttribute(REQUEST_ATTR, userSession);
}
return userSession;
}
use of org.springframework.web.context.request.RequestAttributes in project weixin-java-pay-demo by binarywang.
the class WxErrorController method getErrorAttributes.
private Map<String, Object> getErrorAttributes(HttpServletRequest request, boolean includeStackTrace) {
RequestAttributes requestAttributes = new ServletRequestAttributes(request);
Map<String, Object> map = this.errorAttributes.getErrorAttributes(requestAttributes, includeStackTrace);
logger.error("map is [{}]", map);
String url = request.getRequestURL().toString();
map.put("URL", url);
logger.error("[error info]: status-{}, request url-{}", map.get("status"), url);
return map;
}
use of org.springframework.web.context.request.RequestAttributes in project portal by ixinportal.
the class LogUtil method getRemoteAddr.
private static String getRemoteAddr() {
RequestAttributes ra = RequestContextHolder.getRequestAttributes();
if (null == ra) {
return "127.0.0.1";
}
HttpServletRequest request = ((ServletRequestAttributes) ra).getRequest();
return request.getRemoteAddr();
}
Aggregations