org.jooby.Router.use()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(126)

本文整理了Java中org.jooby.Router.use方法的一些代码示例,展示了Router.use的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Router.use方法的具体详情如下:
包路径:org.jooby.Router
类名称:Router
方法名:use

Router.use介绍

[英]Append MVC routes from a controller like class:

use(MyRoute.class);

Where MyRoute.java is:

@Path("/") 
public class MyRoute { 
 @GET 
public String hello() { 
return "Hello Jooby"; 
} 
}

Programming model is quite similar to JAX-RS/Jersey with some minor differences and/or simplifications.

To learn more about Mvc Routes, please check org.jooby.mvc.Path, org.jooby.mvc.Produces org.jooby.mvc.Consumes.
[中]从类似控制器的类附加MVC路由:

use(MyRoute.class);

我的路线在哪里。java是:

@Path("/") 
public class MyRoute { 
 @GET 
public String hello() { 
return "Hello Jooby"; 
} 
}

编程模型与JAX-RS/Jersey非常相似,只是有一些细微的差异和/或简化。
要了解更多关于Mvc路线的信息,请查看org。乔比。mvc。路径,组织。乔比。mvc。生产组织。乔比。mvc。消耗。

代码示例

代码示例来源:origin: jooby-project/jooby

/**
 * 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;
}

代码示例来源:origin: jooby-project/jooby

/**
 * 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;
}

代码示例来源:origin: jooby-project/jooby

/**
 * 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;
}

代码示例来源:origin: jooby-project/jooby

@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));
}

代码示例来源:origin: jooby-project/jooby

@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");
}

代码示例来源:origin: jooby-project/jooby

.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 + ")");

代码示例来源:origin: jooby-project/jooby

.map(loadClass)
.filter(C)
.forEach(klass -> routes.use(((Jooby) newObject(klass))));

代码示例来源:origin: jooby-project/jooby

.use(it.method(), it.pattern(), new OpenHandle(jdbi, it))
   .name("transactionPerRequest");
});

代码示例来源:origin: jooby-project/jooby

.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");

代码示例来源:origin: jooby-project/jooby

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"),

代码示例来源:origin: jooby-project/jooby

router.assets("/livereload.js", livereloadjs);
router.use("*", (req, rsp) -> req.set("liveReload", template(req)))
  .name("livereload");

代码示例来源:origin: org.jooby/jooby-metrics

/**
 * 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;
}

代码示例来源:origin: org.jooby/jooby-metrics

/**
 * 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;
}

代码示例来源:origin: org.jooby/jooby-metrics

/**
 * 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;
}

代码示例来源:origin: org.jooby/jooby-metrics

@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));
}

代码示例来源:origin: org.jooby/jooby

@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");
}

代码示例来源:origin: org.jooby/jooby-scanner

.map(loadClass)
.filter(C)
.forEach(klass -> routes.use(((Jooby) newObject(klass))));

代码示例来源:origin: org.jooby/jooby-pac4j

.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 + ")");

代码示例来源:origin: org.jooby/jooby-assets

.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");

相关文章

微信公众号

最新文章

更多