Search in sources :

Example 11 with ResponseHandler

use of com.yahoo.jdisc.handler.ResponseHandler in project vespa by vespa-engine.

the class ServerProviderConformanceTest method testRequestExceptionBeforeResponseWriteWithAsyncHandleResponse.

private <T extends ServerProvider, U, V> void testRequestExceptionBeforeResponseWriteWithAsyncHandleResponse(final Adapter<T, U, V> adapter, final Module... config) throws Throwable {
    runTest(adapter, Modules.combine(config), RequestType.WITHOUT_CONTENT, new TestRequestHandler() {

        @Override
        public ContentChannel handle(final Request request, final ResponseHandler handler) {
            final Event exceptionHandledByFramework = new Event();
            callInOtherThread(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    exceptionHandledByFramework.await();
                    try {
                        final ContentChannel out = handler.handleResponse(new Response(Response.Status.OK));
                        exceptionHandledByFramework.await();
                        writeResponse(out);
                        closeResponse(out);
                    } catch (Throwable ignored) {
                    }
                    return null;
                }
            });
            throw new ConformanceException(exceptionHandledByFramework);
        }
    });
}
Also used : Response(com.yahoo.jdisc.Response) ResponseHandler(com.yahoo.jdisc.handler.ResponseHandler) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) Request(com.yahoo.jdisc.Request) Callable(java.util.concurrent.Callable)

Example 12 with ResponseHandler

use of com.yahoo.jdisc.handler.ResponseHandler in project vespa by vespa-engine.

the class ProxyRequestHandlerTestCase method requireThatNullResponseContentIsProxied.

@Test
public void requireThatNullResponseContentIsProxied() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    MyRequestHandler requestHandler = MyRequestHandler.newEagerCompletion();
    Request request = newRequest(driver, requestHandler);
    ResponseHandler responseHandler = new ResponseHandler() {

        @Override
        public ContentChannel handleResponse(Response response) {
            return null;
        }
    };
    request.connect(responseHandler).close(null);
    requestHandler.handler.handleResponse(new Response(Response.Status.OK)).close(null);
    request.release();
    assertTrue(driver.close());
}
Also used : ResponseHandler(com.yahoo.jdisc.handler.ResponseHandler) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 13 with ResponseHandler

use of com.yahoo.jdisc.handler.ResponseHandler in project vespa by vespa-engine.

the class JDiscFilterInvokerFilter method runRequestFilterWithMatchingBinding.

private HttpServletRequest runRequestFilterWithMatchingBinding(AtomicReference<Boolean> responseReturned, URI uri, HttpServletRequest request, HttpServletResponse response) throws IOException {
    try {
        RequestFilter requestFilter = jDiscContext.requestFilters.resolve(uri);
        if (requestFilter == null)
            return request;
        ResponseHandler responseHandler = createResponseHandler(responseReturned, request, response);
        return filterInvoker.invokeRequestFilterChain(requestFilter, uri, request, responseHandler);
    } catch (Exception e) {
        throw new RuntimeException("Failed running request filter chain for uri " + uri, e);
    }
}
Also used : ResponseHandler(com.yahoo.jdisc.handler.ResponseHandler) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 14 with ResponseHandler

use of com.yahoo.jdisc.handler.ResponseHandler in project vespa by vespa-engine.

the class FilterTestCase method requireThatRequestFilterChainIsRun.

@Test
public void requireThatRequestFilterChainIsRun() throws Exception {
    final RequestFilter requestFilter1 = mock(RequestFilter.class);
    final RequestFilter requestFilter2 = mock(RequestFilter.class);
    final RequestFilter requestFilterChain = RequestFilterChain.newInstance(requestFilter1, requestFilter2);
    final HttpRequest request = null;
    final ResponseHandler responseHandler = null;
    requestFilterChain.filter(request, responseHandler);
    verify(requestFilter1).filter(any(HttpRequest.class), any(ResponseHandler.class));
    verify(requestFilter2).filter(any(HttpRequest.class), any(ResponseHandler.class));
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) ResponseHandler(com.yahoo.jdisc.handler.ResponseHandler) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) Test(org.testng.annotations.Test)

Example 15 with ResponseHandler

use of com.yahoo.jdisc.handler.ResponseHandler in project vespa by vespa-engine.

the class AccessLoggingRequestHandler method handleRequest.

@Override
public ContentChannel handleRequest(final Request request, final ResponseHandler handler) {
    Preconditions.checkArgument(request instanceof HttpRequest, "Expected HttpRequest, got " + request);
    final HttpRequest httpRequest = (HttpRequest) request;
    httpRequest.context().put(CONTEXT_KEY_ACCESS_LOG_ENTRY, accessLogEntry);
    final ResponseHandler accessLoggingResponseHandler = new AccessLoggingResponseHandler(httpRequest, handler, accessLogEntry);
    final ContentChannel requestContentChannel = delegate.handleRequest(request, accessLoggingResponseHandler);
    return requestContentChannel;
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) ResponseHandler(com.yahoo.jdisc.handler.ResponseHandler) ContentChannel(com.yahoo.jdisc.handler.ContentChannel)

Aggregations

ResponseHandler (com.yahoo.jdisc.handler.ResponseHandler)15 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)7 RequestFilter (com.yahoo.jdisc.http.filter.RequestFilter)7 Response (com.yahoo.jdisc.Response)6 HttpRequest (com.yahoo.jdisc.http.HttpRequest)6 Test (org.testng.annotations.Test)4 Request (com.yahoo.jdisc.Request)3 Callable (java.util.concurrent.Callable)3 RequestDeniedException (com.yahoo.jdisc.handler.RequestDeniedException)2 HttpResponse (com.yahoo.jdisc.http.HttpResponse)2 ResponseFilter (com.yahoo.jdisc.http.filter.ResponseFilter)2 AbstractModule (com.google.inject.AbstractModule)1 AbstractRequestHandler (com.yahoo.jdisc.handler.AbstractRequestHandler)1 BindingNotFoundException (com.yahoo.jdisc.handler.BindingNotFoundException)1 BufferedContentChannel (com.yahoo.jdisc.handler.BufferedContentChannel)1 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)1 FilterBindings (com.yahoo.jdisc.http.server.FilterBindings)1 FilterInvoker (com.yahoo.jdisc.http.server.jetty.FilterInvoker)1 TestDriver (com.yahoo.jdisc.test.TestDriver)1 IOException (java.io.IOException)1