/** * Instrument request using {@link InstrumentedHandler}. * * @param method Method to filter for. Default is: <code>GET</code>. * @param pattern A pattern to filter for. Default is: <code>*</code> (all the requests). * @return This metrics module. */ public Metrics request(final String method, final String pattern) { routes.add(r -> r.use(method, pattern, new InstrumentedHandler())); return this; }
/** * Append a simple ping handler that results in a <code>200</code> responses with a * <code>pong</code> body. See {@link PingHandler} * * @return This metrics module. */ public Metrics ping() { bindings.add((binder, routes, conf) -> { routes.use("GET", this.pattern + "/ping", new PingHandler()); }); return this; }
/** * Append a handler that prints thread states (a.k.a thread dump). See {@link ThreadDumpHandler}. * * @return This metrics module. */ public Metrics threadDump() { bindings.add((binder, routes, conf) -> { routes.use("GET", this.pattern + "/thread-dump", new ThreadDumpHandler()); }); return this; }
@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"); }
.newMapBinder(binder, String.class, Authorizer.class); routes.use("*", authCallbackPath(conf), (req, rsp, chain) -> req .require(AuthCallback.class).handle(req, rsp, chain)) .excludes("/favicon.ico") .name("auth(Callback)"); routes.use("*", logoutUrl.orElse(conf.getString("auth.logout.url")), new AuthLogout(redirecTo.orElse(conf.getString("auth.logout.redirectTo")))) .name("auth(Logout)"); routes.use("*", pattern, head).name("auth(" + head.getName() + ")").excludes("/favicon.ico"); }); .collect(Collectors.joining(Pac4jConstants.ELEMENT_SEPRATOR)); routes.use("*", pattern, new AuthorizerFilter(names)) .name("auth(" + names + ")");
.map(loadClass) .filter(C) .forEach(klass -> routes.use(((Jooby) newObject(klass))));
.use(it.method(), it.pattern(), new OpenHandle(jdbi, it)) .name("transactionPerRequest"); });
.map(it -> conf.getString("assets." + it + ".prefix")) .orElse(cpath); routes.use("*", "*", new AssetVars(compiler, prefix, !dev)).name("/assets/vars"); boolean watch = conf.hasPath("assets.watch") ? conf.getBoolean("assets.watch") : dev; LiveCompiler liveCompiler = new LiveCompiler(compiler, workdir); routes.use("*", "*", liveCompiler) .name("/assets/compiler");
boolean renewSession = conf.getBoolean("pac4j.callback.renewSession"); List<String> excludePaths = conf.getStringList("pac4j.excludePaths"); router.use(conf.getString("pac4j.callback.method"), callbackPath, new Pac4jCallback(pac4j, callbackRedirectTo, multiProfile, renewSession)) .excludes(excludePaths) excludes.remove(pattern); excludes.remove("/**"); router.use(conf.getString("pac4j.securityFilter.method"), pattern, filter) .excludes(excludes) .name("pac4j(" + filter + ")"); pac4j.setLogoutLogic(logoutLogic); router.use(conf.getString("pac4j.logout.method"), conf.getString("pac4j.logout.path"), new Pac4jLogout(pac4j, conf.getString("pac4j.logout.redirectTo"),
router.assets("/livereload.js", livereloadjs); router.use("*", (req, rsp) -> req.set("liveReload", template(req))) .name("livereload");
/** * Append a simple ping handler that results in a <code>200</code> responses with a * <code>pong</code> body. See {@link PingHandler} * * @return This metrics module. */ public Metrics ping() { bindings.add((binder, routes, conf) -> { routes.use("GET", this.pattern + "/ping", new PingHandler()); }); return this; }
/** * Append a handler that prints thread states (a.k.a thread dump). See {@link ThreadDumpHandler}. * * @return This metrics module. */ public Metrics threadDump() { bindings.add((binder, routes, conf) -> { routes.use("GET", this.pattern + "/thread-dump", new ThreadDumpHandler()); }); return this; }
/** * Instrument request using {@link InstrumentedHandler}. * * @param method Method to filter for. Default is: <code>GET</code>. * @param pattern A pattern to filter for. Default is: <code>*</code> (all the requests). * @return This metrics module. */ public Metrics request(final String method, final String pattern) { routes.add(r -> r.use(method, pattern, new InstrumentedHandler())); return this; }
@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"); }
.map(loadClass) .filter(C) .forEach(klass -> routes.use(((Jooby) newObject(klass))));
.newMapBinder(binder, String.class, Authorizer.class); routes.use("*", authCallbackPath(conf), (req, rsp, chain) -> req .require(AuthCallback.class).handle(req, rsp, chain)) .excludes("/favicon.ico") .name("auth(Callback)"); routes.use("*", logoutUrl.orElse(conf.getString("auth.logout.url")), new AuthLogout(redirecTo.orElse(conf.getString("auth.logout.redirectTo")))) .name("auth(Logout)"); routes.use("*", pattern, head).name("auth(" + head.getName() + ")").excludes("/favicon.ico"); }); .collect(Collectors.joining(Pac4jConstants.ELEMENT_SEPRATOR)); routes.use("*", pattern, new AuthorizerFilter(names)) .name("auth(" + names + ")");
.map(it -> conf.getString("assets." + it + ".prefix")) .orElse(cpath); routes.use("*", "*", new AssetVars(compiler, prefix, !dev)).name("/assets/vars"); boolean watch = conf.hasPath("assets.watch") ? conf.getBoolean("assets.watch") : dev; LiveCompiler liveCompiler = new LiveCompiler(compiler, workdir); routes.use("*", "*", liveCompiler) .name("/assets/compiler");