Search in sources :

Example 11 with Response

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());
}
Also used : Response(com.yahoo.application.container.handler.Response)

Example 12 with Response

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);
}
Also used : Response(com.yahoo.application.container.handler.Response) SecurityRequestFilter(com.yahoo.jdisc.http.filter.SecurityRequestFilter) SecurityRequestFilterChain(com.yahoo.jdisc.http.filter.SecurityRequestFilterChain) FilterChainRepository(com.yahoo.container.http.filter.FilterChainRepository)

Aggregations

Response (com.yahoo.application.container.handler.Response)12 Request (com.yahoo.application.container.handler.Request)7 Test (org.junit.Test)7 File (java.io.File)2 HttpResponse (org.apache.http.HttpResponse)2 MockHttpHandler (com.yahoo.application.container.handlers.MockHttpHandler)1 MockRenderer (com.yahoo.application.container.renderers.MockRenderer)1 Version (com.yahoo.component.Version)1 FilterChainRepository (com.yahoo.container.http.filter.FilterChainRepository)1 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)1 SecurityRequestFilter (com.yahoo.jdisc.http.filter.SecurityRequestFilter)1 SecurityRequestFilterChain (com.yahoo.jdisc.http.filter.SecurityRequestFilterChain)1 Application (com.yahoo.vespa.hosted.controller.Application)1 ApplicationPackage (com.yahoo.vespa.hosted.controller.application.ApplicationPackage)1 JobStatus (com.yahoo.vespa.hosted.controller.application.JobStatus)1 ApplicationPackageBuilder (com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder)1 BuildJob (com.yahoo.vespa.hosted.controller.deployment.BuildJob)1 ContainerControllerTester (com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester)1 ControllerContainerTest (com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest)1 ComparisonFailure (org.junit.ComparisonFailure)1