@Override public Route route() { return req.route(); }
private static Object[] vars(final Request req) { Map<Object, String> vars = req.route().vars(); return vars.values().toArray(new Object[vars.size()]); }
/** * @return HTTP method. */ @Nonnull default String method() { return route().method(); }
/** * Escape the path using {@link UrlEscapers#urlFragmentEscaper()}. * * Given: * * <pre>{@code * http://domain.com/404<h1>X</h1> {@literal ->} /404%3Ch1%3EX%3C/h1%3E * }</pre> * * @param escape True if we want to escape this path. * @return The request URL pathname. */ @Nonnull default String path(final boolean escape) { String path = route().path(); return escape ? UrlEscapers.urlFragmentEscaper().escape(path) : path; }
protected void handshake(final Request req, final Runnable handler) throws Exception { this.injector = req.require(Injector.class); this.renderers = ImmutableList.copyOf(injector.getInstance(Renderer.KEY)); this.produces = req.route().produces(); this.locals = req.attributes(); this.lastEventId = req.header("Last-Event-ID"); this.locale = req.locale(); handshake(handler); }
@Override public void handle(Request req, Response rsp) { TimedSupport timed = TimedSupport.create(req.route()); if (timed != null) { MeterRegistry registry = req.require(MeterRegistry.class); TimedSupport.Sample sample = timed.start(registry); rsp.complete((request, response, cause) -> sample.stop()); } } }
@Override public void handle(final Request req, final Response rsp, final Err ex) throws Throwable { log.error("execution of: {}{} resulted in exception\nRoute:\n{}\n\nStacktrace:", req.method(), req.path(), req.route().print(6), ex); Config conf = req.require(Config.class); boolean stackstrace = Try.apply(() -> conf.getBoolean("err.stacktrace")) .orElse(req.require(Env.class).name().equals("dev")); rsp.send( Results .when(MediaType.html, () -> Results.html(VIEW).put("err", ex.toMap(stackstrace))) .when(MediaType.all, () -> ex.toMap(stackstrace))); }
@Override public Route route() { return req.route(); }
/** * @return HTTP method. */ @Nonnull default String method() { return route().method(); }
private static Object[] vars(final Request req) { Map<Object, String> vars = req.route().vars(); return vars.values().toArray(new Object[vars.size()]); }
/** * Escape the path using {@link UrlEscapers#urlFragmentEscaper()}. * * Given: * * <pre>{@code * http://domain.com/404<h1>X</h1> {@literal ->} /404%3Ch1%3EX%3C/h1%3E * }</pre> * * @param escape True if we want to escape this path. * @return The request URL pathname. */ @Nonnull default String path(final boolean escape) { String path = route().path(); return escape ? UrlEscapers.urlFragmentEscaper().escape(path) : path; }
protected void handshake(final Request req, final Runnable handler) throws Exception { this.injector = req.require(Injector.class); this.renderers = ImmutableList.copyOf(injector.getInstance(Renderer.KEY)); this.produces = req.route().produces(); this.locals = req.attributes(); this.lastEventId = req.header("Last-Event-ID"); this.locale = req.locale(); handshake(handler); }
@Override public void handle(final Request req, final Response rsp, final Err ex) throws Throwable { log.error("execution of: {}{} resulted in exception\nRoute:\n{}\n\nStacktrace:", req.method(), req.path(), req.route().print(6), ex); Config conf = req.require(Config.class); boolean stackstrace = Try.apply(() -> conf.getBoolean("err.stacktrace")) .orElse(req.require(Env.class).name().equals("dev")); rsp.send( Results .when(MediaType.html, () -> Results.html(VIEW).put("err", ex.toMap(stackstrace))) .when(MediaType.all, () -> ex.toMap(stackstrace))); }