Search in sources :

Example 1 with Route

use of io.vertx.reactivex.ext.web.Route in project api-framework by vinscom.

the class SessionRouteBuillder method getRouter.

@Override
public Router getRouter(Router pRouter) {
    Route route = pRouter.route();
    route.handler(BodyHandler.create());
    route.handler(CookieHandler.create());
    route.handler(SessionHandler.create(getSessionStore()));
    return pRouter;
}
Also used : Route(io.vertx.reactivex.ext.web.Route)

Example 2 with Route

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

the class ZeroRxAgent method recordServer.

private void recordServer(final HttpServerOptions options, final Router router) {
    final Integer port = options.getPort();
    final AtomicInteger out = ZeroAtomic.RX_START_LOGS.get(port);
    if (Values.ZERO == out.getAndIncrement()) {
        // 1. Build logs for current server;
        final String portLiteral = String.valueOf(port);
        LOGGER.info(Info.RX_SERVERS, this.NAME, deploymentID(), portLiteral);
        final List<Route> routes = router.getRoutes();
        final Map<String, Route> routeMap = new TreeMap<>();
        for (final Route route : routes) {
            // 2.Route
            final String path = null == route.getPath() ? "/*" : route.getPath();
            routeMap.put(path, route);
        }
        routeMap.forEach((path, route) -> LOGGER.info(Info.MAPPED_ROUTE, this.NAME, path, route.toString()));
        // 3. Endpoint Publish
        final String address = MessageFormat.format("http://{0}:{1}/", options.getHost(), portLiteral);
        LOGGER.info(Info.RX_LISTEN, this.NAME, address);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TreeMap(java.util.TreeMap) Route(io.vertx.reactivex.ext.web.Route)

Example 3 with Route

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

the class ZeroRxAgent method start.

@Override
public void start() {
    /**
     * 1.Call router hub to mount commont *
     */
    final Axis<Router> routerAxiser = Fn.poolThread(Pool.ROUTERS, () -> Instance.instance(RouterAxis.class));
    /**
     * 2.Call route hub to mount defined *
     */
    final Axis<Router> axiser = Fn.poolThread(Pool.EVENTS, () -> Instance.instance(EventAxis.class));
    /**
     * 3.Get the default HttpServer Options *
     */
    ZeroAtomic.RX_OPTS.forEach((port, option) -> {
        /**
         * 3.1.Single server processing *
         */
        final HttpServer server = this.vertx.createHttpServer(option);
        /**
         * 3.2. Build router with current option *
         */
        final Router router = Router.router(this.vertx);
        routerAxiser.mount(router);
        axiser.mount(router);
        /**
         * 3.3. Listen for router on the server *
         */
        final Single<HttpServer> result = server.requestHandler(router::accept).rxListen();
        /**
         * 3.4. Log output *
         */
        {
            result.subscribe((rxServer) -> {
                recordServer(option, router);
            });
        }
    });
}
Also used : ZeroAtomic(io.vertx.up.micro.ZeroAtomic) HttpServer(io.vertx.reactivex.core.http.HttpServer) Fn(io.vertx.up.func.Fn) Router(io.vertx.reactivex.ext.web.Router) ServerType(io.vertx.up.eon.em.ServerType) RouterAxis(io.vertx.rx.rs.router.RouterAxis) Route(io.vertx.reactivex.ext.web.Route) Single(io.reactivex.Single) Instance(io.vertx.up.tool.mirror.Instance) MessageFormat(java.text.MessageFormat) List(java.util.List) Axis(io.vertx.up.rs.Axis) Values(io.vertx.zero.eon.Values) TreeMap(java.util.TreeMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Annal(io.vertx.up.log.Annal) HttpServerOptions(io.vertx.core.http.HttpServerOptions) AbstractVerticle(io.vertx.reactivex.core.AbstractVerticle) EventAxis(io.vertx.rx.rs.router.EventAxis) Agent(io.vertx.up.annotations.Agent) EventAxis(io.vertx.rx.rs.router.EventAxis) RouterAxis(io.vertx.rx.rs.router.RouterAxis) HttpServer(io.vertx.reactivex.core.http.HttpServer) Router(io.vertx.reactivex.ext.web.Router)

Example 4 with Route

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

the class EventAxis method mount.

@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 aim = this.splitter.distribute(event);
            route.handler(this.verifier.signal(depot)).failureHandler(ZeroRxEndurer.create());
        });
    });
}
Also used : Aim(io.vertx.up.rs.Aim) Depot(io.vertx.up.atom.agent.Depot) Route(io.vertx.reactivex.ext.web.Route)

Aggregations

Route (io.vertx.reactivex.ext.web.Route)4 TreeMap (java.util.TreeMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Single (io.reactivex.Single)1 HttpServerOptions (io.vertx.core.http.HttpServerOptions)1 AbstractVerticle (io.vertx.reactivex.core.AbstractVerticle)1 HttpServer (io.vertx.reactivex.core.http.HttpServer)1 Router (io.vertx.reactivex.ext.web.Router)1 EventAxis (io.vertx.rx.rs.router.EventAxis)1 RouterAxis (io.vertx.rx.rs.router.RouterAxis)1 Agent (io.vertx.up.annotations.Agent)1 Depot (io.vertx.up.atom.agent.Depot)1 ServerType (io.vertx.up.eon.em.ServerType)1 Fn (io.vertx.up.func.Fn)1 Annal (io.vertx.up.log.Annal)1 ZeroAtomic (io.vertx.up.micro.ZeroAtomic)1 Aim (io.vertx.up.rs.Aim)1 Axis (io.vertx.up.rs.Axis)1 Instance (io.vertx.up.tool.mirror.Instance)1 Values (io.vertx.zero.eon.Values)1