Search in sources :

Example 11 with RequestHandler

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/")));
}
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 12 with RequestHandler

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/")));
}
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 13 with RequestHandler

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;
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler)

Example 14 with RequestHandler

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;
    }
}
Also used : RequestHandler(com.yahoo.jdisc.handler.RequestHandler) RequestDeniedException(com.yahoo.jdisc.handler.RequestDeniedException) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) BindingNotFoundException(com.yahoo.jdisc.handler.BindingNotFoundException)

Example 15 with RequestHandler

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);
}
Also used : ClusterList(com.yahoo.vespaclient.ClusterList) CallStack(com.yahoo.docproc.CallStack) FeederConfig(com.yahoo.vespaclient.config.FeederConfig) Container(com.yahoo.container.Container) Executor(java.util.concurrent.Executor) DocumentProcessingHandler(com.yahoo.docproc.jdisc.DocumentProcessingHandler) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) ComponentRegistry(com.yahoo.component.provider.ComponentRegistry) FeedContext(com.yahoo.feedapi.FeedContext) ComponentId(com.yahoo.component.ComponentId) DocumentProcessingHandlerParameters(com.yahoo.docproc.jdisc.DocumentProcessingHandlerParameters)

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