use of jakarta.servlet.http.HttpServletResponse in project spring-framework by spring-projects.
the class BaseViewTests method pathVarsOverrideStaticAttributes.
@Test
public void pathVarsOverrideStaticAttributes() throws Exception {
WebApplicationContext wac = mock(WebApplicationContext.class);
given(wac.getServletContext()).willReturn(new MockServletContext());
HttpServletRequest request = new MockHttpServletRequest();
HttpServletResponse response = new MockHttpServletResponse();
TestView tv = new TestView(wac);
tv.setApplicationContext(wac);
Properties p = new Properties();
p.setProperty("one", "bar");
p.setProperty("something", "else");
tv.setAttributes(p);
Map<String, Object> pathVars = new HashMap<>();
pathVars.put("one", new HashMap<>());
pathVars.put("two", new Object());
request.setAttribute(View.PATH_VARIABLES, pathVars);
tv.render(new HashMap<>(), request, response);
checkContainsAll(pathVars, tv.model);
assertThat(tv.model.size()).isEqualTo(3);
assertThat(tv.model.get("something")).isEqualTo("else");
assertThat(tv.initialized).isTrue();
}
use of jakarta.servlet.http.HttpServletResponse in project spring-framework by spring-projects.
the class BaseViewTests method renderWithoutStaticAttributes.
@Test
public void renderWithoutStaticAttributes() throws Exception {
WebApplicationContext wac = mock(WebApplicationContext.class);
given(wac.getServletContext()).willReturn(new MockServletContext());
HttpServletRequest request = new MockHttpServletRequest();
HttpServletResponse response = new MockHttpServletResponse();
TestView tv = new TestView(wac);
// Check superclass handles duplicate init
tv.setApplicationContext(wac);
tv.setApplicationContext(wac);
Map<String, Object> model = new HashMap<>();
model.put("foo", "bar");
model.put("something", new Object());
tv.render(model, request, response);
checkContainsAll(model, tv.model);
assertThat(tv.initialized).isTrue();
}
use of jakarta.servlet.http.HttpServletResponse in project spring-security by spring-projects.
the class MiscHttpConfigTests method getWhenUsingCustomRequestRejectedHandlerThenRequestRejectedHandlerIsInvoked.
@Test
public void getWhenUsingCustomRequestRejectedHandlerThenRequestRejectedHandlerIsInvoked() throws Exception {
this.spring.configLocations(xml("RequestRejectedHandler")).autowire();
HttpServletResponse response = new MockHttpServletResponse();
RequestRejectedException rejected = new RequestRejectedException("failed");
HttpFirewall firewall = this.spring.getContext().getBean(HttpFirewall.class);
RequestRejectedHandler requestRejectedHandler = this.spring.getContext().getBean(RequestRejectedHandler.class);
given(firewall.getFirewalledRequest(any(HttpServletRequest.class))).willThrow(rejected);
this.mvc.perform(get("/unprotected"));
verify(requestRejectedHandler).handle(any(), any(), any());
}
use of jakarta.servlet.http.HttpServletResponse in project tomcat by apache.
the class ApplicationDispatcher method wrapResponse.
/**
* Create and return a response wrapper that has been inserted in the
* appropriate spot in the response chain.
*/
private ServletResponse wrapResponse(State state) {
// Locate the response we should insert in front of
ServletResponse previous = null;
ServletResponse current = state.outerResponse;
while (current != null) {
if (state.hresponse == null && (current instanceof HttpServletResponse)) {
state.hresponse = (HttpServletResponse) current;
if (!state.including) {
// Forward only needs hresponse
return null;
}
}
if (!(current instanceof ServletResponseWrapper)) {
break;
}
if (current instanceof ApplicationHttpResponse) {
break;
}
if (current instanceof ApplicationResponse) {
break;
}
previous = current;
current = ((ServletResponseWrapper) current).getResponse();
}
// Instantiate a new wrapper at this point and insert it in the chain
ServletResponse wrapper = null;
if ((current instanceof ApplicationHttpResponse) || (current instanceof Response) || (current instanceof HttpServletResponse)) {
wrapper = new ApplicationHttpResponse((HttpServletResponse) current, state.including);
} else {
wrapper = new ApplicationResponse(current, state.including);
}
if (previous == null) {
state.outerResponse = wrapper;
} else {
((ServletResponseWrapper) previous).setResponse(wrapper);
}
state.wrapResponse = wrapper;
return wrapper;
}
use of jakarta.servlet.http.HttpServletResponse in project tomcat by apache.
the class AddDefaultCharsetFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// Wrap the response
if (response instanceof HttpServletResponse) {
ResponseWrapper wrapped = new ResponseWrapper((HttpServletResponse) response, encoding);
chain.doFilter(request, wrapped);
} else {
chain.doFilter(request, response);
}
}
Aggregations