Search in sources :

Example 6 with Route

use of io.vertx.ext.web.Route in project vertx-web by vert-x3.

the class TemplateHandlerImplTest method testDefaultIndex.

@Test
public void testDefaultIndex() {
    TemplateEngine templateEngine = mock(TemplateEngine.class);
    RoutingContext routingContext = mock(RoutingContext.class);
    when(routingContext.normalisedPath()).thenReturn("/");
    Route currentRoute = mock(Route.class);
    when(currentRoute.getPath()).thenReturn("/");
    when(routingContext.currentRoute()).thenReturn(currentRoute);
    TemplateHandler templateHandler = new TemplateHandlerImpl(templateEngine, "templates", "ext");
    templateHandler.handle(routingContext);
    verify(templateEngine).render(any(), eq("templates"), eq("/index"), any());
}
Also used : TemplateEngine(io.vertx.ext.web.templ.TemplateEngine) TemplateHandlerImpl(io.vertx.ext.web.handler.impl.TemplateHandlerImpl) RoutingContext(io.vertx.ext.web.RoutingContext) TemplateHandler(io.vertx.ext.web.handler.TemplateHandler) Route(io.vertx.ext.web.Route) Test(org.junit.Test)

Example 7 with Route

use of io.vertx.ext.web.Route in project vertx-web by vert-x3.

the class RouterImpl method getAndCheckRoutePath.

private String getAndCheckRoutePath(RoutingContext ctx) {
    Route currentRoute = ctx.currentRoute();
    String path = currentRoute.getPath();
    if (path == null) {
        throw new IllegalStateException("Sub routers must be mounted on constant paths (no regex or patterns)");
    }
    return path;
}
Also used : Route(io.vertx.ext.web.Route)

Example 8 with Route

use of io.vertx.ext.web.Route in project vertx-web by vert-x3.

the class BlockingHandlerDecorator method handle.

@Override
public void handle(RoutingContext context) {
    Route currentRoute = context.currentRoute();
    context.vertx().executeBlocking(fut -> {
        decoratedHandler.handle(new RoutingContextDecorator(currentRoute, context));
        fut.complete();
    }, ordered, res -> {
        if (res.failed()) {
            // This means an exception was thrown from the blocking handler
            context.fail(res.cause());
        }
    });
}
Also used : Route(io.vertx.ext.web.Route)

Example 9 with Route

use of io.vertx.ext.web.Route in project vertx-zero by silentbalanceyh.

the class EventAxis method mount.

/**
 * Secreter for security limitation
 * 1. Authorization
 * 2. Authorize
 */
@Override
public void mount(final Router router) {
    // Extract Event foreach
    EVENTS.forEach(event -> {
        // Build Route and connect to each Action
        Fn.safeSemi(null == event, LOGGER, () -> LOGGER.warn(Info.NULL_EVENT, getClass().getName()), () -> {
            // 1. Verify
            Verifier.verify(event);
            final Route route = router.route();
            // 2. Path, Method, Order
            Hub<Route> hub = Fn.poolThread(Pool.URIHUBS, () -> Instance.instance(UriHub.class));
            hub.mount(route, event);
            // 3. Consumes/Produces
            hub = Fn.poolThread(Pool.MEDIAHUBS, () -> Instance.instance(MediaHub.class));
            hub.mount(route, event);
            // 4. Request validation
            final Depot depot = Depot.create(event);
            // 5. Request workflow executor: handler
            final Aim<RoutingContext> aim = this.splitter.distribute(event);
            /**
             * 6. Handler chain
             * 1) Mime Analyzer ( Build arguments )
             * 2) Validation
             * 3) Execute handler ( Code Logical )
             * 4) Uniform failure handler
             */
            route.handler(this.verifier.signal(depot)).handler(aim.attack(event)).failureHandler(CommonEndurer.create());
        });
    });
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) Depot(io.vertx.up.atom.agent.Depot) Route(io.vertx.ext.web.Route)

Example 10 with Route

use of io.vertx.ext.web.Route in project vertx-zero by silentbalanceyh.

the class FilterAxis method mount.

@Override
public void mount(final Router router) {
    // Extract Event foreach
    FILTERS.forEach((path, events) -> events.forEach(event -> Fn.safeSemi(null == event, LOGGER, () -> LOGGER.warn(Info.NULL_EVENT, this.getClass().getName()), () -> {
        // Path for filter
        final Route route = router.route();
        Hub<Route> hub = Fn.poolThread(Pool.URIHUBS, () -> Instance.instance(UriHub.class));
        hub.mount(route, event);
        // Consumes/Produces
        hub = Fn.poolThread(Pool.MEDIAHUBS, () -> Instance.instance(MediaHub.class));
        hub.mount(route, event);
        // Filter Handler execution
        route.handler(context -> {
            // Execute method
            final Method method = event.getAction();
            final Object proxy = event.getProxy();
            // Call
            this.execute(context, proxy, method);
        });
    })));
}
Also used : Route(io.vertx.ext.web.Route) Event(io.vertx.up.atom.agent.Event) HttpServerRequest(io.vertx.core.http.HttpServerRequest) Fn(io.vertx.up.func.Fn) Router(io.vertx.ext.web.Router) Set(java.util.Set) RoutingContext(io.vertx.ext.web.RoutingContext) Instance(io.vertx.up.tool.mirror.Instance) ConcurrentMap(java.util.concurrent.ConcurrentMap) Axis(io.vertx.up.rs.Axis) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Annal(io.vertx.up.log.Annal) ZeroAnno(io.vertx.up.web.ZeroAnno) Method(java.lang.reflect.Method) Method(java.lang.reflect.Method) Route(io.vertx.ext.web.Route)

Aggregations

Route (io.vertx.ext.web.Route)30 JsonObject (io.vertx.core.json.JsonObject)17 ServerCacheException (com.arm.mbed.cloud.sdk.testserver.cache.ServerCacheException)14 UnknownAPIException (com.arm.mbed.cloud.sdk.testserver.internal.model.UnknownAPIException)14 APICallException (com.arm.mbed.cloud.sdk.testutils.APICallException)14 MissingInstanceException (com.arm.mbed.cloud.sdk.testserver.cache.MissingInstanceException)13 RoutingContext (io.vertx.ext.web.RoutingContext)10 Router (io.vertx.ext.web.Router)7 HttpMethod (io.vertx.core.http.HttpMethod)4 AbstractVerticle (io.vertx.core.AbstractVerticle)3 Handler (io.vertx.core.Handler)3 HttpServerResponse (io.vertx.core.http.HttpServerResponse)3 TemplateHandler (io.vertx.ext.web.handler.TemplateHandler)3 TemplateHandlerImpl (io.vertx.ext.web.handler.impl.TemplateHandlerImpl)3 TemplateEngine (io.vertx.ext.web.templ.TemplateEngine)3 Date (java.util.Date)3 Map (java.util.Map)3 Set (java.util.Set)3 Test (org.junit.Test)3 APIMethodResult (com.arm.mbed.cloud.sdk.testserver.internal.model.APIMethodResult)2