本文整理汇总了Java中io.undertow.server.handlers.form.FormData.getFirst方法的典型用法代码示例。如果您正苦于以下问题:Java FormData.getFirst方法的具体用法?Java FormData.getFirst怎么用?Java FormData.getFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.server.handlers.form.FormData
的用法示例。
在下文中一共展示了FormData.getFirst方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
}
示例3: 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());
}
}
}
示例4: 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);
}
示例5: extractMetadata
import io.undertow.server.handlers.form.FormData; //导入方法依赖的package包/类
/**
* Search the request for a field named 'metadata' (or 'properties') which
* must contain valid JSON
*
* @param formData
* @return the parsed BsonDocument from the form data or an empty
* BsonDocument
*/
protected static BsonDocument extractMetadata(
final FormData formData)
throws JSONParseException {
BsonDocument metadata = new BsonDocument();
final String metadataString;
metadataString = formData.getFirst(FILE_METADATA) != null
? formData.getFirst(FILE_METADATA).getValue()
: formData.getFirst(PROPERTIES) != null
? formData.getFirst(PROPERTIES).getValue()
: null;
if (metadataString != null) {
metadata = BsonDocument.parse(metadataString);
}
return metadata;
}
示例6: 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);
}
}
示例7: 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;
}
示例8: 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);
}
示例9: 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));
}
示例10: 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);
}
示例11: 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;
}
示例12: extractFileField
import io.undertow.server.handlers.form.FormData; //导入方法依赖的package包/类
/**
* Find the name of the first file field in this request
*
* @param formData
* @return the first file field name or null
*/
private static String extractFileField(final FormData formData) {
String fileField = null;
for (String f : formData) {
if (formData.getFirst(f) != null && formData.getFirst(f).isFile()) {
fileField = f;
break;
}
}
return fileField;
}
示例13: handleRequest
import io.undertow.server.handlers.form.FormData; //导入方法依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
final FormDataParser parser = formParserFactory.createParser(exchange);
FormData data = parser.parseBlocking();
for (String fieldName : data) {
//Get all the files
FormValue value = data.getFirst(fieldName);
if (value.isFile()) {
ModelNode response = null;
InputStream in = new BufferedInputStream(new FileInputStream(value.getPath().toFile()));
try {
final ModelNode dmr = new ModelNode();
dmr.get("operation").set("upload-deployment-stream");
dmr.get("address").setEmptyList();
dmr.get("input-stream-index").set(0);
ModelNode headers = dmr.get(OPERATION_HEADERS);
headers.get(ACCESS_MECHANISM).set(AccessMechanism.HTTP.toString());
headers.get(CALLER_TYPE).set(USER);
OperationBuilder operation = new OperationBuilder(dmr);
operation.addInputStream(in);
response = modelController.execute(dmr, OperationMessageHandler.logging, ModelController.OperationTransactionControl.COMMIT, operation.build());
if (!response.get(OUTCOME).asString().equals(SUCCESS)){
Common.sendError(exchange, false, response);
return;
}
} catch (Throwable t) {
// TODO Consider draining input stream
ROOT_LOGGER.uploadError(t);
Common.sendError(exchange, false, t.getLocalizedMessage());
return;
} finally {
IoUtils.safeClose(in);
}
// TODO Determine what format the response should be in for a deployment upload request.
writeResponse(exchange, response, Common.TEXT_HTML);
return; //Ignore later files
}
}
Common.sendError(exchange, false, "No file found"); //TODO i18n
}