org.jooby.Router类的使用及代码示例

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

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

Router介绍

[英]Route DSL. Constructs and creates several flavors of jooby routes.
[中]路由DSL。构建并创建多种风格的jooby路线。

代码示例

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

/**
 * Append a route that matches the HTTP GET method:
 *
 * <pre>
 *   get((req, rsp) {@literal ->} {
 *     rsp.send(something);
 *   });
 * </pre>
 *
 * @param handler A handler to execute.
 * @return A new route definition.
 */
@Nonnull
default Route.Definition get(Route.Handler handler) {
 return get("/", handler);
}

代码示例来源: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

String path = conf.getString("crash.webshell.path");
String title = conf.getString("application.name") + " shell";
routes.assets(path + "/css/**", "META-INF/resources/css/{0}");
routes.assets(path + "/js/**", "META-INF/resources/js/{0}");
String rootpath = Route.normalize(conf.getString("application.path") + path);
routes.get(path, req -> Results.ok("<!DOCTYPE HTML>\n" +
  "<html>\n" +
  "<head>\n" +
  "</html>").type(MediaType.html));
routes.ws(path, new WebShellHandler()).consumes(MediaType.json).produces(MediaType.json);

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

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

代码示例来源: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");
compiler.patterns().forEach(pattern -> routes.get(pattern, handler));

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

router.get(api, req -> {
  Config conf = req.require(Config.class);
  Map<String, Object> hash = conf.getConfig("raml").root().unwrapped();
} else {
 byte[] ramlString = readRaml(options.file);
 router.get(api, req -> {
  return Results.ok(ramlString).type("text/yml");
 });
 router.assets(options.path + "/static/**", RAML_STATIC + "{0}");
       + "\"></raml-console-loader>");
 router.get(options.path, req -> {
  String page = Optional.ofNullable(req.param("theme").value(options.theme))
    .map(theme -> index

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

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

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

@Override
public void configure(final Env env, final Config conf, final Binder binder) {
 env.router()
  .map(reactor(flux, mono));
}

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

public ServletServletRequest(final HttpServletRequest req, final String tmpdir,
  final boolean multipart) throws IOException {
 this.req = requireNonNull(req, "HTTP req is required.");
 this.tmpdir = requireNonNull(tmpdir, "A tmpdir is required.");
 this.multipart = multipart;
 String pathInfo = req.getPathInfo();
 if (pathInfo == null) {
  pathInfo = "/";
 }
 this.path = req.getContextPath() + Router.decode(pathInfo);
}

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

/**
 * Setup a custom error handler.The error handler will be executed if the current exception is an
 * instance of given type type.
 *
 * All headers are reset while generating the error response.
 *
 * @param type Exception type. The error handler will be executed if the current exception is an
 *        instance of this type.
 * @param handler A route error handler.
 * @return This router.
 */
@Nonnull
default Router err(final Class<? extends Throwable> type, final Err.Handler handler) {
 return err((req, rsp, x) -> {
  if (type.isInstance(x) || type.isInstance(x.getCause())) {
   handler.handle(req, rsp, x);
  }
 });
}

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

/**
 * Append a new WebSocket handler under the given path.
 *
 * <pre>
 *   ws(MyHandler.class);
 * </pre>
 *
 * @param handler A message callback.
 * @param <T> Message type.
 * @return A new WebSocket definition.
 */
@Nonnull
default <T> WebSocket.Definition ws(final Class<? extends WebSocket.OnMessage<T>> handler) {
 return ws("", handler);
}

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

return assets(path, "/");

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

router.get("/login",
   new Pac4jLoginForm(Route.normalize(contextPath + callbackPath)))
   .name("pac4j(LoginForm)");
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.get(options.path + "/swagger.json", options.path + "/swagger.yml", req -> {
 Map<String, Object> hash = conf.getConfig("swagger").root().unwrapped();
 Swagger base = Json.mapper().convertValue(hash, Swagger.class);
 configurer.accept(swagger);
router.get(options.path + "/swagger.json", options.path + "/swagger.yml", req -> {
 boolean json = req.path().endsWith(".json");
 if (json) {
router.assets(staticPath + "**", SWAGGER_STATIC + "{0}");
router.assets(staticPath + "**", SWAGGER_THEME + "{0}");
    options.tryIt ? "</head>" : "<style> .try-out {display: none;}</style></head>");
router.get(options.path, req -> {
 String page = Optional.ofNullable(req.param("theme").value(options.theme))
   .map(theme -> index.replace("<style>", "<link rel=\"stylesheet\" "
  .format(REDOC, conf.getString("swagger.info.title"), swaggerJsonPath, redocjsfull);
router.assets(options.redoc + redocjs, "/redoc/" + redocjs);
router.get(options.redoc, () -> Results.ok(redoc).type(MediaType.html));

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

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

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

public UndertowRequest(final HttpServerExchange exchange, final Config conf) throws IOException {
 this.exchange = exchange;
 this.blocking = Suppliers.memoize(() -> this.exchange.startBlocking());
 this.conf = conf;
 this.path = Router.decode(exchange.getRequestPath());
}

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

/**
 * Setup a route error handler. The error handler will be executed if current status code matches
 * the one provided.
 *
 * All headers are reset while generating the error response.
 *
 * @param statusCode The status code to match.
 * @param handler A route error handler.
 * @return This router.
 */
@Nonnull
default Router err(final int statusCode, final Err.Handler handler) {
 return err((req, rsp, x) -> {
  if (statusCode == x.statusCode()) {
   handler.handle(req, rsp, x);
  }
 });
}

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

/**
 * Append a new WebSocket handler under the given path.
 *
 * <pre>
 *   ws("/ws", (socket) {@literal ->} {
 *     // connected
 *     socket.onMessage(message {@literal ->} {
 *       System.out.println(message);
 *     });
 *     socket.send("Connected"):
 *   });
 * </pre>
 *
 * @param path A path pattern.
 * @param handler A connect callback.
 * @return A new WebSocket definition.
 */
@Nonnull
default WebSocket.Definition ws(final String path, final WebSocket.OnOpen1 handler) {
 return ws(path, (WebSocket.OnOpen) handler);
}

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

return assets(path, "/");

代码示例来源: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;
}

相关文章