Class RequestAttributes

java.lang.Object
org.apache.juneau.rest.httppart.RequestAttributes

public class RequestAttributes extends Object
Represents the attributes in an HTTP request.

The RequestAttributes object is the API for accessing the standard servlet attributes on an HTTP request (i.e. ServletRequest.getAttribute(String)).

@RestPost(...) public Object myMethod(RequestAttributes attributes) {...}

Example:

@RestPost(...) public Object myMethod(RequestAttributes attributes) { // Add a default value. attributes.addDefault("Foo", 123); // Get an attribute value as a POJO. UUID etag = attributes.get("ETag").as(UUID.class).orElse(null); }

Some important methods on this class are:

Modifications made to request attributes through the RequestAttributes bean are automatically reflected in the underlying servlet request attributes making it possible to mix the usage of both APIs.

See Also:
  • Constructor Details

  • Method Details

    • addDefault

      Adds default entries to the request attributes.
      Parameters:
      pairs - The default entries.
      Can be null.
      Returns:
      This object.
    • addDefault

      Adds default entries to the request attributes.
      Parameters:
      pairs - The default entries.
      Can be null.
      Returns:
      This object.
    • addDefault

      Adds default entries to the request attributes.
      Parameters:
      pairs - The default entries.
      Can be null.
      Returns:
      This object.
    • addDefault

      public RequestAttributes addDefault(String name, Object value)
      Adds a default entry to the request attributes.
      Parameters:
      name - The name.
      value - The value.
      Returns:
      This object.
    • get

      public RequestAttribute get(String name)
      Returns the request attribute with the specified name.
      Parameters:
      name - The attribute name.
      Returns:
      The parameter value, or Optional.empty() if it doesn't exist.
    • getAll

      Returns all the attribute on this request.
      Returns:
      All the attribute on this request.
    • contains

      public boolean contains(String... names)
      Returns true if the attributes with the specified names are present.
      Parameters:
      names - The attribute names. 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 attribute with any of the specified names are present.
      Parameters:
      names - The attribute names. Must not be null.
      Returns:
      true if the attribute with any of the specified names are present.
    • set

      public RequestAttributes set(String name, Object value)
      Sets a request attribute.
      Parameters:
      name - The attribute name. Must not be null.
      value - The attribute value.
      Can be null.
      Returns:
      This object.
    • set

      public RequestAttributes set(NamedAttribute... attributes)
      Sets request attributes.
      Parameters:
      attributes - The parameters to set. Must not be null or contain null.
      Returns:
      This object.
    • remove

      public RequestAttributes remove(String... name)
      Remove request attributes.
      Parameters:
      name - The attribute names. Must not be null.
      Returns:
      This object.
    • remove

      public RequestAttributes remove(NamedAttribute... attributes)
      Remove request attributes.
      Parameters:
      attributes - The attributes to remove. Must not be null.
      Returns:
      This object.
    • asMap

      public Map<String,Object> asMap()
      Returns the request attributes as a map.
      Returns:
      The request attributes as a map. Never null.
    • toString

      public String toString()
      Overrides:
      toString in class Object