@Override public String path(final boolean escape) { return req.path(escape); }
@Override public String getPath() { return req.path(); }
@Override public String path() { return req.path(); }
@Override public String getPath() { return req.path(); }
/** * Given: * * <pre> * http://domain.com/some/path.html {@literal ->} /some/path.html * http://domain.com/a.html {@literal ->} /a.html * </pre> * * @return The request URL pathname. */ @Nonnull default String path() { return path(false); }
@Override public void handle(final Request req, final Response rsp) throws Throwable { String CRLF = "\r\n"; StringBuilder buffer = new StringBuilder("TRACE ").append(req.path()) .append(" ").append(req.protocol()); for (Entry<String, Mutant> entry : req.headers().entrySet()) { buffer.append(CRLF).append(entry.getKey()).append(": ") .append(entry.getValue().toList(String.class).stream().collect(Collectors.joining(", "))); } buffer.append(CRLF); rsp.type(MediaType.valueOf("message/http")); rsp.length(buffer.length()); rsp.send(buffer.toString()); }
@Override public void handle(final Request req, final Response rsp) throws Exception { if (!rsp.header(ALLOW).isSet()) { Set<String> allow = new LinkedHashSet<>(); Set<String> methods = new LinkedHashSet<>(Route.METHODS); String path = req.path(); methods.remove(req.method()); for (String method : methods) { routes.stream() .filter(route -> route.matches(method, path, MediaType.all, MediaType.ALL).isPresent()) .forEach(route -> allow.add(route.method())); } rsp.header(ALLOW, Joiner.on(SEP).join(allow)) .length(0) .status(Status.OK); } }
@Override public String getFullRequestURL() { String query = req.queryString().map(it -> "?" + it).orElse(""); return getScheme() + "://" + getServerName() + ":" + getServerPort() + req.contextPath() + req .path() + query; }
public static RouteWithFilter notFound(final String method, final String path) { return new FallbackRoute("404", method, path, MediaType.ALL, (req, rsp, chain) -> { if (!rsp.status().isPresent()) { throw new Err(Status.NOT_FOUND, req.path(true)); } }); }
sb.append(Q).append(req.method()); sb.append(SP); sb.append(req.path()); if (queryString) { req.queryString().ifPresent(s -> sb.append(QUERY).append(s));
@Override public void handle(final Request req, final Response rsp, final Chain chain) throws Throwable { String error = req.param("error").toOptional().orElse(""); String username = req.param("username").toOptional().orElse(""); req.set("username", username); req.set("error", error); if (loginUrl.equals(req.path())) { // default login form rsp.type(MediaType.html).send(String.format(FORM, error, callback, username)); } else { super.handle(req, rsp, chain); } }
@Override public void handle(final Request req, final Response rsp, final Route.Chain chain) throws Throwable { String path = req.path(); for (Route.Definition router : routes) { // ignore glob route if (!router.glob()) { Optional<Route> ifRoute = router .matches(Route.GET, path, MediaType.all, MediaType.ALL); if (ifRoute.isPresent()) { // route found rsp.length(0); ((RouteImpl) ifRoute.get()).handle(req, rsp, chain); return; } } } // not handled, just call next chain.next(req, rsp); } }
private static Route[] routes(final Set<Route.Definition> routeDefs, final String method, final String path, final MediaType type, final List<MediaType> accept) { List<Route> routes = findRoutes(routeDefs, method, path, type, accept); routes.add(RouteImpl.fallback((req, rsp, chain) -> { if (!rsp.status().isPresent()) { // 406 or 415 Err ex = handle406or415(routeDefs, method, path, type, accept); if (ex != null) { throw ex; } // 405 ex = handle405(routeDefs, method, path, type, accept); if (ex != null) { throw ex; } // favicon.ico if (path.equals("/favicon.ico")) { // default /favicon.ico handler: rsp.status(Status.NOT_FOUND).end(); } else { throw new Err(Status.NOT_FOUND, req.path(true)); } } }, method, path, "err", accept)); return routes.toArray(new Route[routes.size()]); }
@Override public void handle(final Request req, final Response rsp) throws Throwable { String path = req.path(); URL resource = resolve(req, path); if (resource != null) { String localpath = resource.getPath(); int jarEntry = localpath.indexOf("!/"); if (jarEntry > 0) { localpath = localpath.substring(jarEntry + 2); } URLAsset asset = new URLAsset(resource, path, MediaType.byPath(localpath).orElse(MediaType.octetstream)); if (asset.exists()) { // cdn? if (cdn != null) { String absUrl = cdn + path; rsp.redirect(absUrl); rsp.end(); } else { doHandle(req, rsp, asset); } } } else if (statusCode > 0) { throw new Err(statusCode); } }
req.method(), req.path(), req.route().print(6), err); rsp.type(MediaType.html).send(writer.toString());
@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 default void handle(final Request req, final Response rsp, final Chain chain) throws Throwable { Sse sse = req.require(Sse.class); String path = req.path(); rsp.send(new Deferred(deferred -> { try { sse.handshake(req, () -> { Try.run(() -> handle(req, sse)) .onSuccess(() -> deferred.resolve(null)) .onFailure(ex -> { deferred.reject(ex); Logger log = LoggerFactory.getLogger(Sse.class); log.error("execution of {} resulted in error", path, ex); }); }); } catch (Exception ex) { deferred.reject(ex); } })); }
Swagger swagger = new SwaggerBuilder(options.tagger) .build(base, provider.apply(req.require(M))); boolean json = req.path().endsWith(".json"); if (configurer != null) { configurer.accept(swagger); boolean json = req.path().endsWith(".json"); if (json) { return Results.json(Json.mapper().writer().writeValueAsBytes(swagger));
final String requestedUrl = req.path() + queryString; log.debug("requestedUrl: {}", requestedUrl); ctx.setSessionAttribute(Pac4jConstants.REQUESTED_URL, requestedUrl);
public static RouteWithFilter notFound(final String method, final String path) { return new FallbackRoute("404", method, path, MediaType.ALL, (req, rsp, chain) -> { if (!rsp.status().isPresent()) { throw new Err(Status.NOT_FOUND, req.path(true)); } }); }