Java Code Examples for io.undertow.server.handlers.form.FormData#get()

The following examples show how to use io.undertow.server.handlers.form.FormData#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpServletRequestImpl.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Override
public Enumeration<String> getParameterNames() {
    if (queryParameters == null) {
        queryParameters = exchange.getQueryParameters();
    }
    final Set<String> parameterNames = new HashSet<>(queryParameters.keySet());
    if (exchange.getRequestMethod().equals(HttpMethodNames.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.isFileItem()) {
                        parameterNames.add(name);
                        break;
                    }
                }
            }
        }
    }
    return new IteratorEnumeration<>(parameterNames.iterator());
}
 
Example 2
Source File: HttpServletRequestImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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());
}
 
Example 3
Source File: HttpServletRequestImpl.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@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(HttpMethodNames.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.isFileItem()) {
                        ret.add(value.getValue());
                    }
                }
            }
        }
    }
    if (ret.isEmpty()) {
        return null;
    }
    return ret.toArray(new String[ret.size()]);
}
 
Example 4
Source File: ServerRequest.java    From proteus with Apache License 2.0 5 votes vote down vote up
private void extractFormParameters(final FormData formData)
{
    if (formData != null) {
        for (String key : formData) {
            final Deque<FormData.FormValue> formValues = formData.get(key);
            final Deque<String> values = formValues.stream()
                    .filter(fv -> !fv.isFileItem())
                    .map(FormData.FormValue::getValue)
                    .collect(java.util.stream.Collectors.toCollection(FastConcurrentDirectDeque::new));

            exchange.getQueryParameters().put(key, values);
        }
    }
}
 
Example 5
Source File: HttpServletRequestImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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()]);
}
 
Example 6
Source File: RequestDumpingHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 7
Source File: FormHandler.java    From mangooio with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the form parameter from a request
 *
 * @param exchange The Undertow HttpServerExchange
 *
 * @throws IOException
 */
@SuppressWarnings("rawtypes")
protected Form getForm(HttpServerExchange exchange) throws IOException {
    final Form form = Application.getInstance(Form.class);
    if (RequestUtils.isPostPutPatch(exchange)) {
        final Builder builder = FormParserFactory.builder();
        builder.setDefaultCharset(StandardCharsets.UTF_8.name());
        try (final FormDataParser formDataParser = builder.build().createParser(exchange)) {
            if (formDataParser != null) {
                exchange.startBlocking();
                final FormData formData = formDataParser.parseBlocking();
                for (String data : formData) {
                    Deque<FormValue> deque = formData.get(data);
                    if (deque != null) {
                        FormValue formValue = deque.element();
                        if (formValue != null) {
                            if (formValue.isFileItem() && formValue.getFileItem().getFile() != null) {
                                form.addFile(Files.newInputStream(formValue.getFileItem().getFile()));
                            } 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;
}