Class HttpParts

java.lang.Object
org.apache.juneau.http.HttpParts

public final class HttpParts extends Object
Static factory methods for creating HTTP parts (query parameters, form fields, path variables).

Import statically for clean DSL-style usage:

import static HttpParts.*; PartList form = PartList.of( part("username", "alice"), part("password", passwordSupplier) );

See Also:
Since:
9.2.1
  • Method Details

    • part

      public static HttpPart part(String name, String value)
      Creates an HttpPart with an eager string value.
      Parameters:
      name - The part name. Must not be null.
      value - The part value. May be null.
      Returns:
      A new part. Never null.
    • part

      public static HttpPart part(String name, Supplier<String> valueSupplier)
      Creates an HttpPart with a lazy value supplier.
      Parameters:
      name - The part name. Must not be null.
      valueSupplier - Supplier for the value. Must not be null.
      Returns:
      A new part. Never null.
    • partList

      public static PartList partList(HttpPart... parts)
      Creates a PartList from the given parts.
      Parameters:
      parts - The parts. Must not be null.
      Returns:
      A new list. Never null.
    • partListOfPairs

      public static PartList partListOfPairs(String... pairs)
      Creates a PartList from alternating name/value string pairs.
      Parameters:
      pairs - Alternating name/value strings. Must not be null. Length must be even.
      Returns:
      A new list. Never null.
    • getConstructor

      Returns the (String) or (String,String) public constructor for the specified type.

      Used by part-parsing logic to instantiate typed parts from a wire string.

      Parameters:
      type - The type to find the constructor on. Must not be null.
      Returns:
      The constructor wrapped in an Optional; empty if none is found.
    • isHttpPart

      public static boolean isHttpPart(HttpPartType partType, ClassMeta<?> type)
      Returns true if the specified type is a transport-neutral part type for the given HttpPartType.

      The check is whether the type is assignable to HttpHeader (for HEADER) or HttpPart (for PATH, QUERY, FORMDATA).

      Parameters:
      partType - The part type. Must not be null.
      type - The type to check. Must not be null.
      Returns:
      true if the type is a part type for the given category.
    • getName

      public static Optional<String> getName(HttpPartType partType, ClassMeta<?> type)
      Returns the name of the specified part type by reading the @Header, @Query, @FormData, or @Path annotation on the class.
      Parameters:
      partType - The part type. Must not be null.
      type - The type to check. Must not be null.
      Returns:
      The part name, wrapped in an Optional.