本文整理汇总了Java中io.undertow.server.handlers.form.FormData.FormValue方法的典型用法代码示例。如果您正苦于以下问题:Java FormData.FormValue方法的具体用法?Java FormData.FormValue怎么用?Java FormData.FormValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.server.handlers.form.FormData
的用法示例。
在下文中一共展示了FormData.FormValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getParameter
import io.undertow.server.handlers.form.FormData; //导入方法依赖的package包/类
@Override
public String getParameter(final String name) {
if(queryParameters == null) {
queryParameters = exchange.getQueryParameters();
}
Deque<String> params = queryParameters.get(name);
if (params == null) {
if (exchange.getRequestMethod().equals(Methods.POST)) {
final FormData parsedFormData = parseFormData();
if (parsedFormData != null) {
FormData.FormValue res = parsedFormData.getFirst(name);
if (res == null || res.isFile()) {
return null;
} else {
return res.getValue();
}
}
}
return null;
}
return params.getFirst();
}
示例2: getParameterNames
import io.undertow.server.handlers.form.FormData; //导入方法依赖的package包/类
@Override
public Enumeration<String> getParameterNames() {
if (queryParameters == null) {
queryParameters = exchange.getQueryParameters();
}
final Set<String> parameterNames = new HashSet<>(queryParameters.keySet());
if (exchange.getRequestMethod().equals(Methods.POST)) {
final FormData parsedFormData = parseFormData();
if (parsedFormData != null) {
Iterator<String> it = parsedFormData.iterator();
while (it.hasNext()) {
String name = it.next();
for(FormData.FormValue param : parsedFormData.get(name)) {
if(!param.isFile()) {
parameterNames.add(name);
break;
}
}
}
}
}
return new IteratorEnumeration<>(parameterNames.iterator());
}
示例3: ban
import io.undertow.server.handlers.form.FormData; //导入方法依赖的package包/类
public void ban(HttpServerExchange exchange) {
User user = parseUserFromForm(exchange);
User user_perform = exchange.getAttachment(AuthReader.USER);
if (user != null && user.getRole().lessThan(user_perform.getRole())) {
String time = "86400";
FormData data = exchange.getAttachment(FormDataParser.FORM_DATA);
FormData.FormValue time_form = data.getFirst("time");
if (time_form != null) {
time = time_form.getValue();
}
if (doLog(exchange)) {
App.getDatabase().adminLog("ban " + user.getName(), user_perform.getId());
}
user.ban(Integer.parseInt(time), getBanReason(exchange), getRollbackTime(exchange));
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/text");
exchange.setStatusCode(200);
} else {
exchange.setStatusCode(400);
}
}
示例4: parseForm
import io.undertow.server.handlers.form.FormData; //导入方法依赖的package包/类
private void parseForm(RequestImpl request, HttpServerExchange exchange) {
FormData formData = exchange.getAttachment(FormDataParser.FORM_DATA);
if (formData == null) return;
for (String name : formData) {
FormData.FormValue value = formData.getFirst(name);
if (value.isFile()) {
if (!Strings.isEmpty(value.getFileName())) { // browser passes empty file name if not choose file in form
logger.debug("[request:file] {}={}, size={}", name, value.getFileName(), Files.size(value.getPath()));
request.files.put(name, new MultipartFile(value.getPath(), value.getFileName(), value.getHeaders().getFirst(Headers.CONTENT_TYPE)));
}
} else {
logger.debug("[request:form] {}={}", name, value.getValue());
request.formParams.put(name, value.getValue());
}
}
}
示例5: handleRequest
import io.undertow.server.handlers.form.FormData; //导入方法依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
if (Methods.POST.equals(exchange.getRequestMethod())) {
String newMethod = exchange.getRequestHeaders().getFirst(HEADER);
Optional<HttpString> opt = HttpMethod.find(newMethod);
if (opt.isPresent()) {
exchange.setRequestMethod(opt.get());
} else {
FormData data = exchange
.getAttachment(FormDataParser.FORM_DATA);
if (data != null) {
FormData.FormValue fv = data.getFirst(FORM);
if (fv != null && fv.isFile() == false) {
HttpMethod.find(fv.getValue()).map(
exchange::setRequestMethod);
}
}
}
}
this.next.handleRequest(exchange);
}
示例6: getFileFromForm
import io.undertow.server.handlers.form.FormData; //导入方法依赖的package包/类
/**
* Return the first file received in the request.
*
* @param formData The multipart request.
* @return A file if the request has one, null otherwise.
*/
private File getFileFromForm(FormData formData) {
for (String data: formData) {
for (FormData.FormValue formValue : formData.get(data)) {
if (formValue.isFile()) {
return formValue.getPath().toFile();
}
}
}
return null;
}
示例7: runFormAuth
import io.undertow.server.handlers.form.FormData; //导入方法依赖的package包/类
public AuthenticationMechanismOutcome runFormAuth(final HttpServerExchange exchange, final SecurityContext securityContext) {
final FormDataParser parser = formParserFactory.createParser(exchange);
if (parser == null) {
UndertowLogger.REQUEST_LOGGER.debug("Could not authenticate as no form parser is present");
// TODO - May need a better error signaling mechanism here to prevent repeated attempts.
return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
try {
final FormData data = parser.parseBlocking();
final FormData.FormValue jUsername = data.getFirst("j_username");
final FormData.FormValue jPassword = data.getFirst("j_password");
if (jUsername == null || jPassword == null) {
UndertowLogger.REQUEST_LOGGER.debug("Could not authenticate as username or password was not present in the posted result");
return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
final String userName = jUsername.getValue();
final String password = jPassword.getValue();
AuthenticationMechanismOutcome outcome = null;
PasswordCredential credential = new PasswordCredential(password.toCharArray());
try {
IdentityManager identityManager = securityContext.getIdentityManager();
Account account = identityManager.verify(userName, credential);
if (account != null) {
securityContext.authenticationComplete(account, name, true);
outcome = AuthenticationMechanismOutcome.AUTHENTICATED;
} else {
securityContext.authenticationFailed(MESSAGES.authenticationFailed(userName), name);
}
} finally {
if (outcome == AuthenticationMechanismOutcome.AUTHENTICATED) {
handleRedirectBack(exchange);
exchange.endExchange();
}
return outcome != null ? outcome : AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例8: getParameterValues
import io.undertow.server.handlers.form.FormData; //导入方法依赖的package包/类
@Override
public String[] getParameterValues(final String name) {
if (queryParameters == null) {
queryParameters = exchange.getQueryParameters();
}
final List<String> ret = new ArrayList<>();
Deque<String> params = queryParameters.get(name);
if (params != null) {
for (String param : params) {
ret.add(param);
}
}
if (exchange.getRequestMethod().equals(Methods.POST)) {
final FormData parsedFormData = parseFormData();
if (parsedFormData != null) {
Deque<FormData.FormValue> res = parsedFormData.get(name);
if (res != null) {
for (FormData.FormValue value : res) {
if(!value.isFile()) {
ret.add(value.getValue());
}
}
}
}
}
if (ret.isEmpty()) {
return null;
}
return ret.toArray(new String[ret.size()]);
}
示例9: getBanReason
import io.undertow.server.handlers.form.FormData; //导入方法依赖的package包/类
private String getBanReason(HttpServerExchange exchange) {
FormData data = exchange.getAttachment(FormDataParser.FORM_DATA);
FormData.FormValue reason = data.getFirst("reason");
String reason_str = "";
if (reason != null) {
reason_str = reason.getValue();
}
return reason_str;
}
示例10: getRollbackTime
import io.undertow.server.handlers.form.FormData; //导入方法依赖的package包/类
private int getRollbackTime(HttpServerExchange exchange) {
FormData data = exchange.getAttachment(FormDataParser.FORM_DATA);
FormData.FormValue rollback = data.getFirst("rollback_time");
String rollback_int = "0";
if (rollback != null) {
rollback_int = rollback.getValue();
}
return Integer.parseInt(rollback_int);
}
示例11: signUp
import io.undertow.server.handlers.form.FormData; //导入方法依赖的package包/类
public void signUp(HttpServerExchange exchange) {
FormData data = exchange.getAttachment(FormDataParser.FORM_DATA);
FormData.FormValue nameVal = data.getFirst("username");
FormData.FormValue tokenVal = data.getFirst("token");
if (nameVal == null || tokenVal == null) {
respond(exchange, StatusCodes.BAD_REQUEST, new Error("bad_params", "Missing parameters"));
return;
}
String name = nameVal.getValue();
String token = tokenVal.getValue();
if (token.isEmpty()) {
respond(exchange, StatusCodes.BAD_REQUEST, new Error("bad_token", "Missing signup token"));
return;
} else if (name.isEmpty()) {
respond(exchange, StatusCodes.BAD_REQUEST, new Error("bad_username", "Username may not be empty"));
return;
} else if (!name.matches("[a-zA-Z0-9_\\-]+")) {
respond(exchange, StatusCodes.BAD_REQUEST, new Error("bad_username", "Username contains invalid characters"));
return;
} else if (!App.getUserManager().isValidSignupToken(token)) {
respond(exchange, StatusCodes.BAD_REQUEST, new Error("bad_token", "Invalid signup token"));
return;
}
String ip = exchange.getAttachment(IPReader.IP);
User user = App.getUserManager().signUp(name, token, ip);
if (user == null) {
respond(exchange, StatusCodes.BAD_REQUEST, new Error("bad_username", "Username taken, try another?"));
return;
}
String loginToken = App.getUserManager().logIn(user, ip);
setAuthCookie(exchange, loginToken, 24);
respond(exchange, StatusCodes.OK, new SignUpResponse(loginToken));
}
示例12: report
import io.undertow.server.handlers.form.FormData; //导入方法依赖的package包/类
public void report(HttpServerExchange exchange) {
User user = exchange.getAttachment(AuthReader.USER);
if (user == null) {
exchange.setStatusCode(StatusCodes.BAD_REQUEST);
exchange.endExchange();
return;
}
FormData data = exchange.getAttachment(FormDataParser.FORM_DATA);
FormData.FormValue xq = data.getFirst("x");
FormData.FormValue yq = data.getFirst("y");
FormData.FormValue idq = data.getFirst("id");
FormData.FormValue msgq = data.getFirst("message");
if (xq == null || yq == null || idq == null || msgq == null) {
exchange.setStatusCode(StatusCodes.BAD_REQUEST);
exchange.endExchange();
return;
}
int x = Integer.parseInt(xq.getValue());
int y = Integer.parseInt(yq.getValue());
int id = Integer.parseInt(idq.getValue());
if (x < 0 || x >= App.getWidth() || y < 0 || y >= App.getHeight()) {
exchange.setStatusCode(StatusCodes.BAD_REQUEST);
exchange.endExchange();
return;
}
DBPixelPlacement pxl = App.getDatabase().getPixelByID(id);
if (pxl.x != x || pxl.y != y) {
exchange.setStatusCode(StatusCodes.BAD_REQUEST);
exchange.endExchange();
return;
}
App.getDatabase().addReport(user.getId(), id, x, y, msgq.getValue());
exchange.setStatusCode(200);
}
示例13: parseUserFromForm
import io.undertow.server.handlers.form.FormData; //导入方法依赖的package包/类
private User parseUserFromForm(HttpServerExchange exchange) {
FormData data = exchange.getAttachment(FormDataParser.FORM_DATA);
if (data != null) {
FormData.FormValue username = data.getFirst("username");
if (username != null) {
return App.getUserManager().getByName(username.getValue());
}
}
return null;
}
示例14: convertToStream
import io.undertow.server.handlers.form.FormData; //导入方法依赖的package包/类
private InputStream convertToStream(FormData.FormValue op) throws IOException {
if (op.isFile()) {
return Files.newInputStream(op.getPath());
} else {
return new ByteArrayInputStream(op.getValue().getBytes(StandardCharsets.UTF_8));
}
}
示例15: translateForms
import io.undertow.server.handlers.form.FormData; //导入方法依赖的package包/类
<T> Map<String, List<T>> translateForms(Predicate<FormData.FormValue> pred,
Function<FormData.FormValue, T> translator) {
FormData fd = this.exchange.getAttachment(FormDataParser.FORM_DATA);
if (fd == null) {
return Collections.emptyMap();
}
Map<String, List<T>> newone = new HashMap<>();
fd.forEach(k -> {
List<T> list = fd.get(k).stream().filter(pred).map(translator)
.collect(Collectors.toList());
newone.put(k, list);
});
return Collections.unmodifiableMap(newone);
}