Search in sources :

Example 26 with RequestHandler

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

the class ApplicationStatusHandlerTest method request_handlers_are_rendered.

@Test
public void request_handlers_are_rendered() throws Exception {
    final String id = "myHandler";
    final String serverBinding1 = "http://*/serverBinding";
    final String serverBinding2 = "http://*/anotherServerBinding";
    final String clientBinding = "http://*/clientBinding";
    HashMap<ComponentId, RequestHandler> handlersById = new HashMap<>();
    handlersById.put(new ComponentId(id), Mockito.mock(RequestHandler.class));
    JdiscBindingsConfig bindingsConfig = new JdiscBindingsConfig(new JdiscBindingsConfig.Builder().handlers(id, new Handlers.Builder().serverBindings(serverBinding1).serverBindings(serverBinding2).clientBindings(clientBinding)));
    String json = ApplicationStatusHandler.renderRequestHandlers(bindingsConfig, handlersById).toString();
    assertThat(json, containsString("\"" + id + "\""));
    assertThat(json, containsString(serverBinding1));
    assertThat(json, containsString(serverBinding2));
    assertThat(json, containsString(clientBinding));
}
Also used : Handlers(com.yahoo.container.jdisc.JdiscBindingsConfig.Handlers) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) HashMap(java.util.HashMap) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ComponentId(com.yahoo.component.ComponentId) JdiscBindingsConfig(com.yahoo.container.jdisc.JdiscBindingsConfig) Test(org.junit.Test)

Example 27 with RequestHandler

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

the class MessagePropertyProcessor method getDocprocServiceRegistry.

public synchronized ComponentRegistry<DocprocService> getDocprocServiceRegistry(HttpRequest request) {
    String docprocChain = getDocprocChainParameter(request);
    if (docprocChain == null) {
        return null;
    }
    Container container = Container.get();
    if (container == null) {
        throw new IllegalStateException("Could not get Container instance.");
    }
    ComponentRegistry<RequestHandler> requestHandlerRegistry = container.getRequestHandlerRegistry();
    if (requestHandlerRegistry == null) {
        throw new IllegalStateException("Could not get requesthandlerregistry.");
    }
    DocumentProcessingHandler handler = (DocumentProcessingHandler) requestHandlerRegistry.getComponent(DocumentProcessingHandler.class.getName());
    if (handler == null) {
        return null;
    }
    ComponentRegistry<DocprocService> services = handler.getDocprocServiceRegistry();
    if (services == null) {
        throw new IllegalStateException("Could not get DocprocServiceRegistry.");
    }
    return services;
}
Also used : Container(com.yahoo.container.Container) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) DocumentProcessingHandler(com.yahoo.docproc.jdisc.DocumentProcessingHandler) DocprocService(com.yahoo.docproc.DocprocService)

Example 28 with RequestHandler

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

the class ActiveContainerTestCase method requireThatClientBindingAccessorWorks.

@Test
public void requireThatClientBindingAccessorWorks() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    RequestHandler foo = new NonWorkingRequestHandler();
    RequestHandler bar = new NonWorkingRequestHandler();
    builder.clientBindings().bind("http://host/foo", foo);
    builder.clientBindings("bar").bind("http://host/bar", bar);
    ActiveContainer container = new ActiveContainer(builder);
    Map<String, BindingSet<RequestHandler>> bindings = container.clientBindings();
    assertNotNull(bindings);
    assertEquals(2, bindings.size());
    BindingSet<RequestHandler> set = bindings.get(BindingSet.DEFAULT);
    assertNotNull(set);
    Iterator<Map.Entry<UriPattern, RequestHandler>> it = set.iterator();
    assertNotNull(it);
    assertTrue(it.hasNext());
    Map.Entry<UriPattern, RequestHandler> entry = it.next();
    assertNotNull(entry);
    assertEquals(new UriPattern("http://host/foo"), entry.getKey());
    assertSame(foo, entry.getValue());
    assertFalse(it.hasNext());
    assertNotNull(set = bindings.get("bar"));
    assertNotNull(it = set.iterator());
    assertTrue(it.hasNext());
    assertNotNull(entry = it.next());
    assertEquals(new UriPattern("http://host/bar"), entry.getKey());
    assertSame(bar, entry.getValue());
    assertFalse(it.hasNext());
    assertNotNull(bindings = container.serverBindings());
    assertEquals(1, bindings.size());
    assertNotNull(set = bindings.get(BindingSet.DEFAULT));
    assertNotNull(it = set.iterator());
    assertFalse(it.hasNext());
    driver.close();
}
Also used : BindingSet(com.yahoo.jdisc.application.BindingSet) UriPattern(com.yahoo.jdisc.application.UriPattern) TestDriver(com.yahoo.jdisc.test.TestDriver) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) Map(java.util.Map) Test(org.junit.Test)

Example 29 with RequestHandler

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

the class ActiveContainerTestCase method requireThatDefaultBindingsAreAlwaysCreated.

@Test
public void requireThatDefaultBindingsAreAlwaysCreated() {
    TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
    ContainerBuilder builder = driver.newContainerBuilder();
    ActiveContainer container = new ActiveContainer(builder);
    Map<String, BindingSet<RequestHandler>> bindings = container.serverBindings();
    assertNotNull(bindings);
    assertEquals(1, bindings.size());
    BindingSet<RequestHandler> set = bindings.get(BindingSet.DEFAULT);
    assertFalse(set.iterator().hasNext());
    driver.close();
}
Also used : BindingSet(com.yahoo.jdisc.application.BindingSet) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) NonWorkingRequestHandler(com.yahoo.jdisc.test.NonWorkingRequestHandler) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 30 with RequestHandler

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

the class NonWorkingRequestHandlerTestCase method requireThatHandleTimeoutThrowsException.

@Test
public void requireThatHandleTimeoutThrowsException() {
    RequestHandler requestHandler = new NonWorkingRequestHandler();
    try {
        requestHandler.handleTimeout(null, null);
        fail();
    } catch (UnsupportedOperationException e) {
    }
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) 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