本文整理汇总了Java中io.undertow.server.handlers.form.FormDataParser.parseBlocking方法的典型用法代码示例。如果您正苦于以下问题:Java FormDataParser.parseBlocking方法的具体用法?Java FormDataParser.parseBlocking怎么用?Java FormDataParser.parseBlocking使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.server.handlers.form.FormDataParser
的用法示例。
在下文中一共展示了FormDataParser.parseBlocking方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseFormData
import io.undertow.server.handlers.form.FormDataParser; //导入方法依赖的package包/类
private FormData parseFormData() {
if (parsedFormData == null) {
if (readStarted) {
return null;
}
final ManagedServlet originalServlet = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY).getCurrentServlet().getManagedServlet();
final FormDataParser parser = originalServlet.getFormParserFactory().createParser(exchange);
if (parser == null) {
return null;
}
readStarted = true;
try {
return parsedFormData = parser.parseBlocking();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return parsedFormData;
}
示例2: OvertownRequest
import io.undertow.server.handlers.form.FormDataParser; //导入方法依赖的package包/类
public OvertownRequest(HttpServerExchange exchange) {
this.exchange = exchange;
this.queryParameters = exchange.getQueryParameters();
this.parameterConverters = new HashMap<>();
this.viewAttributes = new ViewAttributes();
this.sessionManager = OvertownSessionManager.getInstance();
if (isPostRequest()) {
FormDataParser create = new FormEncodedDataDefinition().create(exchange);
try {
formData = create != null ? create.parseBlocking() : null;
} catch (IOException ioe) {
LOGGER.error(ioe.getMessage());
}
}
if( exchange.getAttachment( EXCEPTION_ATTACHMENT_KEY ) != null){
Exception e = exchange.getAttachment( EXCEPTION_ATTACHMENT_KEY );
addAttribute(ErrorHandler.ERROR_500, e);
exchange.removeAttachment( EXCEPTION_ATTACHMENT_KEY );
}
}
示例3: runFormAuth
import io.undertow.server.handlers.form.FormDataParser; //导入方法依赖的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);
}
}
示例4: getForm
import io.undertow.server.handlers.form.FormDataParser; //导入方法依赖的package包/类
/**
* Retrieves the form parameter from a request
*
* @param exchange The Undertow HttpServerExchange
*
* @throws IOException
*/
@SuppressWarnings("all")
protected Form getForm(HttpServerExchange exchange) throws IOException {
final Form form = Application.getInstance(Form.class);
if (this.requestHelper.isPostPutPatch(exchange)) {
final Builder builder = FormParserFactory.builder();
builder.setDefaultCharset(Charsets.UTF_8.name());
final FormDataParser formDataParser = builder.build().createParser(exchange);
if (formDataParser != null) {
exchange.startBlocking();
final FormData formData = formDataParser.parseBlocking();
formData.forEach(data -> {
Deque<FormValue> deque = formData.get(data);
if (deque != null) {
FormValue formValue = deque.element();
if (formValue != null) {
if (formValue.isFile() && formValue.getPath() != null) {
form.addFile(formValue.getPath().toFile());
} else {
if (data.contains("[]")) {
String key = StringUtils.replace(data, "[]", "");
for (Iterator iterator = deque.iterator(); iterator.hasNext();) {
form.addValueList(new HttpString(key).toString(), ((FormValue) iterator.next()).getValue());
}
} else {
form.addValue(new HttpString(data).toString(), formValue.getValue());
}
}
}
}
});
form.setSubmitted(true);
}
}
return form;
}
示例5: handleRequest
import io.undertow.server.handlers.form.FormDataParser; //导入方法依赖的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
}