Search in sources :

Example 1 with BRouter

use of org.webpieces.router.impl.routers.BRouter in project webpieces by deanhiller.

the class DomainRouteBuilderImpl method build.

public BRouter build() {
    CRouter router = leftOverDomainsBuilder2.buildRouter();
    CRouter backendRouter = backendRouteBuilder2.buildRouter();
    Map<String, CRouter> domainToRouter = new HashMap<>();
    for (Entry<String, AllContentTypesBuilderImpl> entry : domainToRouteBuilder2.entrySet()) {
        CRouter router2 = entry.getValue().buildRouter();
        domainToRouter.put(entry.getKey(), router2);
    }
    return new BRouter(router, backendRouter, domainToRouter);
}
Also used : BRouter(org.webpieces.router.impl.routers.BRouter) HashMap(java.util.HashMap) CRouter(org.webpieces.router.impl.routers.CRouter)

Example 2 with BRouter

use of org.webpieces.router.impl.routers.BRouter in project webpieces by deanhiller.

the class DevelopmentController method notFound.

public Render notFound() {
    RouterRequest request = Current.request();
    String error = request.getSingleMultipart("webpiecesError");
    String url = request.getSingleMultipart("url");
    if (url.contains("?")) {
        url += "&" + NOT_FOUND_KEY + "=true";
    } else {
        url += "?" + NOT_FOUND_KEY + "=true";
    }
    Collection<CRouter> routers = new ArrayList<>();
    CRouter router;
    BRouter domainRouter = routingHolder.getDomainRouter();
    if (request.isBackendRequest) {
        router = domainRouter.getBackendRouter();
    } else {
        router = domainRouter.getLeftOverDomains();
        for (CRouter oneRouter : domainRouter.getDomainToRouter().values()) {
            routers.add(oneRouter);
        }
    }
    RouterRequest req = (RouterRequest) request.requestState.get(ORIGINAL_REQUEST);
    // This is a pain but dynamically build up the html
    String routeHtml = build(req.isHttps, req.method, req.relativePath, router);
    List<String> paths = new ArrayList<>();
    if (req.isHttps) {
        paths.add(req.method + " :https : " + req.relativePath);
    } else {
        paths.add(req.method + " :https : " + req.relativePath);
        paths.add(req.method + " :both  : " + req.relativePath);
    }
    return Actions.renderThis("domains", routers, "paths", paths, "routeHtml", routeHtml, "error", error, "url", url);
}
Also used : BRouter(org.webpieces.router.impl.routers.BRouter) ArrayList(java.util.ArrayList) CRouter(org.webpieces.router.impl.routers.CRouter) RouterRequest(org.webpieces.ctx.api.RouterRequest)

Example 3 with BRouter

use of org.webpieces.router.impl.routers.BRouter in project webpieces by deanhiller.

the class RouteLoader method loadAllRoutes.

// protected abstract void verifyRoutes(Collection<Route> allRoutes);
public void loadAllRoutes(WebAppMeta rm, Injector injector, RoutingHolder routingHolder) {
    log.info("adding routes");
    reverseRoutes = new ReverseRoutes(config, redirectFormation, objectTranslator, reverseTranslator);
    ResettingLogic resettingLogic = new ResettingLogic(reverseRoutes, injector);
    Boolean enableSeparateBackend = backPortExists.get();
    DomainRouteBuilderImpl routerBuilder = new DomainRouteBuilderImpl(routerFutures, futureUtil, routeBuilderLogic, resettingLogic, enableSeparateBackend);
    routingHolder.setReverseRouteLookup(reverseRoutes);
    routeBuilderLogic.init(reverseRoutes);
    List<Routes> all = new ArrayList<>();
    // the core application routes
    all.addAll(rm.getRouteModules());
    List<Plugin> plugins = rm.getPlugins();
    if (plugins != null) {
        for (Plugin plugin : plugins) {
            all.addAll(plugin.getRouteModules());
        }
    }
    for (Routes module : all) {
        CurrentRoutes.set(new RouteModuleInfo(module.getClass()));
        module.configure(routerBuilder);
        CurrentRoutes.set(null);
    }
    log.info("added all routes to router.  Applying Filters");
    reverseRoutes.finalSetup();
    BRouter domainRouter = routerBuilder.build();
    routingHolder.setDomainRouter(domainRouter);
    masterRouter.setDomainRouter(domainRouter);
    log.info("all filters applied");
    compressionCacheSetup.setupCache(routerBuilder.getStaticRoutes());
}
Also used : BRouter(org.webpieces.router.impl.routers.BRouter) ArrayList(java.util.ArrayList) CurrentRoutes(org.webpieces.router.impl.routebldr.CurrentRoutes) Routes(org.webpieces.router.api.routes.Routes) DomainRouteBuilderImpl(org.webpieces.router.impl.routebldr.DomainRouteBuilderImpl) RouteModuleInfo(org.webpieces.router.impl.model.RouteModuleInfo) Plugin(org.webpieces.router.api.plugins.Plugin)

Aggregations

BRouter (org.webpieces.router.impl.routers.BRouter)3 ArrayList (java.util.ArrayList)2 CRouter (org.webpieces.router.impl.routers.CRouter)2 HashMap (java.util.HashMap)1 RouterRequest (org.webpieces.ctx.api.RouterRequest)1 Plugin (org.webpieces.router.api.plugins.Plugin)1 Routes (org.webpieces.router.api.routes.Routes)1 RouteModuleInfo (org.webpieces.router.impl.model.RouteModuleInfo)1 CurrentRoutes (org.webpieces.router.impl.routebldr.CurrentRoutes)1 DomainRouteBuilderImpl (org.webpieces.router.impl.routebldr.DomainRouteBuilderImpl)1