Class RequestParameters
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The standardized request parameter name used by any action taking a configurable batch size.static final String
The standardized request parameter name used by any action in dry run mode.static final String
The standardized request parameter name used by any action taking a tld parameter.static final String
The standardized request parameter name used by any action taking multiple tld parameters. -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
extractBooleanParameter
(jakarta.servlet.http.HttpServletRequest req, String name) Returnstrue
iff the given parameter is present, not empty, and not"false"
.static <C extends Enum<C>>
CextractEnumParameter
(jakarta.servlet.http.HttpServletRequest req, Class<C> enumClass, String name) Returns the first GET or POST parameter associated withname
.static int
extractIntParameter
(jakarta.servlet.http.HttpServletRequest req, String name) Returns first GET or POST parameter associated withname
as an integer.static long
extractLongParameter
(jakarta.servlet.http.HttpServletRequest req, String name) Returns first GET or POST parameter associated withname
as a long.extractOptionalBooleanParameter
(jakarta.servlet.http.HttpServletRequest req, String name) Returns first GET or POST parameter associated withname
as a boolean.static Optional
<org.joda.time.DateTime> extractOptionalDatetimeParameter
(jakarta.servlet.http.HttpServletRequest req, String name) Returns first request parameter associated withname
parsed as an ISO 8601 timestamp, e.g.extractOptionalEnumParameter
(jakarta.servlet.http.HttpServletRequest req, Class<C> enumClass, String name) Returns all GET or POST parameters associated withname
.extractOptionalHeader
(jakarta.servlet.http.HttpServletRequest req, String name) Returns anOptional
of the first HTTP header associated withname
, or empty.extractOptionalIntParameter
(jakarta.servlet.http.HttpServletRequest req, String name) Returns first GET or POST parameter associated withname
as an integer.extractOptionalLongParameter
(jakarta.servlet.http.HttpServletRequest req, String name) Returns first GET or POST parameter associated withname
as a long.extractOptionalParameter
(jakarta.servlet.http.HttpServletRequest req, String name) Returns the first GET or POST parameter associated withname
.static org.joda.time.DateTime
extractRequiredDatetimeParameter
(jakarta.servlet.http.HttpServletRequest req, String name) Returns first request parameter associated withname
parsed as an ISO 8601 timestamp, e.g.static String
extractRequiredHeader
(jakarta.servlet.http.HttpServletRequest req, String name) Returns first HTTP header associated withname
.static String
extractRequiredParameter
(jakarta.servlet.http.HttpServletRequest req, String name) Returns first GET or POST parameter associated withname
.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 withname
, or an empty set if none.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 withname
.static com.google.common.collect.ImmutableSet
<String> extractSetOfParameters
(jakarta.servlet.http.HttpServletRequest req, String name) Returns all GET or POST parameters associated withname
.
-
Field Details
-
PARAM_TLD
The standardized request parameter name used by any action taking a tld parameter.- See Also:
-
PARAM_TLDS
The standardized request parameter name used by any action taking multiple tld parameters.- See Also:
-
PARAM_DRY_RUN
The standardized request parameter name used by any action in dry run mode.- See Also:
-
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 withname
.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 withname
. -
extractOptionalIntParameter
public static Optional<Integer> extractOptionalIntParameter(jakarta.servlet.http.HttpServletRequest req, String name) Returns first GET or POST parameter associated withname
as an integer.- Throws:
HttpException.BadRequestException
- if request parameter is present but not a valid integer
-
extractIntParameter
Returns first GET or POST parameter associated withname
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 withname
as a long.- Throws:
HttpException.BadRequestException
- if request parameter is present but not a valid long
-
extractLongParameter
Returns first GET or POST parameter associated withname
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 withname
.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 parametername
- 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 withname
.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 parameterenumClass
- the Class of the expected Enum typename
- 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 namedname
aren't equal to any of the values inenumClass
-
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 withname
.- Throws:
HttpException.BadRequestException
- if request parameter namedname
is absent, empty, or not equal to any of the values inenumClass
-
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 withname
.- Throws:
HttpException.BadRequestException
- if request parameter namedname
is absent, empty, or not equal to any of the values inenumClass
-
extractOptionalBooleanParameter
public static Optional<Boolean> extractOptionalBooleanParameter(jakarta.servlet.http.HttpServletRequest req, String name) Returns first GET or POST parameter associated withname
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) Returnstrue
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 thebar
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 withname
parsed as an ISO 8601 timestamp, e.g.1984-12-18TZ
,2000-01-01T16:20:00Z
.- Throws:
HttpException.BadRequestException
- if request parameter namedname
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 withname
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 validDateTime
.
-
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 withname
, 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 validDateTime
.
-
extractRequiredHeader
public static String extractRequiredHeader(jakarta.servlet.http.HttpServletRequest req, String name) Returns first HTTP header associated withname
.- 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 anOptional
of the first HTTP header associated withname
, or empty.- Parameters:
name
- case-insensitive header name
-