org.jooby.Request.path()方法的使用及代码示例

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

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

Request.path介绍

[英]Given:

  1. http://domain.com/some/path.html
  2. -> /some/path.html
  3. http://domain.com/a.html
  4. -> /a.html

[中]给定:

  1. http://domain.com/some/path.html
  2. -> /some/path.html
  3. http://domain.com/a.html
  4. -> /a.html

代码示例

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

  1. @Override
  2. public String path(final boolean escape) {
  3. return req.path(escape);
  4. }

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

  1. @Override
  2. public String getPath() {
  3. return req.path();
  4. }

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

  1. @Override
  2. public String path() {
  3. return req.path();
  4. }

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

  1. @Override public String getPath() {
  2. return req.path();
  3. }

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

  1. /**
  2. * Given:
  3. *
  4. * <pre>
  5. * http://domain.com/some/path.html {@literal ->} /some/path.html
  6. * http://domain.com/a.html {@literal ->} /a.html
  7. * </pre>
  8. *
  9. * @return The request URL pathname.
  10. */
  11. @Nonnull
  12. default String path() {
  13. return path(false);
  14. }

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

  1. @Override
  2. public void handle(final Request req, final Response rsp) throws Throwable {
  3. String CRLF = "\r\n";
  4. StringBuilder buffer = new StringBuilder("TRACE ").append(req.path())
  5. .append(" ").append(req.protocol());
  6. for (Entry<String, Mutant> entry : req.headers().entrySet()) {
  7. buffer.append(CRLF).append(entry.getKey()).append(": ")
  8. .append(entry.getValue().toList(String.class).stream().collect(Collectors.joining(", ")));
  9. }
  10. buffer.append(CRLF);
  11. rsp.type(MediaType.valueOf("message/http"));
  12. rsp.length(buffer.length());
  13. rsp.send(buffer.toString());
  14. }

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

  1. @Override
  2. public void handle(final Request req, final Response rsp) throws Exception {
  3. if (!rsp.header(ALLOW).isSet()) {
  4. Set<String> allow = new LinkedHashSet<>();
  5. Set<String> methods = new LinkedHashSet<>(Route.METHODS);
  6. String path = req.path();
  7. methods.remove(req.method());
  8. for (String method : methods) {
  9. routes.stream()
  10. .filter(route -> route.matches(method, path, MediaType.all, MediaType.ALL).isPresent())
  11. .forEach(route -> allow.add(route.method()));
  12. }
  13. rsp.header(ALLOW, Joiner.on(SEP).join(allow))
  14. .length(0)
  15. .status(Status.OK);
  16. }
  17. }

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

  1. @Override
  2. public String getFullRequestURL() {
  3. String query = req.queryString().map(it -> "?" + it).orElse("");
  4. return getScheme() + "://" + getServerName() + ":" + getServerPort() + req.contextPath() + req
  5. .path() + query;
  6. }

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

  1. public static RouteWithFilter notFound(final String method, final String path) {
  2. return new FallbackRoute("404", method, path, MediaType.ALL, (req, rsp, chain) -> {
  3. if (!rsp.status().isPresent()) {
  4. throw new Err(Status.NOT_FOUND, req.path(true));
  5. }
  6. });
  7. }

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

  1. sb.append(Q).append(req.method());
  2. sb.append(SP);
  3. sb.append(req.path());
  4. if (queryString) {
  5. req.queryString().ifPresent(s -> sb.append(QUERY).append(s));

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

  1. @Override
  2. public void handle(final Request req, final Response rsp, final Chain chain) throws Throwable {
  3. String error = req.param("error").toOptional().orElse("");
  4. String username = req.param("username").toOptional().orElse("");
  5. req.set("username", username);
  6. req.set("error", error);
  7. if (loginUrl.equals(req.path())) {
  8. // default login form
  9. rsp.type(MediaType.html).send(String.format(FORM, error, callback, username));
  10. } else {
  11. super.handle(req, rsp, chain);
  12. }
  13. }

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

  1. @Override
  2. public void handle(final Request req, final Response rsp, final Route.Chain chain)
  3. throws Throwable {
  4. String path = req.path();
  5. for (Route.Definition router : routes) {
  6. // ignore glob route
  7. if (!router.glob()) {
  8. Optional<Route> ifRoute = router
  9. .matches(Route.GET, path, MediaType.all, MediaType.ALL);
  10. if (ifRoute.isPresent()) {
  11. // route found
  12. rsp.length(0);
  13. ((RouteImpl) ifRoute.get()).handle(req, rsp, chain);
  14. return;
  15. }
  16. }
  17. }
  18. // not handled, just call next
  19. chain.next(req, rsp);
  20. }
  21. }

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

  1. private static Route[] routes(final Set<Route.Definition> routeDefs, final String method,
  2. final String path, final MediaType type, final List<MediaType> accept) {
  3. List<Route> routes = findRoutes(routeDefs, method, path, type, accept);
  4. routes.add(RouteImpl.fallback((req, rsp, chain) -> {
  5. if (!rsp.status().isPresent()) {
  6. // 406 or 415
  7. Err ex = handle406or415(routeDefs, method, path, type, accept);
  8. if (ex != null) {
  9. throw ex;
  10. }
  11. // 405
  12. ex = handle405(routeDefs, method, path, type, accept);
  13. if (ex != null) {
  14. throw ex;
  15. }
  16. // favicon.ico
  17. if (path.equals("/favicon.ico")) {
  18. // default /favicon.ico handler:
  19. rsp.status(Status.NOT_FOUND).end();
  20. } else {
  21. throw new Err(Status.NOT_FOUND, req.path(true));
  22. }
  23. }
  24. }, method, path, "err", accept));
  25. return routes.toArray(new Route[routes.size()]);
  26. }

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

  1. @Override
  2. public void handle(final Request req, final Response rsp) throws Throwable {
  3. String path = req.path();
  4. URL resource = resolve(req, path);
  5. if (resource != null) {
  6. String localpath = resource.getPath();
  7. int jarEntry = localpath.indexOf("!/");
  8. if (jarEntry > 0) {
  9. localpath = localpath.substring(jarEntry + 2);
  10. }
  11. URLAsset asset = new URLAsset(resource, path,
  12. MediaType.byPath(localpath).orElse(MediaType.octetstream));
  13. if (asset.exists()) {
  14. // cdn?
  15. if (cdn != null) {
  16. String absUrl = cdn + path;
  17. rsp.redirect(absUrl);
  18. rsp.end();
  19. } else {
  20. doHandle(req, rsp, asset);
  21. }
  22. }
  23. } else if (statusCode > 0) {
  24. throw new Err(statusCode);
  25. }
  26. }

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

  1. req.method(), req.path(), req.route().print(6), err);
  2. rsp.type(MediaType.html).send(writer.toString());

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

  1. @Override
  2. public void handle(final Request req, final Response rsp, final Err ex) throws Throwable {
  3. log.error("execution of: {}{} resulted in exception\nRoute:\n{}\n\nStacktrace:",
  4. req.method(), req.path(), req.route().print(6), ex);
  5. Config conf = req.require(Config.class);
  6. boolean stackstrace = Try.apply(() -> conf.getBoolean("err.stacktrace"))
  7. .orElse(req.require(Env.class).name().equals("dev"));
  8. rsp.send(
  9. Results
  10. .when(MediaType.html, () -> Results.html(VIEW).put("err", ex.toMap(stackstrace)))
  11. .when(MediaType.all, () -> ex.toMap(stackstrace)));
  12. }

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

  1. @Override
  2. default void handle(final Request req, final Response rsp, final Chain chain) throws Throwable {
  3. Sse sse = req.require(Sse.class);
  4. String path = req.path();
  5. rsp.send(new Deferred(deferred -> {
  6. try {
  7. sse.handshake(req, () -> {
  8. Try.run(() -> handle(req, sse))
  9. .onSuccess(() -> deferred.resolve(null))
  10. .onFailure(ex -> {
  11. deferred.reject(ex);
  12. Logger log = LoggerFactory.getLogger(Sse.class);
  13. log.error("execution of {} resulted in error", path, ex);
  14. });
  15. });
  16. } catch (Exception ex) {
  17. deferred.reject(ex);
  18. }
  19. }));
  20. }

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

  1. Swagger swagger = new SwaggerBuilder(options.tagger)
  2. .build(base, provider.apply(req.require(M)));
  3. boolean json = req.path().endsWith(".json");
  4. if (configurer != null) {
  5. configurer.accept(swagger);
  6. boolean json = req.path().endsWith(".json");
  7. if (json) {
  8. return Results.json(Json.mapper().writer().writeValueAsBytes(swagger));

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

  1. final String requestedUrl = req.path() + queryString;
  2. log.debug("requestedUrl: {}", requestedUrl);
  3. ctx.setSessionAttribute(Pac4jConstants.REQUESTED_URL, requestedUrl);

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

  1. public static RouteWithFilter notFound(final String method, final String path) {
  2. return new FallbackRoute("404", method, path, MediaType.ALL, (req, rsp, chain) -> {
  3. if (!rsp.status().isPresent()) {
  4. throw new Err(Status.NOT_FOUND, req.path(true));
  5. }
  6. });
  7. }

相关文章