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

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

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

Request.param介绍

[英]Get a HTTP request parameter under the given name. A HTTP parameter can be provided in any of these forms:

  • Path parameter, like: /path/:name or /path/{name}
  • Query parameter, like: ?name=jooby
  • Body parameter when Content-Type is application/x-www-form-urlencoded or multipart/form-data
    The order of precedence is: path, query and body. For example a pattern like: GET /path/:name for /path/jooby?name=rocks produces:
  1. assertEquals("jooby", req.param(name).value());
  2. assertEquals("jooby", req.param(name).toList().get(0));
  3. assertEquals("rocks", req.param(name).toList().get(1));

Uploads can be retrieved too when Content-Type is multipart/form-data see Upload for more information.
[中]获取给定名称下的HTTP请求参数。HTTP参数可以以下任何形式提供:
*路径参数,例如:/path/:name/path/{name}
*查询参数,比如:?name=jooby
*Content-Typeapplication/x-www-form-urlencodedmultipart/form-data时的正文参数
优先顺序为:[6$]、[$7$]和[$8$]。例如,/path/jooby?name=rocksGET /path/:name这样的模式会产生:

  1. assertEquals("jooby", req.param(name).value());
  2. assertEquals("jooby", req.param(name).toList().get(0));
  3. assertEquals("rocks", req.param(name).toList().get(1));

Content-Typemultipart/form-data时,也可以检索上载内容。有关更多信息,请参阅上载。

代码示例

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

  1. @Override
  2. public Mutant param(final String name, final String... xss) {
  3. return req.param(name, xss);
  4. }

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

  1. private static final GetValue param() {
  2. return (req, rsp, chain, param) -> {
  3. Mutant mutant = req.param(param.name);
  4. if (mutant.isSet() || param.optional) {
  5. return mutant.to(param.type);
  6. }
  7. try {
  8. return req.params().to(param.type);
  9. } catch (Err ex) {
  10. // force parsing
  11. return mutant.to(param.type);
  12. }
  13. };
  14. }
  15. }

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

  1. @Override
  2. public Mutant param(final String name) {
  3. return req.param(name);
  4. }

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

  1. private static final GetValue param() {
  2. return (req, rsp, chain, param) -> {
  3. Mutant mutant = req.param(param.name);
  4. if (mutant.isSet() || param.optional) {
  5. return mutant.to(param.type);
  6. }
  7. try {
  8. return req.params().to(param.type);
  9. } catch (Err ex) {
  10. // force parsing
  11. return mutant.to(param.type);
  12. }
  13. };
  14. }
  15. }

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

  1. @Override
  2. public void handle(final Request req, final Response rsp) throws Throwable {
  3. String error = req.param("error").value("");
  4. String username = req.param("username").value("");
  5. req.set("username", username);
  6. req.set("error", error);
  7. // default login form
  8. rsp.type(MediaType.html).send(String.format(FORM, error, callback, username));
  9. }

