Search in sources :

Example 21 with RequestHandler

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

the class NonWorkingRequestHandlerTestCase method requireThatHandleRequestThrowsException.

@Test
public void requireThatHandleRequestThrowsException() {
    RequestHandler requestHandler = new NonWorkingRequestHandler();
    try {
        requestHandler.handleRequest(null, null);
        fail();
    } catch (UnsupportedOperationException e) {
    }
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) Test(org.junit.Test)

Example 22 with RequestHandler

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

the class NonWorkingRequestHandlerTestCase method requireThatDestroyDoesNotThrow.

@Test
public void requireThatDestroyDoesNotThrow() {
    RequestHandler requestHandler = new NonWorkingRequestHandler();
    requestHandler.release();
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) Test(org.junit.Test)

Example 23 with RequestHandler

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

the class HttpServerTest method mockRequestHandler.

private static RequestHandler mockRequestHandler() {
    final RequestHandler mockRequestHandler = mock(RequestHandler.class);
    when(mockRequestHandler.refer()).thenReturn(References.NOOP_REFERENCE);
    return mockRequestHandler;
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) AbstractRequestHandler(com.yahoo.jdisc.handler.AbstractRequestHandler)

Example 24 with RequestHandler

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

the class FilteringRequestHandler method handleRequest.

@Override
public ContentChannel handleRequest(Request request, ResponseHandler originalResponseHandler) {
    Preconditions.checkArgument(request instanceof HttpRequest, "Expected HttpRequest, got " + request);
    Objects.requireNonNull(originalResponseHandler, "responseHandler");
    RequestFilter requestFilter = requestFilters.resolve(request.getUri());
    ResponseFilter responseFilter = responseFilters.resolve(request.getUri());
    // Not using request.connect() here - it adds logic for error handling that we'd rather leave to the framework.
    RequestHandler resolvedRequestHandler = request.container().resolveHandler(request);
    if (resolvedRequestHandler == null) {
        throw new BindingNotFoundException(request.getUri());
    }
    RequestHandler requestHandler = new ReferenceCountingRequestHandler(resolvedRequestHandler);
    ResponseHandler responseHandler;
    if (responseFilter != null) {
        responseHandler = new FilteringResponseHandler(originalResponseHandler, responseFilter, request);
    } else {
        responseHandler = originalResponseHandler;
    }
    if (requestFilter != null) {
        InterceptingResponseHandler interceptingResponseHandler = new InterceptingResponseHandler(responseHandler);
        requestFilter.filter(HttpRequest.class.cast(request), interceptingResponseHandler);
        if (interceptingResponseHandler.hasProducedResponse()) {
            return COMPLETING_CONTENT_CHANNEL;
        }
    }
    ContentChannel contentChannel = requestHandler.handleRequest(request, responseHandler);
    if (contentChannel == null) {
        throw new RequestDeniedException(request);
    }
    return contentChannel;
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) AbstractRequestHandler(com.yahoo.jdisc.handler.AbstractRequestHandler) ResponseHandler(com.yahoo.jdisc.handler.ResponseHandler) RequestDeniedException(com.yahoo.jdisc.handler.RequestDeniedException) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) ResponseFilter(com.yahoo.jdisc.http.filter.ResponseFilter) BindingNotFoundException(com.yahoo.jdisc.handler.BindingNotFoundException) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter)

Example 25 with RequestHandler

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

the class ConfiguredApplication method addHandlerBindings.

private static void addHandlerBindings(ContainerBuilder builder, ComponentRegistry<RequestHandler> requestHandlerRegistry, JdiscBindingsConfig discBindingsConfig) {
    for (Map.Entry<String, JdiscBindingsConfig.Handlers> handlerEntry : discBindingsConfig.handlers().entrySet()) {
        String id = handlerEntry.getKey();
        JdiscBindingsConfig.Handlers handlerConfig = handlerEntry.getValue();
        RequestHandler handler = requestHandlerRegistry.getComponent(id);
        if (handler == null) {
            throw new RuntimeException("Binding configured for non-jdisc request handler " + id);
        }
        bindUri(builder.serverBindings(), handlerConfig.serverBindings(), handler);
        bindUri(builder.clientBindings(), handlerConfig.clientBindings(), handler);
    }
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap)

Aggregations

RequestHandler (com.yahoo.jdisc.handler.RequestHandler)43 Test (org.junit.Test)33 NonWorkingRequestHandler (com.yahoo.jdisc.test.NonWorkingRequestHandler)23 LinkedHashMap (java.util.LinkedHashMap)19 TestDriver (com.yahoo.jdisc.test.TestDriver)6 Map (java.util.Map)6 AbstractRequestHandler (com.yahoo.jdisc.handler.AbstractRequestHandler)5 ComponentId (com.yahoo.component.ComponentId)4 ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)4 BindingSet (com.yahoo.jdisc.application.BindingSet)3 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)3 Container (com.yahoo.container.Container)2 RequestHandlerTestDriver (com.yahoo.container.jdisc.RequestHandlerTestDriver)2 ThreadedHttpRequestHandler (com.yahoo.container.jdisc.ThreadedHttpRequestHandler)2 DocumentProcessingHandler (com.yahoo.docproc.jdisc.DocumentProcessingHandler)2 Request (com.yahoo.jdisc.Request)2 UriPattern (com.yahoo.jdisc.application.UriPattern)2 BindingNotFoundException (com.yahoo.jdisc.handler.BindingNotFoundException)2 RequestDeniedException (com.yahoo.jdisc.handler.RequestDeniedException)2 JSONArray (org.json.JSONArray)2