use of com.yahoo.jdisc.handler.RequestHandler in project vespa by vespa-engine.
the class BindingSetTestCase method requireThatTreeWorksForURIWithPathWildCards.
@Test
public void requireThatTreeWorksForURIWithPathWildCards() {
Map<UriPattern, RequestHandler> handlers = new LinkedHashMap<>();
RequestHandler foo = new NonWorkingRequestHandler();
RequestHandler foo1 = new NonWorkingRequestHandler();
RequestHandler foo2 = new NonWorkingRequestHandler();
RequestHandler foo3 = new NonWorkingRequestHandler();
RequestHandler foo4 = new NonWorkingRequestHandler();
RequestHandler foo5 = new NonWorkingRequestHandler();
RequestHandler foo6 = new NonWorkingRequestHandler();
RequestHandler foo7 = new NonWorkingRequestHandler();
RequestHandler foo8 = new NonWorkingRequestHandler();
RequestHandler foo9 = new NonWorkingRequestHandler();
RequestHandler foo10 = new NonWorkingRequestHandler();
RequestHandler foo11 = new NonWorkingRequestHandler();
RequestHandler foo12 = new NonWorkingRequestHandler();
RequestHandler foo13 = new NonWorkingRequestHandler();
RequestHandler foo14 = new NonWorkingRequestHandler();
RequestHandler foo15 = new NonWorkingRequestHandler();
handlers.put(new UriPattern("http://*/config/v1/*"), foo);
handlers.put(new UriPattern("http://*/config/v1/*/"), foo1);
handlers.put(new UriPattern("http://*/config/v1/*/*"), foo2);
handlers.put(new UriPattern("http://*/config/v1/*/*/"), foo3);
handlers.put(new UriPattern("http://*/application/v2/tenant/"), foo4);
handlers.put(new UriPattern("http://*/application/v2/tenant/*"), foo5);
handlers.put(new UriPattern("http://*/application/v2/tenant/*/session"), foo6);
handlers.put(new UriPattern("http://*/application/v2/tenant/*/session/*/prepared"), foo7);
handlers.put(new UriPattern("http://*/application/v2/tenant/*/session/*/active"), foo8);
handlers.put(new UriPattern("http://*/application/v2/tenant/*/session/*/content/*"), foo9);
handlers.put(new UriPattern("http://*/application/v2/tenant/*/application/"), foo10);
handlers.put(new UriPattern("http://*/application/v2/tenant/*/application/*/environment/*/" + "region/*/instance/*/content/*"), foo11);
handlers.put(new UriPattern("http://*/config/v2/tenant/*/application/*/*"), foo12);
handlers.put(new UriPattern("http://*/config/v2/tenant/*/application/*/*/*"), foo13);
handlers.put(new UriPattern("http://*/config/v2/tenant/*/application/*/environment" + "/*/region/*/instance/*/*"), foo14);
handlers.put(new UriPattern("http://*/config/v2/tenant/*/application/*/*/*/"), foo15);
BindingSet<RequestHandler> bindings = new BindingSet<>(handlers.entrySet());
assertNotNull(bindings);
assertSame(foo, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" + "/config/v1/cloud.config.log.logd")));
assertSame(foo1, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" + "/config/v1/cloud.config.log.logd/")));
assertSame(foo2, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" + "/config/v1/cloud.config.log.logd/admin")));
assertSame(foo3, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" + "/config/v1/cloud.config.log.logd/admin/")));
assertSame(foo4, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" + "/application/v2/tenant/")));
assertSame(foo5, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" + "/application/v2/tenant/b")));
assertSame(foo6, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" + "/application/v2/tenant/bar/session")));
assertSame(foo7, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" + "/application/v2/tenant/bar/session/aef/prepared")));
assertSame(foo8, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" + "/application/v2/tenant/bar/session/a/active")));
assertSame(foo9, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" + "/application/v2/tenant/bar/session/aef/content/x")));
assertSame(foo10, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" + "/application/v2/tenant/bar/session/application/")));
assertSame(foo11, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" + "/application/v2/tenant/bar/application/bbc/environment/xyz/region/m/inst" + "ance/a/content/l")));
assertSame(foo12, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" + "/config/v2/tenant/bar/application/bbc/xyz")));
assertSame(foo13, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" + "/config/v2/tenant/bar/application/bbc/xyz/a")));
assertSame(foo14, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" + "/config/v2/tenant/bar/application/bbc/environment/a/region/b/instance/a/b")));
assertSame(foo15, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" + "/config/v2/tenant/bar/application/bbc/xyz/a/c/")));
}
use of com.yahoo.jdisc.handler.RequestHandler in project vespa by vespa-engine.
the class BindingSetTestCase method requireThatSchemeOrderOverHost.
@Test
public void requireThatSchemeOrderOverHost() {
Map<UriPattern, RequestHandler> handlers = new LinkedHashMap<>();
RequestHandler foo = new NonWorkingRequestHandler();
RequestHandler bar = new NonWorkingRequestHandler();
handlers.put(new UriPattern("http://host:5050/a/"), foo);
handlers.put(new UriPattern("ftp://host:5050/a/"), bar);
BindingSet<RequestHandler> bindings = new BindingSet<>(handlers.entrySet());
assertNotNull(bindings);
assertSame(foo, bindings.resolve(URI.create("http://host:5050/a/")));
assertSame(bar, bindings.resolve(URI.create("ftp://host:5050/a/")));
}
use of com.yahoo.jdisc.handler.RequestHandler in project vespa by vespa-engine.
the class ContainerSnapshot method resolveHandler.
@Override
public RequestHandler resolveHandler(Request request) {
BindingMatch<RequestHandler> match = request.isServerRequest() ? serverBindings.match(request.getUri()) : clientBindings.match(request.getUri());
if (match == null) {
return null;
}
request.setBindingMatch(match);
RequestHandler ret = new NullContentRequestHandler(match.target());
if (request.getTimeoutManager() == null) {
ret = timeoutMgr.manageHandler(ret);
}
return ret;
}
use of com.yahoo.jdisc.handler.RequestHandler in project vespa by vespa-engine.
the class Request method connect.
/**
* <p>Attempts to resolve and connect to the {@link RequestHandler} appropriate for the {@link URI} of this Request.
* An exception is thrown if this operation fails at any point. This method is exception-safe.</p>
*
* @param responseHandler The handler to pass the corresponding {@link Response} to.
* @return The {@link ContentChannel} to write the Request content to.
* @throws NullPointerException If the {@link ResponseHandler} is null.
* @throws BindingNotFoundException If the corresponding call to {@link Container#resolveHandler(Request)} returns
* null.
*/
public ContentChannel connect(final ResponseHandler responseHandler) {
try {
Objects.requireNonNull(responseHandler, "responseHandler");
RequestHandler requestHandler = container().resolveHandler(this);
if (requestHandler == null) {
throw new BindingNotFoundException(uri);
}
requestHandler = new ProxyRequestHandler(requestHandler);
ContentChannel content = requestHandler.handleRequest(this, responseHandler);
if (content == null) {
throw new RequestDeniedException(this);
}
return content;
} catch (Throwable t) {
cancel();
throw t;
}
}
use of com.yahoo.jdisc.handler.RequestHandler in project vespa by vespa-engine.
the class VespaFeedHandlerTestCase method setup.
public void setup(com.yahoo.messagebus.Error e, LoadTypeConfig loadTypeCfg, boolean autoReply, DummySessionFactory.ReplyFactory autoReplyFactory) throws Exception {
DocumentTypeManager docMan = new DocumentTypeManager();
DocumentTypeManagerConfigurer.configure(docMan, "file:" + xmlFilesPath + "documentmanager.cfg");
if (autoReply) {
if (autoReplyFactory != null) {
factory = DummySessionFactory.createWithAutoReplyFactory(autoReplyFactory);
} else {
factory = DummySessionFactory.createWithErrorAutoReply(e);
}
} else {
factory = DummySessionFactory.createDefault();
}
context = new FeedContext(new MessagePropertyProcessor(new FeederConfig(new FeederConfig.Builder()), loadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric());
Executor threadPool = Executors.newCachedThreadPool();
feedHandler = new VespaFeedHandler(context, threadPool);
removeHandler = new VespaFeedHandlerRemove(context, threadPool);
statusHandler = new VespaFeedHandlerStatus(context, false, false, threadPool);
removeLocationHandler = new VespaFeedHandlerRemoveLocation(context, threadPool);
CallStack dpCallstack = new CallStack("bar");
dpCallstack.addLast(new TestDocProc());
dpCallstack.addLast(new TestLaterDocProc());
DocprocService myservice = new DocprocService("bar");
myservice.setCallStack(dpCallstack);
myservice.setInService(true);
ComponentRegistry<DocprocService> registry = new ComponentRegistry<DocprocService>();
registry.register(new ComponentId(myservice.getName()), myservice);
DocumentProcessingHandler handler = new DocumentProcessingHandler(registry, new ComponentRegistry<>(), new ComponentRegistry<>(), new DocumentProcessingHandlerParameters());
Container container = Container.get();
ComponentRegistry<RequestHandler> requestHandlerComponentRegistry = new ComponentRegistry<>();
requestHandlerComponentRegistry.register(new ComponentId(DocumentProcessingHandler.class.getName()), handler);
container.setRequestHandlerRegistry(requestHandlerComponentRegistry);
}
Aggregations