/** * 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); }
/** * 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; }
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);
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); })); }
.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));
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
@Override public void configure(final Env env, final Config conf, final Binder binder) { env.router() .map(reactor(flux, mono)); }
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); }
/** * 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); } }); }
/** * 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); }
return assets(path, "/");
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"),
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));
@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); } }); }
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()); }
/** * 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); } }); }
/** * 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); }
return assets(path, "/");
/** * 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; }