Search in sources :

Example 11 with FormData

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;
    }
}
Also used : FormData(io.undertow.server.handlers.form.FormData) Part(javax.servlet.http.Part) ArrayList(java.util.ArrayList) ServletRequestContext(io.undertow.servlet.handlers.ServletRequestContext) HttpString(io.undertow.util.HttpString)

Example 12 with FormData

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);
    }
}
Also used : FormData(io.undertow.server.handlers.form.FormData) HeaderValues(io.undertow.util.HeaderValues)

Example 13 with FormData

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());
}
Also used : FormData(io.undertow.server.handlers.form.FormData) IteratorEnumeration(io.undertow.servlet.util.IteratorEnumeration) HttpString(io.undertow.util.HttpString) HashSet(java.util.HashSet)

Example 14 with FormData

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;
}
Also used : FormData(io.undertow.server.handlers.form.FormData) FormDataParser(io.undertow.server.handlers.form.FormDataParser) HttpString(io.undertow.util.HttpString) HttpString(io.undertow.util.HttpString)

Example 15 with FormData

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;
}
Also used : FormData(io.undertow.server.handlers.form.FormData) HttpString(io.undertow.util.HttpString)

Aggregations

FormData (io.undertow.server.handlers.form.FormData)15 HttpString (io.undertow.util.HttpString)10 FormDataParser (io.undertow.server.handlers.form.FormDataParser)4 ArrayList (java.util.ArrayList)3 FormParserFactory (io.undertow.server.handlers.form.FormParserFactory)2 HeaderValues (io.undertow.util.HeaderValues)2 HashMap (java.util.HashMap)2 JsonParser (com.fasterxml.jackson.core.JsonParser)1 TreeNode (com.fasterxml.jackson.core.TreeNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JsonObject (com.google.gson.JsonObject)1 FieldParam (core.framework.impl.log.filter.FieldParam)1 MultipartFile (core.framework.web.MultipartFile)1 SuccessStatusJson (io.kamax.mxisd.http.io.identity.SuccessStatusJson)1 Undertow (io.undertow.Undertow)1 Account (io.undertow.security.idm.Account)1 IdentityManager (io.undertow.security.idm.IdentityManager)1 PasswordCredential (io.undertow.security.idm.PasswordCredential)1 HttpServerExchange (io.undertow.server.HttpServerExchange)1 ServletRequestContext (io.undertow.servlet.handlers.ServletRequestContext)1