@Override public void configure(final Env env, final Config conf, final Binder binder) { String baseurl = this.baseurl.orElseGet(() -> { if (conf.hasPath(SITEMAP_BASEURL)) { return conf.getString(SITEMAP_BASEURL); } else { Config $ = conf.getConfig("application"); return "http://" + $.getString("host") + ":" + $.getString("port") + $.getString("path"); } }); wpp.accept(binder); env.router().get(path, new SitemapHandler(path, NOT_ME.and(filter), gen(baseurl))); }
@Override public void configure(final Env env, final Config conf, final Binder binder) { boolean whoops = conf.hasPath("whoops.enabled") ? conf.getBoolean("whoops.enabled") : "dev".equals(env.name()); if (whoops) { ClassLoader loader = env.router().getClass().getClassLoader(); Handler handler = prettyPage(loader, SourceLocator.local(), maxFrameSize, log); env.router().err(tryPage(handler, log)); } }
@Override public void configure(final Env env, final Config conf, final Binder binder) { env.router() .map(reactor(flux, mono)); }
@Override public void configure(final Env env, final Config conf, final Binder binder) throws Exception { boolean useFile = Stream.of(swaggerOptions, ramlOptions) .filter(Objects::nonNull) .filter(it -> it.file != null) .findFirst() .isPresent(); Throwing.Function<Set<Route.Definition>, List<RouteMethod>> provider = null; if (!useFile) { Path dir = Optional.ofNullable(basedir).orElse(Paths.get(conf.getString("user.dir"))); ApiParser parser = new ApiParser(dir, filter); customizer.forEach(parser::modify); provider = routes -> parser .parseFully(conf.getString("application.class"), new ArrayList<>(routes)); if (!env.name().equals("dev")) { provider = provider.memoized(); } binder.bind(ApiParser.class).toInstance(parser); } String contextPath = conf.getString("application.path"); if (swaggerOptions != null) { swagger(contextPath, env.router(), swaggerOptions, conf, swagger, provider); } if (ramlOptions != null) { raml(contextPath, env.router(), ramlOptions, raml, provider); } }
@Override public void configure(final Env env, final Config conf, final Binder binder) { // empty metric & checks MapBinder.newMapBinder(binder, String.class, Metric.class); MapBinder.newMapBinder(binder, String.class, HealthCheck.class); Router routes = env.router(); MetricHandler mhandler = new MetricHandler(); routes.use("GET", this.pattern + "/metrics", mhandler); routes.use("GET", this.pattern + "/metrics/:type", mhandler); routes.use("GET", this.pattern + "/healthcheck", new HealthCheckHandler()); Multibinder<Reporter> reporters = Multibinder.newSetBinder(binder, Reporter.class); binder.bind(MetricRegistry.class).toInstance(metricRegistry); this.reporters.forEach(it -> reporters.addBinding().toInstance(it.apply(metricRegistry, conf))); binder.bind(MetricRegistryInitializer.class).asEagerSingleton(); env.onStop(app -> app.require(MetricRegistryInitializer.class).close()); binder.bind(HealthCheckRegistry.class).toInstance(healthCheckRegistry); binder.bind(HealthCheckRegistryInitializer.class).asEagerSingleton(); bindings.forEach(it -> it.bind(binder, routes, conf)); this.routes.forEach(it -> it.accept(routes)); }
@Override public void configure(final Env env, final Config conf, final Binder binder) { Config $cookie = conf.getConfig("flash.cookie"); String cpath = $cookie.getString("path"); boolean chttp = $cookie.getBoolean("httpOnly"); boolean csecure = $cookie.getBoolean("secure"); Cookie.Definition cookie = this.cookie .orElseGet(() -> new Cookie.Definition($cookie.getString("name"))); // uses user provided or fallback to defaults cookie.path(cookie.path().orElse(cpath)) .httpOnly(cookie.httpOnly().orElse(chttp)) .secure(cookie.secure().orElse(csecure)); env.router() .use(method, path, new FlashScopeHandler(cookie, decoder, encoder)) .name("flash-scope"); }
@Override public void configure(final Env env, final Config conf, final Binder binder) { // dump rx.* as system properties conf.getConfig("rx") .withoutPath("schedulers").entrySet() .forEach( e -> System.setProperty("rx." + e.getKey(), e.getValue().unwrapped().toString())); Map<String, Executor> executors = new HashMap<>(); super.configure(env, conf, binder, executors::put); env.router() .map(rx(observable, single, completable)); /** * Side effects of global/evil static state. Hack to turn off some of this errors. */ trySchedulerHook(executors); // shutdown schedulers: silent shutdown in dev mode between app reloads env.onStop(() -> { try { Schedulers.shutdown(); } catch (Throwable ex) { log.debug("Schedulers.shutdown() resulted in error", ex); } }); }
}); env.router() .use(it.method(), it.pattern(), new OpenHandle(jdbi, it)) .name("transactionPerRequest");
.whitelistPackages(spec.toArray(new String[spec.size()])); Router routes = env.router();
.setDefault().toInstance(new DefaultClientFinder()); Router routes = env.router();
env.router().get(checkConfig.getString("path"), () -> response);
env.router() .map(mapper());
Router router = env.router();
AssetCompiler compiler = new AssetCompiler(assetClassLoader, conf); Router routes = env.router(); List<String> dist = dev ? ImmutableList.of("dev") : ImmutableList.of(envname, "dist"); String prefix = dist.stream()
: "dev".equals(env.name()); if (enabled) { Router router = env.router();
static void install(final Env env, final Config conf) { String path = conf.getString("crash.httpshell.path"); Router router = env.router(); router.get(path + "/{cmd:.*}", router.promise("direct", (req, deferred) -> { MediaType type = req.accepts(MediaType.json) .map(it -> MediaType.json) .orElse(MediaType.html); PluginContext ctx = req.require(PluginContext.class); ShellFactory shellFactory = ctx.getPlugin(ShellFactory.class); Shell shell = shellFactory.create(null); String cmd = req.param("cmd").value().replaceAll("/", " "); ShellProcess process = shell.createProcess(cmd); ShellProcessContext spc = new SimpleProcessContext( result -> deferred.resolve(result.type(type))); process.execute(spc); })); }
static void install(final Env env, final Config conf) { Router routes = env.router(); String path = conf.getString("crash.webshell.path"); String title = conf.getString("application.name") + " shell";
}); env.router() .map(new CassandraMapper());
@Override public void configure(final Env env, final Config conf, final Binder binder) { boolean whoops = conf.hasPath("whoops.enabled") ? conf.getBoolean("whoops.enabled") : "dev".equals(env.name()); if (whoops) { ClassLoader loader = env.router().getClass().getClassLoader(); Handler handler = prettyPage(loader, SourceLocator.local(), maxFrameSize, log); env.router().err(tryPage(handler, log)); } }
@Override public void configure(final Env env, final Config conf, final Binder binder) { env.router() .map(reactor(flux, mono)); }