代码示例来源: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) throws Throwable {
  3. if (compilationDone.get()) {
  4. if (req.param("assets.sync").isSet()) {
  5. onChange(StandardWatchEventKinds.ENTRY_MODIFY, basedir);
  6. }
  7. if (errors.size() > 0) {
  8. throw errors.values().iterator().next();
  9. }
  10. } else {
  11. rsp.type(MediaType.html)
  12. .send("<!DOCTYPE html>\n"
  13. + "<html>\n"
  14. + "<head>\n"
  15. + "<meta charset=\"UTF-8\">\n"
  16. + "<meta http-equiv=\"refresh\" content=\"2\">\n"
  17. + "<title>Compiling assets</title>\n"
  18. + "</head>\n"
  19. + "<body>\n"
  20. + "Compiling assets, please wait...\n"
  21. + "</body>\n"
  22. + "</html>");
  23. }
  24. }

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

  1. @Override
  2. public void handle(final Request req, final Response rsp) throws Throwable {
  3. HealthCheckRegistry registry = req.require(HealthCheckRegistry.class);
  4. SortedMap<String, Result> checks = req.param("name").toOptional().map(name -> {
  5. SortedMap<String, Result> set = ImmutableSortedMap.of(name, registry.runHealthCheck(name));
  6. return set;
  7. }).orElseGet(() -> registry.runHealthChecks());
  8. final Status status;
  9. if (checks.isEmpty()) {
  10. status = Status.NOT_IMPLEMENTED;
  11. } else {
  12. status = checks.values().stream()
  13. .filter(it -> !it.isHealthy())
  14. .findFirst()
  15. .map(it -> Status.SERVER_ERROR)
  16. .orElse(Status.OK);
  17. }
  18. rsp.status(status)
  19. .header("Cache-Control", "must-revalidate,no-cache,no-store")
  20. .send(checks);
  21. }

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

  1. @Override
  2. public void handle(final Request req, final Response rsp, final Route.Chain chain)
  3. throws Throwable {
  4. /**
  5. * Get or generate a token
  6. */
  7. Session session = req.session();
  8. String token = session.get(name).toOptional().orElseGet(() -> {
  9. String newToken = generator.apply(req);
  10. session.set(name, newToken);
  11. return newToken;
  12. });
  13. req.set(name, token);
  14. if (requireToken.test(req)) {
  15. String candidate = req.header(name).toOptional()
  16. .orElseGet(() -> req.param(name).toOptional().orElse(null));
  17. if (!token.equals(candidate)) {
  18. throw new Err(Status.FORBIDDEN, "Invalid Csrf token: " + candidate);
  19. }
  20. }
  21. chain.next(req, rsp);
  22. }
  23. }

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

  1. } else {
  2. String type = req.param("type").value("*");
  3. MetricFilter filter = req.param("name").toOptional()
  4. .<MetricFilter> map(name -> (n, m) -> n.startsWith(name))
  5. .orElse(MetricFilter.ALL);
  6. TimeUnit unit = TimeUnit.valueOf(req.param("unit").value("seconds").toUpperCase());
  7. String rateUnitLabel = calculateRateUnit(unit, "ops");
  8. double rateFactor = unit.toSeconds(1);
  9. double durationFactor = 1.0 / unit.toNanos(1);
  10. boolean showSamples = req.param("showSamples").booleanValue(false);

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

  1. static void install(final Env env, final Config conf) {
  2. String path = conf.getString("crash.httpshell.path");
  3. Router router = env.router();
  4. router.get(path + "/{cmd:.*}", router.promise("direct", (req, deferred) -> {
  5. MediaType type = req.accepts(MediaType.json)
  6. .map(it -> MediaType.json)
  7. .orElse(MediaType.html);
  8. PluginContext ctx = req.require(PluginContext.class);
  9. ShellFactory shellFactory = ctx.getPlugin(ShellFactory.class);
  10. Shell shell = shellFactory.create(null);
  11. String cmd = req.param("cmd").value().replaceAll("/", " ");
  12. ShellProcess process = shell.createProcess(cmd);
  13. ShellProcessContext spc = new SimpleProcessContext(
  14. result -> deferred.resolve(result.type(type)));
  15. process.execute(spc);
  16. }));
  17. }

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

  1. String page = Optional.ofNullable(req.param("theme").value(options.theme))
  2. .map(theme -> index
  3. .replace("api-console-light-theme.css", "api-console-" + theme + "-theme.css"))

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

  1. String page = Optional.ofNullable(req.param("theme").value(options.theme))
  2. .map(theme -> index.replace("<style>", "<link rel=\"stylesheet\" "
  3. + "type=\"text/css\" href=\"" + fullStaticPath + "theme-" + theme.toLowerCase()

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

  1. public void handle(final Request req, final Response rsp) throws Throwable {
  2. Clients clients = req.require(Clients.class);
  3. String clientName = req.param(clients.getClientNameParameter()).value(this.clientName);

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

  1. @Override
  2. public Mutant param(final String name) {
  3. return req.param(name);
  4. }

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

  1. @Override
  2. public Mutant param(final String name, final String... xss) {
  3. return req.param(name, xss);
  4. }

代码示例来源:origin: stackoverflow.com

  1. Request request = webb
  2. .post(Constants.URL + Constants.CUSTOMER_SIGNUP);
  3. for (Map.Entry<String, String> entry : params.entrySet()) {
  4. request.param(entry.getKey(), entry.getValue());
  5. }
  6. Response<String> resp = request.readTimeout(30000)
  7. .connectTimeout(30000)
  8. .asString();

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

  1. @Override
  2. public Object handle(final Request req) throws Exception {
  3. Config conf = req.require(Config.class);
  4. String path = conf.getString("application.path");
  5. if (path.endsWith("/")) {
  6. path += pattern.substring(1);
  7. } else {
  8. path += pattern;
  9. }
  10. String uipath = path;
  11. path += req.param("tag").toOptional().map(t -> "/" + t).orElse("");
  12. String html = template.replace("${ui.path}", uipath).replace("${path}", path);
  13. return html;
  14. }

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

  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: org.jooby/jooby

  1. @Override
  2. public void handle(final Request req, final Response rsp, final Route.Chain chain)
  3. throws Throwable {
  4. /**
  5. * Get or generate a token
  6. */
  7. Session session = req.session();
  8. String token = session.get(name).toOptional().orElseGet(() -> {
  9. String newToken = generator.apply(req);
  10. session.set(name, newToken);
  11. return newToken;
  12. });
  13. req.set(name, token);
  14. if (requireToken.test(req)) {
  15. String candidate = req.header(name).toOptional()
  16. .orElseGet(() -> req.param(name).toOptional().orElse(null));
  17. if (!token.equals(candidate)) {
  18. throw new Err(Status.FORBIDDEN, "Invalid Csrf token: " + candidate);
  19. }
  20. }
  21. chain.next(req, rsp);
  22. }
  23. }

相关文章