use of org.springframework.web.context.request.RequestAttributes in project onebusaway-application-modules by camsys.
the class DefaultSearchLocationServiceImpl method setDefaultLocationForCurrentUser.
@Override
public void setDefaultLocationForCurrentUser(String locationName, double lat, double lon) {
_currentUserService.setDefaultLocation(locationName, lat, lon);
DefaultSearchLocation location = new DefaultSearchLocation(locationName, lat, lon, true);
RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
attributes.setAttribute(KEY_DEFAULT_SEARCH_LOCATION_FOR_SESSSION, location, RequestAttributes.SCOPE_SESSION);
}
use of org.springframework.web.context.request.RequestAttributes in project onebusaway-application-modules by camsys.
the class DefaultSearchLocationServiceImpl method clearDefaultLocationForCurrentUser.
@Override
public void clearDefaultLocationForCurrentUser() {
_currentUserService.clearDefaultLocation();
RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
attributes.removeAttribute(KEY_DEFAULT_SEARCH_LOCATION_FOR_SESSSION, RequestAttributes.SCOPE_SESSION);
}
use of org.springframework.web.context.request.RequestAttributes in project spring-framework by spring-projects.
the class ServletWebArgumentResolverAdapter method getWebRequest.
@Override
protected NativeWebRequest getWebRequest() {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
Assert.state(requestAttributes instanceof ServletRequestAttributes, "No ServletRequestAttributes");
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes;
return new ServletWebRequest(servletRequestAttributes.getRequest());
}
use of org.springframework.web.context.request.RequestAttributes in project spring-framework by spring-projects.
the class MockMvc method perform.
/**
* Perform a request and return a type that allows chaining further
* actions, such as asserting expectations, on the result.
* @param requestBuilder used to prepare the request to execute;
* see static factory methods in
* {@link org.springframework.test.web.servlet.request.MockMvcRequestBuilders}
* @return an instance of {@link ResultActions} (never {@code null})
* @see org.springframework.test.web.servlet.request.MockMvcRequestBuilders
* @see org.springframework.test.web.servlet.result.MockMvcResultMatchers
*/
public ResultActions perform(RequestBuilder requestBuilder) throws Exception {
if (this.defaultRequestBuilder != null && requestBuilder instanceof Mergeable) {
requestBuilder = (RequestBuilder) ((Mergeable) requestBuilder).merge(this.defaultRequestBuilder);
}
MockHttpServletRequest request = requestBuilder.buildRequest(this.servletContext);
AsyncContext asyncContext = request.getAsyncContext();
MockHttpServletResponse mockResponse;
HttpServletResponse servletResponse;
if (asyncContext != null) {
servletResponse = (HttpServletResponse) asyncContext.getResponse();
mockResponse = unwrapResponseIfNecessary(servletResponse);
} else {
mockResponse = new MockHttpServletResponse();
servletResponse = mockResponse;
}
if (this.defaultResponseCharacterEncoding != null) {
mockResponse.setDefaultCharacterEncoding(this.defaultResponseCharacterEncoding.name());
}
if (requestBuilder instanceof SmartRequestBuilder) {
request = ((SmartRequestBuilder) requestBuilder).postProcessRequest(request);
}
MvcResult mvcResult = new DefaultMvcResult(request, mockResponse);
request.setAttribute(MVC_RESULT_ATTRIBUTE, mvcResult);
RequestAttributes previousAttributes = RequestContextHolder.getRequestAttributes();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request, servletResponse));
MockFilterChain filterChain = new MockFilterChain(this.servlet, this.filters);
filterChain.doFilter(request, servletResponse);
if (DispatcherType.ASYNC.equals(request.getDispatcherType()) && asyncContext != null && !request.isAsyncStarted()) {
asyncContext.complete();
}
applyDefaultResultActions(mvcResult);
RequestContextHolder.setRequestAttributes(previousAttributes);
return new ResultActions() {
@Override
public ResultActions andExpect(ResultMatcher matcher) throws Exception {
matcher.match(mvcResult);
return this;
}
@Override
public ResultActions andDo(ResultHandler handler) throws Exception {
handler.handle(mvcResult);
return this;
}
@Override
public MvcResult andReturn() {
return mvcResult;
}
};
}
use of org.springframework.web.context.request.RequestAttributes in project spring-framework by spring-projects.
the class ServletTestExecutionListenerTests method assertSetUpOutsideOfStelAttributeExists.
private void assertSetUpOutsideOfStelAttributeExists() {
RequestAttributes requestAttributes = assertRequestAttributesExist();
Object setUpOutsideOfStel = requestAttributes.getAttribute(SET_UP_OUTSIDE_OF_STEL, RequestAttributes.SCOPE_REQUEST);
assertThat(setUpOutsideOfStel).as(SET_UP_OUTSIDE_OF_STEL + " should exist as a request attribute").isNotNull();
}
Aggregations