Search in sources :

Example 76 with RequestAttributes

use of org.springframework.web.context.request.RequestAttributes in project spring-framework by spring-projects.

the class ServletTestExecutionListenerTests method assertSetUpOutsideOfStelAttributeDoesNotExist.

private void assertSetUpOutsideOfStelAttributeDoesNotExist() {
    RequestAttributes requestAttributes = assertRequestAttributesExist();
    Object setUpOutsideOfStel = requestAttributes.getAttribute(SET_UP_OUTSIDE_OF_STEL, RequestAttributes.SCOPE_REQUEST);
    assertThat(setUpOutsideOfStel).as(SET_UP_OUTSIDE_OF_STEL + " should NOT exist as a request attribute").isNull();
}
Also used : RequestAttributes(org.springframework.web.context.request.RequestAttributes)

Example 77 with RequestAttributes

use of org.springframework.web.context.request.RequestAttributes in project spring-boot by spring-projects.

the class SpringBootTestWebEnvironmentMockTests method setsRequestContextHolder.

@Test
void setsRequestContextHolder() {
    RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
    assertThat(attributes).isNotNull();
}
Also used : RequestAttributes(org.springframework.web.context.request.RequestAttributes) Test(org.junit.jupiter.api.Test)

Example 78 with RequestAttributes

use of org.springframework.web.context.request.RequestAttributes in project series-rest-api by 52North.

the class RequestUtils method resolveQueryLessRequestUrl.

/**
 * Get the request {@link URL} without the query parameter
 *
 * @param externalUrl
 *            the external URL.
 * @return Request {@link URL} without query parameter
 */
public static String resolveQueryLessRequestUrl(String externalUrl) {
    RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
    HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
    return externalUrl == null || externalUrl.isEmpty() ? createRequestUrl(request) : createRequestUrl(externalUrl);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) RequestAttributes(org.springframework.web.context.request.RequestAttributes)

Example 79 with RequestAttributes

use of org.springframework.web.context.request.RequestAttributes in project uPortal by Jasig.

the class PortalWebUtils method currentRequestContextPath.

/**
 * Get the request context path from the current request. Copes with both HttpServletRequest and
 * PortletRequest and so usable when handling Spring-processed Servlet or Portlet requests.
 * Requires that Spring have bound the request, as in the case of dispatcher servlet or portlet
 * or when the binding filter or listener is active. This should be the case for all requests in
 * the uPortal framework and framework portlets.
 *
 * @return request.getContextPath() for the relevant servlet or portlet request
 * @throws IllegalStateException if the request is not Spring-bound or is neither Servlet nor
 *     Portlet flavored
 */
public static String currentRequestContextPath() {
    final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    if (null == requestAttributes) {
        throw new IllegalStateException("Request attributes are not bound.  " + "Not operating in context of a Spring-processed Request?");
    }
    if (requestAttributes instanceof ServletRequestAttributes) {
        final ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes;
        final HttpServletRequest request = servletRequestAttributes.getRequest();
        return request.getContextPath();
    } else if (requestAttributes instanceof PortletRequestAttributes) {
        final PortletRequestAttributes portletRequestAttributes = (PortletRequestAttributes) requestAttributes;
        final PortletRequest request = portletRequestAttributes.getRequest();
        return request.getContextPath();
    } else {
        throw new IllegalStateException("Request attributes are an unrecognized implementation.");
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PortletRequestAttributes(org.springframework.web.portlet.context.PortletRequestAttributes) PortletRequest(javax.portlet.PortletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) RequestAttributes(org.springframework.web.context.request.RequestAttributes) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) PortletRequestAttributes(org.springframework.web.portlet.context.PortletRequestAttributes)

Example 80 with RequestAttributes

use of org.springframework.web.context.request.RequestAttributes in project uPortal by Jasig.

the class PersonLookupHelperImpl method getVisiblePersons.

/**
 * Returns a list of the personAttributes that this principal has permission to view. This
 * implementation does the check on the list items in parallel because personDirectory is
 * consulted for non-admin principals to get the person attributes which is really slow if done
 * on N entries in parallel because personDirectory often goes out to LDAP or another external
 * source for additional attributes. This processing will not retain list order.
 *
 * @param principal user performing the search
 * @param permittedAttributes set of attributes the principal has permission to view
 * @param peopleList list of people returned from the search
 * @return UNORDERED list of visible persons
 */
private List<IPersonAttributes> getVisiblePersons(final IAuthorizationPrincipal principal, final Set<String> permittedAttributes, List<IPersonAttributes> peopleList) {
    List<Future<IPersonAttributes>> futures = new ArrayList<>();
    List<IPersonAttributes> list = new ArrayList<>();
    // Ugly.  PersonDirectory requires RequestContextHolder to be set for each thread, so pass
    // it
    // into the callable.
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    // user
    for (IPersonAttributes person : peopleList) {
        Callable<IPersonAttributes> worker = new FetchVisiblePersonCallable(principal, person, permittedAttributes, requestAttributes);
        Future<IPersonAttributes> task = executor.submit(worker);
        futures.add(task);
    }
    for (Future<IPersonAttributes> future : futures) {
        try {
            final IPersonAttributes visiblePerson = future.get(searchThreadTimeoutSeconds, TimeUnit.SECONDS);
            if (visiblePerson != null) {
                list.add(visiblePerson);
            }
        } catch (InterruptedException e) {
            logger.error("Processing person search interrupted", e);
        } catch (ExecutionException e) {
            logger.error("Error Processing person search", e);
        } catch (TimeoutException e) {
            future.cancel(true);
            logger.warn("Exceeded {} ms waiting for getVisiblePerson to return result", searchThreadTimeoutSeconds);
        }
    }
    logger.debug("Found {} results", list.size());
    return list;
}
Also used : IPersonAttributes(org.apereo.services.persondir.IPersonAttributes) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) RequestAttributes(org.springframework.web.context.request.RequestAttributes) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

RequestAttributes (org.springframework.web.context.request.RequestAttributes)81 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)51 HttpServletRequest (javax.servlet.http.HttpServletRequest)20 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