use of com.yahoo.application.container.handler.Response in project vespa by vespa-engine.
the class ContainerTester method assertResponse.
public void assertResponse(Request request, String expectedResponse, int expectedStatusCode) throws IOException {
FilterResult filterResult = invokeSecurityFilters(request);
request = filterResult.request;
Response response = filterResult.response != null ? filterResult.response : container.handleRequest(request);
assertEquals(expectedResponse, response.getBodyAsString());
assertEquals("Status code", expectedStatusCode, response.getStatus());
}
use of com.yahoo.application.container.handler.Response in project vespa by vespa-engine.
the class ContainerTester method invokeSecurityFilters.
// Hack to run request filters as part of the request processing chain.
// Limitation: Bindings ignored, disc filter request wrapper only support limited set of methods.
private FilterResult invokeSecurityFilters(Request request) {
FilterChainRepository filterChainRepository = (FilterChainRepository) container.components().getComponent(FilterChainRepository.class.getName());
SecurityRequestFilterChain chain = (SecurityRequestFilterChain) filterChainRepository.getFilter(ComponentSpecification.fromString("default"));
for (SecurityRequestFilter securityRequestFilter : chain.getFilters()) {
ApplicationRequestToDiscFilterRequestWrapper discFilterRequest = new ApplicationRequestToDiscFilterRequestWrapper(request);
ResponseHandlerToApplicationResponseWrapper responseHandlerWrapper = new ResponseHandlerToApplicationResponseWrapper();
securityRequestFilter.filter(discFilterRequest, responseHandlerWrapper);
request = discFilterRequest.getUpdatedRequest();
Optional<Response> filterResponse = responseHandlerWrapper.toResponse();
if (filterResponse.isPresent()) {
return new FilterResult(request, filterResponse.get());
}
}
return new FilterResult(request, null);
}
Aggregations