Class RequestParameters

java.lang.Object
google.registry.request.RequestParameters

public final class RequestParameters extends Object
Utilities for extracting parameters from HTTP requests.
  • Field Details

    • PARAM_TLD

      public static final String PARAM_TLD
      The standardized request parameter name used by any action taking a tld parameter.
      See Also:
    • PARAM_TLDS

      public static final String PARAM_TLDS
      The standardized request parameter name used by any action taking multiple tld parameters.
      See Also:
    • PARAM_DRY_RUN

      public static final String PARAM_DRY_RUN
      The standardized request parameter name used by any action in dry run mode.
      See Also:
    • PARAM_BATCH_SIZE

      public static final String PARAM_BATCH_SIZE
      The standardized request parameter name used by any action taking a configurable batch size.
      See Also:
  • Method Details

    • extractRequiredParameter

      public static String extractRequiredParameter(jakarta.servlet.http.HttpServletRequest req, String name)
      Returns first GET or POST parameter associated with name.

      For example, assume name is "bar". The following request URIs would cause this method to yield the following results:

      • /foo?bar=hello → hello
      • /foo?bar=hello&bar=there → hello
      • /foo?bar= → 400 error (empty)
      • /foo?bar=&bar=there → 400 error (empty)
      • /foo → 400 error (absent)
      Throws:
      HttpException.BadRequestException - if request parameter is absent or empty
    • extractOptionalParameter

      public static Optional<String> extractOptionalParameter(jakarta.servlet.http.HttpServletRequest req, String name)
      Returns the first GET or POST parameter associated with name.
    • extractOptionalIntParameter

      public static Optional<Integer> extractOptionalIntParameter(jakarta.servlet.http.HttpServletRequest req, String name)
      Returns first GET or POST parameter associated with name as an integer.
      Throws:
      HttpException.BadRequestException - if request parameter is present but not a valid integer
    • extractIntParameter

      public static int extractIntParameter(jakarta.servlet.http.HttpServletRequest req, String name)
      Returns first GET or POST parameter associated with name as an integer.
      Throws:
      HttpException.BadRequestException - if request parameter is absent, empty, or not a valid integer
    • extractOptionalLongParameter

      public static Optional<Long> extractOptionalLongParameter(jakarta.servlet.http.HttpServletRequest req, String name)
      Returns first GET or POST parameter associated with name as a long.
      Throws:
      HttpException.BadRequestException - if request parameter is present but not a valid long
    • extractLongParameter

      public static long extractLongParameter(jakarta.servlet.http.HttpServletRequest req, String name)
      Returns first GET or POST parameter associated with name as a long.
      Throws:
      HttpException.BadRequestException - if request parameter is absent, empty, or not a valid long
    • extractSetOfParameters

      public static com.google.common.collect.ImmutableSet<String> extractSetOfParameters(jakarta.servlet.http.HttpServletRequest req, String name)
      Returns all GET or POST parameters associated with name.

      The parameter value is assumed to be a comma-delimited set of values - so tlds=com,net would result in ImmutableSet.of("com", "net").

      Empty strings are not supported, and are automatically removed from the result.

      Both missing parameter and parameter with empty value result in an empty set.

      Parameters:
      req - the request that has the parameter
      name - the name of the parameter (should be in plural form. e.g., tlds=, not tld=)
    • extractOptionalEnumParameter

      public static <C extends Enum<C>> Optional<C> extractOptionalEnumParameter(jakarta.servlet.http.HttpServletRequest req, Class<C> enumClass, String name)
      Returns all GET or POST parameters associated with name.

      The parameter value is assumed to be a comma-delimited set of values - so tlds=com,net would result in ImmutableSet.of("com", "net").

      Empty strings are not supported, and are automatically removed from the result.

      Both missing parameter and parameter with empty value result in an empty set.

      Parameters:
      req - the request that has the parameter
      enumClass - the Class of the expected Enum type
      name - the name of the parameter (should be in plural form e.g., tlds=, not tld=)
      Throws:
      HttpException.BadRequestException - if any of the comma-delimited values of the request parameter named name aren't equal to any of the values in enumClass
    • extractEnumParameter

      public static <C extends Enum<C>> C extractEnumParameter(jakarta.servlet.http.HttpServletRequest req, Class<C> enumClass, String name)
      Returns the first GET or POST parameter associated with name.
      Throws:
      HttpException.BadRequestException - if request parameter named name is absent, empty, or not equal to any of the values in enumClass
    • extractSetOfEnumParameters

      public static <C extends Enum<C>> com.google.common.collect.ImmutableSet<C> extractSetOfEnumParameters(jakarta.servlet.http.HttpServletRequest req, Class<C> enumClass, String name)
      Returns the first GET or POST parameter associated with name.
      Throws:
      HttpException.BadRequestException - if request parameter named name is absent, empty, or not equal to any of the values in enumClass
    • extractOptionalBooleanParameter

      public static Optional<Boolean> extractOptionalBooleanParameter(jakarta.servlet.http.HttpServletRequest req, String name)
      Returns first GET or POST parameter associated with name as a boolean.
      Throws:
      HttpException.BadRequestException - if request parameter is present but not a valid boolean
    • extractBooleanParameter

      public static boolean extractBooleanParameter(jakarta.servlet.http.HttpServletRequest req, String name)
      Returns true iff the given parameter is present, not empty, and not "false".

      This considers a parameter with a non-existent value true, for situations where the request URI is something like /foo?bar, where the mere presence of the bar parameter without a value indicates that it's true.

    • extractRequiredDatetimeParameter

      public static org.joda.time.DateTime extractRequiredDatetimeParameter(jakarta.servlet.http.HttpServletRequest req, String name)
      Returns first request parameter associated with name parsed as an ISO 8601 timestamp, e.g. 1984-12-18TZ, 2000-01-01T16:20:00Z.
      Throws:
      HttpException.BadRequestException - if request parameter named name is absent, empty, or could not be parsed as an ISO 8601 timestamp
    • extractOptionalDatetimeParameter

      public static Optional<org.joda.time.DateTime> extractOptionalDatetimeParameter(jakarta.servlet.http.HttpServletRequest req, String name)
      Returns first request parameter associated with name parsed as an ISO 8601 timestamp, e.g. 1984-12-18TZ, 2000-01-01T16:20:00Z.
      Throws:
      HttpException.BadRequestException - if request parameter is present but not a valid DateTime.
    • extractSetOfDatetimeParameters

      public static com.google.common.collect.ImmutableSet<org.joda.time.DateTime> extractSetOfDatetimeParameters(jakarta.servlet.http.HttpServletRequest req, String name)
      Returns all GET or POST date parameters associated with name, or an empty set if none.

      Dates are parsed as an ISO 8601 timestamp, e.g. 1984-12-18TZ, 2000-01-01T16:20:00Z.

      Throws:
      HttpException.BadRequestException - if one of the parameter values is not a valid DateTime.
    • extractRequiredHeader

      public static String extractRequiredHeader(jakarta.servlet.http.HttpServletRequest req, String name)
      Returns first HTTP header associated with name.
      Parameters:
      name - case-insensitive header name
      Throws:
      HttpException.BadRequestException - if request header is absent or empty
    • extractOptionalHeader

      public static Optional<String> extractOptionalHeader(jakarta.servlet.http.HttpServletRequest req, String name)
      Returns an Optional of the first HTTP header associated with name, or empty.
      Parameters:
      name - case-insensitive header name