Search in sources :

Example 1 with RoutingEntry

use of io.knotx.server.configuration.RoutingEntry in project knotx by Cognifide.

the class KnotxEngineHandler method handleRoute.

private void handleRoute(final RoutingContext context, final String address, final Map<String, RoutingEntry> routing) {
    KnotContext knotContext = context.get(KnotContext.KEY);
    proxies.computeIfAbsent(address, adr -> KnotProxy.createProxyWithOptions(vertx, adr, configuration.getDeliveryOptions())).rxProcess(knotContext).doOnSuccess(ctx -> context.put(KnotContext.KEY, ctx)).subscribe(ctx -> OptionalAction.of(Optional.ofNullable(ctx.getTransition())).ifPresent(on -> {
        RoutingEntry entry = routing.get(on);
        if (entry != null) {
            handleRoute(context, entry.address(), entry.onTransition());
        } else {
            LOGGER.debug("Received transition '{}' from '{}'. No further routing available for the transition. Go to the response generation.", on, address);
            // last knot can return default transition
            context.put(KnotContext.KEY, ctx);
            context.next();
        }
    }).ifNotPresent(() -> {
        LOGGER.debug("Request processing finished by {} Knot. Go to the response generation", address);
        context.put(KnotContext.KEY, ctx);
        context.next();
    }), error -> {
        LOGGER.error("Error happened while communicating with {} engine", error, address);
        context.fail(error);
    });
}
Also used : KnotContext(io.knotx.dataobjects.KnotContext) OptionalAction(io.knotx.util.OptionalAction) KnotProxy(io.knotx.reactivex.proxy.KnotProxy) HashMap(java.util.HashMap) RoutingContext(io.vertx.reactivex.ext.web.RoutingContext) LoggerFactory(io.vertx.core.logging.LoggerFactory) RoutingEntry(io.knotx.server.configuration.RoutingEntry) Vertx(io.vertx.reactivex.core.Vertx) Map(java.util.Map) Optional(java.util.Optional) Handler(io.vertx.core.Handler) Logger(io.vertx.core.logging.Logger) KnotxServerConfiguration(io.knotx.server.configuration.KnotxServerConfiguration) RoutingEntry(io.knotx.server.configuration.RoutingEntry) KnotContext(io.knotx.dataobjects.KnotContext)

Aggregations

KnotContext (io.knotx.dataobjects.KnotContext)1 KnotProxy (io.knotx.reactivex.proxy.KnotProxy)1 KnotxServerConfiguration (io.knotx.server.configuration.KnotxServerConfiguration)1 RoutingEntry (io.knotx.server.configuration.RoutingEntry)1 OptionalAction (io.knotx.util.OptionalAction)1 Handler (io.vertx.core.Handler)1 Logger (io.vertx.core.logging.Logger)1 LoggerFactory (io.vertx.core.logging.LoggerFactory)1 Vertx (io.vertx.reactivex.core.Vertx)1 RoutingContext (io.vertx.reactivex.ext.web.RoutingContext)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1