Search in sources :

Example 1 with Plugin

use of org.webpieces.router.api.plugins.Plugin in project webpieces by deanhiller.

the class DevServerMeta method getPlugins.

@Override
public List<Plugin> getPlugins() {
    List<Plugin> prodPlugins = prodMeta.getPlugins();
    List<Plugin> devPlugins = Lists.newArrayList(// so the in-memory H2 DB can be queried to debug issues with your application code
    new H2DbPlugin(new H2DbConfig()), new WebpiecesDocumentationPlugin(new DocumentationConfig()));
    prodPlugins.addAll(devPlugins);
    return prodPlugins;
}
Also used : WebpiecesDocumentationPlugin(org.webpieces.plugin.documentation.WebpiecesDocumentationPlugin) H2DbConfig(org.webpieces.plugin.hsqldb.H2DbConfig) DocumentationConfig(org.webpieces.plugin.documentation.DocumentationConfig) WebpiecesDocumentationPlugin(org.webpieces.plugin.documentation.WebpiecesDocumentationPlugin) H2DbPlugin(org.webpieces.plugin.hsqldb.H2DbPlugin) Plugin(org.webpieces.router.api.plugins.Plugin) H2DbPlugin(org.webpieces.plugin.hsqldb.H2DbPlugin)

Example 2 with Plugin

use of org.webpieces.router.api.plugins.Plugin in project webpieces by deanhiller.

the class JsonMeta method getPlugins.

@Override
public List<Plugin> getPlugins() {
    JacksonConfig config = new JacksonConfig("/json/.*");
    config.setFilterClazz(TestCatchAllFilter.class);
    config.setNotFoundFilterClazz(TestNotFoudSubclassFilter.class);
    return Lists.<Plugin>newArrayList(new JacksonPlugin(config));
}
Also used : JacksonConfig(org.webpieces.plugin.json.JacksonConfig) JacksonPlugin(org.webpieces.plugin.json.JacksonPlugin) JacksonPlugin(org.webpieces.plugin.json.JacksonPlugin) Plugin(org.webpieces.router.api.plugins.Plugin)

Example 3 with Plugin

use of org.webpieces.router.api.plugins.Plugin in project webpieces by deanhiller.

the class RouteLoader method createTHEModule.

// private XFuture<Void> setupSimpleStorage(Injector injector) {
// SimpleStorage storage = injector.getInstance(SimpleStorage.class);
// 
// List<XFuture<?>> futures = new ArrayList<>();
// List<NeedsSimpleStorage> needsStorage = config.getNeedsStorage();
// for(NeedsSimpleStorage bean : needsStorage) {
// XFuture<Void> future = bean.init(storage);
// futures.add(future);
// }
// 
// return XFuture.allOf(futures.toArray(new XFuture<?>[0]));
// }
public Module createTHEModule(WebAppMeta routerModule, RoutingHolder routingHolder) {
    List<Module> guiceModules = routerModule.getGuiceModules();
    if (guiceModules == null)
        guiceModules = new ArrayList<>();
    int corePoolSize = config.getScheduledThreadPoolSize();
    ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(corePoolSize, new ThreadFactory() {

        @Override
        public Thread newThread(Runnable r) {
            // always name the threads & prevent thread death
            Thread t = new Thread(new SafeRunnable(r), "webpieces-scheduling");
            t.setDaemon(true);
            return t;
        }
    });
    guiceModules.add(new WebpiecesToAppBindingModule(routingHolder, beanMeta, platformInjector, objectTranslator, scheduler, metrics));
    Module module = Modules.combine(guiceModules);
    List<Plugin> plugins = routerModule.getPlugins();
    if (plugins != null) {
        for (Plugin plugin : plugins) {
            List<Module> modules = new ArrayList<>();
            modules.addAll(plugin.getGuiceModules());
            modules.add(module);
            module = Modules.combine(modules);
        }
    }
    if (config.getWebappOverrides() != null)
        module = Modules.override(module).with(config.getWebappOverrides());
    return module;
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SafeRunnable(org.webpieces.util.threading.SafeRunnable) ArrayList(java.util.ArrayList) SafeRunnable(org.webpieces.util.threading.SafeRunnable) Module(com.google.inject.Module) Plugin(org.webpieces.router.api.plugins.Plugin)

Example 4 with Plugin

use of org.webpieces.router.api.plugins.Plugin 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

Plugin (org.webpieces.router.api.plugins.Plugin)4 ArrayList (java.util.ArrayList)2 Module (com.google.inject.Module)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 DocumentationConfig (org.webpieces.plugin.documentation.DocumentationConfig)1 WebpiecesDocumentationPlugin (org.webpieces.plugin.documentation.WebpiecesDocumentationPlugin)1 H2DbConfig (org.webpieces.plugin.hsqldb.H2DbConfig)1 H2DbPlugin (org.webpieces.plugin.hsqldb.H2DbPlugin)1 JacksonConfig (org.webpieces.plugin.json.JacksonConfig)1 JacksonPlugin (org.webpieces.plugin.json.JacksonPlugin)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 BRouter (org.webpieces.router.impl.routers.BRouter)1 SafeRunnable (org.webpieces.util.threading.SafeRunnable)1