use of org.springframework.web.context.request.RequestAttributes in project midpoint by Evolveum.
the class AbstractRestController method controllerBasePath.
/**
* Returns base path (without servlet context) reflecting currently used request.
* This solves the problem of base path being one of multiple possible mappings.
*/
protected String controllerBasePath() {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes instanceof ServletRequestAttributes) {
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
String servletPath = request.getServletPath();
for (String requestMappingPath : requestMappingPaths) {
if (servletPath.startsWith(requestMappingPath)) {
return requestMappingPath;
}
}
}
throw new NullPointerException("Base controller URL could not be determined.");
}
use of org.springframework.web.context.request.RequestAttributes in project spring-framework by spring-projects.
the class ServletTestExecutionListenerTests method assertRequestAttributesExist.
private RequestAttributes assertRequestAttributesExist() {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
assertThat(requestAttributes).as("request attributes should exist").isNotNull();
return requestAttributes;
}
use of org.springframework.web.context.request.RequestAttributes in project spring-framework by spring-projects.
the class CustomRequestAttributesRequestContextHolderTests method verifyCustomRequestAttributesAreRestored.
@AfterEach
public void verifyCustomRequestAttributesAreRestored() {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
assertThat(requestAttributes).isInstanceOf(ServletRequestAttributes.class);
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
assertThat(request.getAttribute(FROM_CUSTOM_MOCK)).isEqualTo(FROM_CUSTOM_MOCK);
assertThat(request.getAttribute(FROM_MVC_TEST_DEFAULT)).isNull();
assertThat(request.getAttribute(FROM_MVC_TEST_MOCK)).isNull();
RequestContextHolder.resetRequestAttributes();
this.wac.close();
}
use of org.springframework.web.context.request.RequestAttributes in project spring-framework by spring-projects.
the class CustomRequestAttributesRequestContextHolderTests method assertRequestAttributes.
private static void assertRequestAttributes() {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
assertThat(requestAttributes).isInstanceOf(ServletRequestAttributes.class);
assertRequestAttributes(((ServletRequestAttributes) requestAttributes).getRequest());
}
use of org.springframework.web.context.request.RequestAttributes in project spring-framework by spring-projects.
the class RequestContextHolderTests method assertRequestAttributes.
private static void assertRequestAttributes(boolean withinMockMvc) {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
assertThat(requestAttributes).isInstanceOf(ServletRequestAttributes.class);
assertRequestAttributes(((ServletRequestAttributes) requestAttributes).getRequest(), withinMockMvc);
}
Aggregations