Class RequestFormParamList

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.ArrayList<RequestFormParam>
org.apache.juneau.rest.server.httppart.RequestFormParamList
All Implemented Interfaces:
Serializable, Cloneable, Iterable<RequestFormParam>, Collection<RequestFormParam>, List<RequestFormParam>, RandomAccess

Represents the parsed form-data parameters in an HTTP request.

The RequestFormParamList object is the API for accessing the HTTP request content as form data. It can be accessed by passing it as a parameter on your REST Java method:

@RestPost(...) public Object myMethod(RequestFormParamList formData) {...}

Example:

@RestPost(...) public Object myMethod(RequestFormParamList formData) { // Get query parameters converted to various types. int p1 = formData.get("p1").asInteger().orElse(0); String p2 = formData.get("p2").orElse(null); UUID p3 = formData.get("p3").as(UUID.class).orElse(null); }

Note that this object does NOT take GET parameters into account and only returns values found in the content of the request.

Some important methods on this class are:

See Also:
See Also:
  • Constructor Details

    • RequestFormParamList

      public RequestFormParamList(RestRequest req, boolean caseSensitive) throws Exception
      Constructor.

      For a multipart/form-data request, the effective @Rest(maxInput) ceiling is enforced against both the declared Content-Length (checked before the servlet container parses the body) and the cumulative size of the parsed parts (checked afterward, as a backstop for a declared length that was absent, chunked, or simply didn't match) — a request whose multipart body is too large is rejected with a PayloadTooLarge (413) response rather than being handed off to the servlet container's own (often much larger, or unset) multipart limits.

      Parameters:
      req - The request creating this bean. Must not be null.
      caseSensitive - Whether case-sensitive name matching is enabled.
      Throws:
      Exception - Any exception can be thrown.
  • Method Details

    • add

      public RequestFormParamList add(HttpPart... parameters)
      Adds request parameter values.

      Parameters are added to the end.
      Existing parameters with the same name are not changed.

      Parameters:
      parameters - The parameter objects. Must not be null.
      Returns:
      This object.
    • add

      public RequestFormParamList add(jakarta.servlet.http.Part part)
      Adds a parameter value.

      Parameter is added to the end.
      Existing parameter with the same name are not changed.

      Parameters:
      part - The parameter part. Must not be null.
      Returns:
      This object.
    • add

      public RequestFormParamList add(String name, Object value)
      Adds a parameter value.

      Parameter is added to the end.
      Existing parameter with the same name are not changed.

      Parameters:
      name - The parameter name. Must not be null.
      value - The parameter value.
      Returns:
      This object.
    • addDefault

      public RequestFormParamList addDefault(List<? extends HttpPart> pairs)
      Adds default entries to these parameters.

      Similar to set(String, Object) but doesn't override existing values.

      Parameters:
      pairs - The default entries.
      Can be null (no-op).
      Returns:
      This object.
    • addDefault

      Adds default entries to these parameters.

      Similar to set(String, Object) but doesn't override existing values.

      Parameters:
      pairs - The default entries.
      Can be null (no-op).
      Returns:
      This object.
    • addDefault

      Adds a default entry to the form data parameters.
      Parameters:
      name - The name.
      value - The value.
      Returns:
      This object.
    • asQueryString

      Converts this object to a query string.

      Returned query string does not start with '?'.

      Returns:
      A new query string, or an empty string if this object is empty.
    • caseSensitive

      public RequestFormParamList caseSensitive(boolean value)
      Sets case sensitivity for names in this list.
      Parameters:
      value - The new value for this setting.
      Returns:
      This object (for method chaining).
    • contains

      public boolean contains(String name)
      Returns true if the parameters with the specified names are present.
      Parameters:
      name - The parameter name. Must not be null.
      Returns:
      true if the parameters with the specified names are present.
    • containsAny

      public boolean containsAny(String... names)
      Returns true if the parameter with any of the specified names are present.
      Parameters:
      names - The parameter names. Must not be null.
      Returns:
      true if the parameter with any of the specified names are present.
    • copy

      Makes a copy of these parameters.
      Returns:
      A new parameters object.
    • get

      public <T> Optional<T> get(Class<T> type)
      Returns the form data parameter as the specified bean type.

      Type must have a name specified via the FormData annotation and a public constructor that takes in either value or name,value as strings.

      Type Parameters:
      T - The bean type to create.
      Parameters:
      type - The bean type to create.
      Returns:
      The bean, or Optional.empty() if the parameter is not present.
    • get

      public RequestFormParam get(String name)
      Returns the condensed parameter with the specified name.

      If multiple parameters are present, they will be combined into a single comma-delimited list.

      Parameters:
      name - The parameter name.
      Returns:
      The parameter, never null.
    • getAll

      Returns all the parameters with the specified name.
      Parameters:
      name - The parameter name.
      Returns:
      The list of all parameters with the specified name, or an empty list if none are found.
    • getFirst

      Returns the first parameter with the specified name.

      Note that this method never returns null and that RequestHttpPart.isPresent() can be used to test for the existence of the parameter.

      Parameters:
      name - The parameter name.
      Returns:
      The parameter. Never null.
    • getLast

      Returns the last parameter with the specified name.

      Note that this method never returns null and that RequestHttpPart.isPresent() can be used to test for the existence of the parameter.

      Parameters:
      name - The parameter name.
      Returns:
      The parameter. Never null.
    • getNames

      public List<String> getNames()
      Returns all the unique header names in this list.
      Returns:
      The list of all unique header names in this list.
    • getSorted

      Returns all headers in sorted order.
      Returns:
      The stream of all headers in sorted order.
    • parser

      Sets the parser to use for part values.
      Parameters:
      value - The new value for this setting.
      Returns:
      This object.
    • remove

      Remove parameters.
      Parameters:
      name - The parameter names. Must not be null.
      Returns:
      This object.
    • set

      public RequestFormParamList set(HttpPart... parameters)
      Sets request header values.

      Parameters are added to the end of the headers.
      Any previous parameters with the same name are removed.

      Parameters:
      parameters - The parameters to set. Must not be null or contain null.
      Returns:
      This object.
    • set

      public RequestFormParamList set(String name, Object value)
      Sets a parameter value.

      Parameter is added to the end.
      Any previous parameters with the same name are removed.

      Parameters:
      name - The parameter name. Must not be null.
      value - The parameter value.
      Converted to a string using Object.toString().
      Can be null (the parameter is set with a null value).
      Returns:
      This object.
    • stream

      Returns all headers with the specified name.
      Parameters:
      name - The header name.
      Returns:
      The stream of all headers with matching names. Never null.
    • subset

      public RequestFormParamList subset(String... names)
      Returns a copy of this object but only with the specified param names copied.
      Parameters:
      names - The list to include in the copy.
      Returns:
      A new list object.
    • properties

    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Collection<RequestFormParam>
      Specified by:
      equals in interface List<RequestFormParam>
      Overrides:
      equals in class ArrayList<RequestFormParam>
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Collection<RequestFormParam>
      Specified by:
      hashCode in interface List<RequestFormParam>
      Overrides:
      hashCode in class ArrayList<RequestFormParam>
    • toString

      public String toString()
      Overrides:
      toString in class AbstractCollection<RequestFormParam>