本文整理了Java中org.jooby.Request.param
方法的一些代码示例,展示了Request.param
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.param
方法的具体详情如下:
包路径:org.jooby.Request
类名称:Request
方法名:param
[英]Get a HTTP request parameter under the given name. A HTTP parameter can be provided in any of these forms:
/path/:name
or /path/{name}
?name=jooby
Content-Type
is application/x-www-form-urlencoded
or multipart/form-data
path
, query
and body
. For example a pattern like: GET /path/:name
for /path/jooby?name=rocks
produces:assertEquals("jooby", req.param(name).value());
assertEquals("jooby", req.param(name).toList().get(0));
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-Type
为application/x-www-form-urlencoded
或multipart/form-data
时的正文参数
优先顺序为:[6$]、[$7$]和[$8$]。例如,/path/jooby?name=rocks
的GET /path/:name
这样的模式会产生:
assertEquals("jooby", req.param(name).value());
assertEquals("jooby", req.param(name).toList().get(0));
assertEquals("rocks", req.param(name).toList().get(1));
当Content-Type
为multipart/form-data
时,也可以检索上载内容。有关更多信息,请参阅上载。
代码示例来源:origin: jooby-project/jooby
@Override
public Mutant param(final String name, final String... xss) {
return req.param(name, xss);
}
代码示例来源:origin: jooby-project/jooby
private static final GetValue param() {
return (req, rsp, chain, param) -> {
Mutant mutant = req.param(param.name);
if (mutant.isSet() || param.optional) {
return mutant.to(param.type);
}
try {
return req.params().to(param.type);
} catch (Err ex) {
// force parsing
return mutant.to(param.type);
}
};
}
}
代码示例来源:origin: jooby-project/jooby
@Override
public Mutant param(final String name) {
return req.param(name);
}
代码示例来源:origin: org.jooby/jooby
private static final GetValue param() {
return (req, rsp, chain, param) -> {
Mutant mutant = req.param(param.name);
if (mutant.isSet() || param.optional) {
return mutant.to(param.type);
}
try {
return req.params().to(param.type);
} catch (Err ex) {
// force parsing
return mutant.to(param.type);
}
};
}
}
代码示例来源:origin: jooby-project/jooby
@Override
public void handle(final Request req, final Response rsp) throws Throwable {
String error = req.param("error").value("");
String username = req.param("username").value("");
req.set("username", username);
req.set("error", error);
// default login form
rsp.type(MediaType.html).send(String.format(FORM, error, callback, username));
}
代码示例来源: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) throws Throwable {
if (compilationDone.get()) {
if (req.param("assets.sync").isSet()) {
onChange(StandardWatchEventKinds.ENTRY_MODIFY, basedir);
}
if (errors.size() > 0) {
throw errors.values().iterator().next();
}
} else {
rsp.type(MediaType.html)
.send("<!DOCTYPE html>\n"
+ "<html>\n"
+ "<head>\n"
+ "<meta charset=\"UTF-8\">\n"
+ "<meta http-equiv=\"refresh\" content=\"2\">\n"
+ "<title>Compiling assets</title>\n"
+ "</head>\n"
+ "<body>\n"
+ "Compiling assets, please wait...\n"
+ "</body>\n"
+ "</html>");
}
}
代码示例来源:origin: jooby-project/jooby
@Override
public void handle(final Request req, final Response rsp) throws Throwable {
HealthCheckRegistry registry = req.require(HealthCheckRegistry.class);
SortedMap<String, Result> checks = req.param("name").toOptional().map(name -> {
SortedMap<String, Result> set = ImmutableSortedMap.of(name, registry.runHealthCheck(name));
return set;
}).orElseGet(() -> registry.runHealthChecks());
final Status status;
if (checks.isEmpty()) {
status = Status.NOT_IMPLEMENTED;
} else {
status = checks.values().stream()
.filter(it -> !it.isHealthy())
.findFirst()
.map(it -> Status.SERVER_ERROR)
.orElse(Status.OK);
}
rsp.status(status)
.header("Cache-Control", "must-revalidate,no-cache,no-store")
.send(checks);
}
代码示例来源:origin: jooby-project/jooby
@Override
public void handle(final Request req, final Response rsp, final Route.Chain chain)
throws Throwable {
/**
* Get or generate a token
*/
Session session = req.session();
String token = session.get(name).toOptional().orElseGet(() -> {
String newToken = generator.apply(req);
session.set(name, newToken);
return newToken;
});
req.set(name, token);
if (requireToken.test(req)) {
String candidate = req.header(name).toOptional()
.orElseGet(() -> req.param(name).toOptional().orElse(null));
if (!token.equals(candidate)) {
throw new Err(Status.FORBIDDEN, "Invalid Csrf token: " + candidate);
}
}
chain.next(req, rsp);
}
}
代码示例来源:origin: jooby-project/jooby
} else {
String type = req.param("type").value("*");
MetricFilter filter = req.param("name").toOptional()
.<MetricFilter> map(name -> (n, m) -> n.startsWith(name))
.orElse(MetricFilter.ALL);
TimeUnit unit = TimeUnit.valueOf(req.param("unit").value("seconds").toUpperCase());
String rateUnitLabel = calculateRateUnit(unit, "ops");
double rateFactor = unit.toSeconds(1);
double durationFactor = 1.0 / unit.toNanos(1);
boolean showSamples = req.param("showSamples").booleanValue(false);
代码示例来源:origin: jooby-project/jooby
static void install(final Env env, final Config conf) {
String path = conf.getString("crash.httpshell.path");
Router router = env.router();
router.get(path + "/{cmd:.*}", router.promise("direct", (req, deferred) -> {
MediaType type = req.accepts(MediaType.json)
.map(it -> MediaType.json)
.orElse(MediaType.html);
PluginContext ctx = req.require(PluginContext.class);
ShellFactory shellFactory = ctx.getPlugin(ShellFactory.class);
Shell shell = shellFactory.create(null);
String cmd = req.param("cmd").value().replaceAll("/", " ");
ShellProcess process = shell.createProcess(cmd);
ShellProcessContext spc = new SimpleProcessContext(
result -> deferred.resolve(result.type(type)));
process.execute(spc);
}));
}
代码示例来源:origin: jooby-project/jooby
String page = Optional.ofNullable(req.param("theme").value(options.theme))
.map(theme -> index
.replace("api-console-light-theme.css", "api-console-" + theme + "-theme.css"))
代码示例来源:origin: jooby-project/jooby
String page = Optional.ofNullable(req.param("theme").value(options.theme))
.map(theme -> index.replace("<style>", "<link rel=\"stylesheet\" "
+ "type=\"text/css\" href=\"" + fullStaticPath + "theme-" + theme.toLowerCase()
代码示例来源:origin: jooby-project/jooby
public void handle(final Request req, final Response rsp) throws Throwable {
Clients clients = req.require(Clients.class);
String clientName = req.param(clients.getClientNameParameter()).value(this.clientName);
代码示例来源:origin: org.jooby/jooby
@Override
public Mutant param(final String name) {
return req.param(name);
}
代码示例来源:origin: org.jooby/jooby
@Override
public Mutant param(final String name, final String... xss) {
return req.param(name, xss);
}
代码示例来源:origin: stackoverflow.com
Request request = webb
.post(Constants.URL + Constants.CUSTOMER_SIGNUP);
for (Map.Entry<String, String> entry : params.entrySet()) {
request.param(entry.getKey(), entry.getValue());
}
Response<String> resp = request.readTimeout(30000)
.connectTimeout(30000)
.asString();
代码示例来源:origin: org.jooby/jooby-swagger
@Override
public Object handle(final Request req) throws Exception {
Config conf = req.require(Config.class);
String path = conf.getString("application.path");
if (path.endsWith("/")) {
path += pattern.substring(1);
} else {
path += pattern;
}
String uipath = path;
path += req.param("tag").toOptional().map(t -> "/" + t).orElse("");
String html = template.replace("${ui.path}", uipath).replace("${path}", path);
return html;
}
代码示例来源:origin: org.jooby/jooby-pac4j
@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: org.jooby/jooby
@Override
public void handle(final Request req, final Response rsp, final Route.Chain chain)
throws Throwable {
/**
* Get or generate a token
*/
Session session = req.session();
String token = session.get(name).toOptional().orElseGet(() -> {
String newToken = generator.apply(req);
session.set(name, newToken);
return newToken;
});
req.set(name, token);
if (requireToken.test(req)) {
String candidate = req.header(name).toOptional()
.orElseGet(() -> req.param(name).toOptional().orElse(null));
if (!token.equals(candidate)) {
throw new Err(Status.FORBIDDEN, "Invalid Csrf token: " + candidate);
}
}
chain.next(req, rsp);
}
}
内容来源于网络,如有侵权,请联系作者删除!