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();
}
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();
}
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);
}
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.");
}
}
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;
}
Aggregations