use of io.undertow.server.handlers.form.FormData in project undertow by undertow-io.
the class HttpServletRequestImpl method loadParts.
private void loadParts() throws IOException, ServletException {
final ServletRequestContext requestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if (parts == null) {
final List<Part> parts = new ArrayList<>();
String mimeType = exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE);
if (mimeType != null && mimeType.startsWith(MultiPartParserDefinition.MULTIPART_FORM_DATA)) {
FormData formData = parseFormData();
if (formData != null) {
for (final String namedPart : formData) {
for (FormData.FormValue part : formData.get(namedPart)) {
parts.add(new PartImpl(namedPart, part, requestContext.getOriginalServletPathMatch().getServletChain().getManagedServlet().getMultipartConfig(), servletContext, this));
}
}
}
} else {
throw UndertowServletMessages.MESSAGES.notAMultiPartRequest();
}
this.parts = parts;
}
}
use of io.undertow.server.handlers.form.FormData in project runwar by cfmlprojects.
the class RequestDebugHandler method dumpRequestBody.
private void dumpRequestBody(HttpServerExchange exchange, StringBuilder sb) {
try {
FormData formData = exchange.getAttachment(FormDataParser.FORM_DATA);
if (formData != null) {
sb.append("body=\n");
for (String formField : formData) {
Deque<FormData.FormValue> formValues = formData.get(formField);
sb.append(formField).append("=");
for (FormData.FormValue formValue : formValues) {
sb.append(formValue.isFile() ? "[file-content]" : formValue.getValue());
sb.append("\n");
if (formValue.getHeaders() != null) {
sb.append("headers=\n");
for (HeaderValues header : formValue.getHeaders()) {
sb.append("\t").append(header.getHeaderName()).append("=").append(header.getFirst()).append("\n");
}
}
}
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of io.undertow.server.handlers.form.FormData in project undertow by undertow-io.
the class HttpServletRequestImpl method getParameterNames.
@Override
public Enumeration<String> getParameterNames() {
if (queryParameters == null) {
queryParameters = exchange.getQueryParameters();
}
final Set<String> parameterNames = new HashSet<>(queryParameters.keySet());
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.isFileItem()) {
parameterNames.add(name);
break;
}
}
}
}
return new IteratorEnumeration<>(parameterNames.iterator());
}
use of io.undertow.server.handlers.form.FormData in project undertow by undertow-io.
the class MCMPHandler method parseFormData.
/**
* Transform the form data into an intermediate request data which can me used
* by the web manager
*
* @param exchange the http server exchange
* @return
* @throws IOException
*/
RequestData parseFormData(final HttpServerExchange exchange) throws IOException {
// Read post parameters
final FormDataParser parser = parserFactory.createParser(exchange);
final FormData formData = parser.parseBlocking();
final RequestData data = new RequestData();
for (String name : formData) {
final HttpString key = new HttpString(name);
data.add(key, formData.get(name));
}
return data;
}
use of io.undertow.server.handlers.form.FormData in project mxisd by kamax-io.
the class BasicHttpHandler method getOrThrow.
protected String getOrThrow(FormData data, String key) {
FormData.FormValue value = data.getFirst(key);
if (Objects.isNull(value)) {
throw new IllegalArgumentException("Form key " + key + " is missing");
}
String object = value.getValue();
if (Objects.isNull(object)) {
throw new IllegalArgumentException("Form key " + key + " does not have a value");
}
return object;
}
Aggregations