Search in sources :

Example 1 with RequestHandler

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

the class ApplicationTest method handler.

@Test
public void handler() throws Exception {
    try (ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container().handler("http://*/*", MockHttpHandler.class))))) {
        RequestHandler handler = app.getRequestHandlerById(MockHttpHandler.class.getName());
        assertNotNull(handler);
        Request request = new Request("http://localhost:" + getDefaults().vespaWebServicePort() + "/");
        Response response = app.handleRequest(request);
        assertNotNull(response);
        assertEquals(response.getStatus(), 200);
        assertEquals(response.getBodyAsString(), "OK");
        request = new Request("http://localhost");
        response = app.handleRequest(request);
        assertNotNull(response);
        assertEquals(response.getStatus(), 200);
        assertEquals(response.getBodyAsString(), "OK");
        request = new Request("http://localhost/query=foo");
        response = app.handleRequest(request);
        assertNotNull(response);
        assertEquals(response.getStatus(), 200);
        assertEquals(response.getBodyAsString(), "OK");
    }
}
Also used : MockHttpHandler(com.yahoo.application.container.handlers.MockHttpHandler) Response(com.yahoo.application.container.handler.Response) HttpResponse(org.apache.http.HttpResponse) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) Request(com.yahoo.application.container.handler.Request) Test(org.junit.Test)

Example 2 with RequestHandler

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

the class BindingsOverviewHandler method renderRequestHandlers.

static JSONArray renderRequestHandlers(JdiscBindingsConfig bindingsConfig, Map<ComponentId, ? extends RequestHandler> handlersById) {
    JSONArray ret = new JSONArray();
    for (Map.Entry<ComponentId, ? extends RequestHandler> handlerEntry : handlersById.entrySet()) {
        String id = handlerEntry.getKey().stringValue();
        RequestHandler handler = handlerEntry.getValue();
        JSONObject handlerJson = renderComponent(handler, handlerEntry.getKey());
        addBindings(bindingsConfig, id, handlerJson);
        ret.put(handlerJson);
    }
    return ret;
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) AbstractRequestHandler(com.yahoo.jdisc.handler.AbstractRequestHandler) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Map(java.util.Map) ComponentId(com.yahoo.component.ComponentId)

Example 3 with RequestHandler

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

the class ApplicationStatusHandler method renderRequestHandlers.

static JSONArray renderRequestHandlers(JdiscBindingsConfig bindingsConfig, Map<ComponentId, ? extends RequestHandler> handlersById) {
    JSONArray ret = new JSONArray();
    for (Map.Entry<ComponentId, ? extends RequestHandler> handlerEntry : handlersById.entrySet()) {
        String id = handlerEntry.getKey().stringValue();
        RequestHandler handler = handlerEntry.getValue();
        JSONObject handlerJson = renderComponent(handler, handlerEntry.getKey());
        addBindings(bindingsConfig, id, handlerJson);
        ret.put(handlerJson);
    }
    return ret;
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) AbstractRequestHandler(com.yahoo.jdisc.handler.AbstractRequestHandler) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Map(java.util.Map) ComponentId(com.yahoo.component.ComponentId)

Example 4 with RequestHandler

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

the class BindingSetTestCase method requireThatSimpleResolutionWorks.

@Test
public void requireThatSimpleResolutionWorks() {
    Map<UriPattern, RequestHandler> handlers = new LinkedHashMap<>();
    RequestHandler foo = new NonWorkingRequestHandler();
    handlers.put(new UriPattern("http://host/foo"), foo);
    RequestHandler bar = new NonWorkingRequestHandler();
    handlers.put(new UriPattern("http://host/bar"), bar);
    BindingSet<RequestHandler> bindings = new BindingSet<>(handlers.entrySet());
    BindingMatch<RequestHandler> match = bindings.match(URI.create("http://host/foo"));
    assertNotNull(match);
    assertEquals(0, match.groupCount());
    assertSame(foo, match.target());
    assertSame(foo, bindings.resolve(URI.create("http://host/foo")));
    assertNotNull(match = bindings.match(URI.create("http://host/bar")));
    assertEquals(0, match.groupCount());
    assertSame(bar, match.target());
    assertSame(bar, bindings.resolve(URI.create("http://host/bar")));
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 5 with RequestHandler

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

the class BindingSetTestCase method requireThatPatternResolutionWorks.

@Test
public void requireThatPatternResolutionWorks() {
    Map<UriPattern, RequestHandler> handlers = new LinkedHashMap<>();
    RequestHandler foo = new NonWorkingRequestHandler();
    handlers.put(new UriPattern("http://host/*"), foo);
    RequestHandler bar = new NonWorkingRequestHandler();
    handlers.put(new UriPattern("http://host/path"), bar);
    BindingSet<RequestHandler> bindings = new BindingSet<>(handlers.entrySet());
    BindingMatch<RequestHandler> match = bindings.match(URI.create("http://host/anon"));
    assertNotNull(match);
    assertEquals(1, match.groupCount());
    assertEquals("anon", match.group(0));
    assertSame(foo, match.target());
    assertSame(foo, bindings.resolve(URI.create("http://host/anon")));
    assertNotNull(match = bindings.match(URI.create("http://host/path")));
    assertEquals(0, match.groupCount());
    assertSame(bar, match.target());
    assertSame(bar, bindings.resolve(URI.create("http://host/path")));
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

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