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

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

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

Request.path介绍

[英]Given:

http://domain.com/some/path.html  
 -> /some/path.html 
http://domain.com/a.html          
 -> /a.html

[中]给定:

http://domain.com/some/path.html  
 -> /some/path.html 
http://domain.com/a.html          
 -> /a.html

代码示例

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

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

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

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

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

@Override
public String path() {
 return req.path();
}

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

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

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

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

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

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

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

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

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

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

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

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

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

sb.append(Q).append(req.method());
sb.append(SP);
sb.append(req.path());
if (queryString) {
 req.queryString().ifPresent(s -> sb.append(QUERY).append(s));

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

相关文章