Search in sources :

Example 41 with RequestAttributes

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(org.apache.tiles.request.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) AbstractRequest(org.apache.tiles.request.AbstractRequest) ServletRequest(org.apache.tiles.request.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.apache.tiles.request.Request) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) RequestAttributes(org.springframework.web.context.request.RequestAttributes)

Example 42 with RequestAttributes

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;
    }
}
Also used : ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) MediaType(org.springframework.http.MediaType) RequestAttributes(org.springframework.web.context.request.RequestAttributes) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) SmartView(org.springframework.web.servlet.SmartView) View(org.springframework.web.servlet.View)

Example 43 with RequestAttributes

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UserSession(com.haulmont.cuba.security.global.UserSession) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) RequestAttributes(org.springframework.web.context.request.RequestAttributes)

Example 44 with RequestAttributes

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;
}
Also used : ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) RequestAttributes(org.springframework.web.context.request.RequestAttributes)

Example 45 with RequestAttributes

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();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) RequestAttributes(org.springframework.web.context.request.RequestAttributes) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes)

Aggregations

RequestAttributes (org.springframework.web.context.request.RequestAttributes)76 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)46 HttpServletRequest (javax.servlet.http.HttpServletRequest)15 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)15 Test (org.junit.Test)11 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 DefaultPrettyPrinter (com.fasterxml.jackson.core.util.DefaultPrettyPrinter)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Response (javax.ws.rs.core.Response)3 XWorkRequestAttributes (org.onebusaway.presentation.impl.users.XWorkRequestAttributes)3 DBUnitTest (org.orcid.test.DBUnitTest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 ProjectService (ca.corefacility.bioinformatics.irida.service.ProjectService)2 UserService (ca.corefacility.bioinformatics.irida.service.user.UserService)2 UserSession (com.haulmont.cuba.security.global.UserSession)2 ActionContext (com.opensymphony.xwork2.ActionContext)2 RecordDefinition (com.revolsys.record.schema.RecordDefinition)2 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)2