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");
}
}
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;
}
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;
}
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")));
}
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")));
}
Aggregations