Search in sources :

Example 26 with RequestAttributes

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

Example 27 with RequestAttributes

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);
    }
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) ModelAndView(org.springframework.web.servlet.ModelAndView) BindingAwareModelMap(org.springframework.validation.support.BindingAwareModelMap) RequestAttributes(org.springframework.web.context.request.RequestAttributes) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest)

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

Example 29 with RequestAttributes

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

Example 30 with RequestAttributes

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

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