public class RequestParameters extends Object
Here is a snippet demonstrating how to obtain a request parameter value:
String value = RequestParameters.of(request).getString("myParameterName", "theDefaultValue");
Modifier and Type | Method and Description |
---|---|
boolean |
getBoolean(String name,
boolean defaultValue)
Returns the boolean value associated with the specified request parameter or default value if parameter is not set.
|
boolean |
getRequiredBoolean(String name)
Returns the boolean value associated with the specified request parameter name that is required to exist.
|
String |
getRequiredString(String name)
Returns the string value associated with the specified request parameter name that is required to exist.
|
URI |
getRequiredURI(String name)
Returns the URI value associated with the specified request parameter name that is required to exist.
|
Optional<String> |
getString(String name)
Returns the string value associated with the specified request parameter name.
|
String |
getString(String name,
String defaultValue)
Returns the string value associated with the specified request parameter or default value if parameter is not set.
|
Optional<URI> |
getURI(String name)
Returns the URI value associated with the specified request parameter name.
|
static RequestParameters |
of(HttpServletRequest request)
Returns an instance that wraps the specified servlet request.
|
static <T> T |
requireNonNull(T parameter,
String name)
Convenient method to ensure a parameter is not
null . |
public static RequestParameters of(HttpServletRequest request)
request
- a servlet request.public Optional<String> getString(String name)
name
- the parameter name.public String getRequiredString(String name)
name
- the parameter name.WebApplicationException
- if the parameter is not set in servlet request parameters.public String getString(String name, String defaultValue)
name
- the parameter name.defaultValue
- the default value to use if the request parameter is not set.public boolean getRequiredBoolean(String name)
name
- the parameter name.WebApplicationException
- if the parameter is not set in request parameters.public boolean getBoolean(String name, boolean defaultValue)
name
- the parameter name.defaultValue
- the default value to use if the request parameter is not set.public Optional<URI> getURI(String name)
If the parameter value is surrounded by '<'
and '>'
characters,
this method strips them to obtain the URI.
name
- the parameter name.WebApplicationException
- if the parameter value is not a valid URI.public URI getRequiredURI(String name)
If the parameter value is surrounded by '<'
and '>'
characters,
this method strips them to obtain the URI.
name
- the parameter name.WebApplicationException
- if the parameter is not set in request parameters or if the value is not a valid URI.public static <T> T requireNonNull(T parameter, String name)
null
.
This shall be used to assert the presence of a value obtained with a QueryParam
annotation on a method argument.T
- parameter's type.parameter
- parameter's value.name
- parameter's name.WebApplicationException
- if parameter
is null
.