Package com.sodius.oslc.server
Class RequestParameters
java.lang.Object
com.sodius.oslc.server.RequestParameters
Provides access to query parameters set on servlet requests.
Here is a snippet demonstrating how to obtain a request parameter value:
String value = RequestParameters.of(request).getString("myParameterName", "theDefaultValue");
- Since:
- 1.4.0
-
Method Summary
Modifier and TypeMethodDescriptionbooleangetBoolean(String name, boolean defaultValue) Returns the boolean value associated with the specified request parameter or default value if parameter is not set.booleangetRequiredBoolean(String name) Returns the boolean value associated with the specified request parameter name that is required to exist.getRequiredString(String name) Returns the string value associated with the specified request parameter name that is required to exist.getRequiredURI(String name) Returns the URI value associated with the specified request parameter name that is required to exist.Returns the string value associated with the specified request parameter name.Returns the string value associated with the specified request parameter or default value if parameter is not set.Returns the URI value associated with the specified request parameter name.static RequestParametersof(HttpServletRequest request) Returns an instance that wraps the specified servlet request.static <T> TrequireNonNull(T parameter, String name) Convenient method to ensure a parameter is notnull.
-
Method Details
-
of
Returns an instance that wraps the specified servlet request.- Parameters:
request- a servlet request.- Returns:
- a new RequestParameters instance.
-
getString
Returns the string value associated with the specified request parameter name.- Parameters:
name- the parameter name.- Returns:
- an Optional wrapping the string value associated to the parameter name, Optional.empty() if none.
-
getRequiredString
Returns the string value associated with the specified request parameter name that is required to exist.- Parameters:
name- the parameter name.- Returns:
- the string value associated to the parameter name.
- Throws:
WebApplicationException- if the parameter is not set in servlet request parameters.
-
getString
Returns the string value associated with the specified request parameter or default value if parameter is not set.- Parameters:
name- the parameter name.defaultValue- the default value to use if the request parameter is not set.- Returns:
- the string value associated to the parameter name or the specified default value if the request parameter is not set.
-
getRequiredBoolean
Returns the boolean value associated with the specified request parameter name that is required to exist.- Parameters:
name- the parameter name.- Returns:
- the boolean value associated to the parameter name.
- Throws:
WebApplicationException- if the parameter is not set in request parameters.
-
getBoolean
Returns the boolean value associated with the specified request parameter or default value if parameter is not set.- Parameters:
name- the parameter name.defaultValue- the default value to use if the request parameter is not set.- Returns:
- the boolean value associated to the parameter name or the specified default value if the request parameter is not set.
-
getURI
Returns the URI value associated with the specified request parameter name.If the parameter value is surrounded by
'<'and'>'characters, this method strips them to obtain the URI.- Parameters:
name- the parameter name.- Returns:
- an Optional wrapping the URI value associated to the parameter name, Optional.empty() if none.
- Throws:
WebApplicationException- if the parameter value is not a valid URI.
-
getRequiredURI
Returns the URI value associated with the specified request parameter name that is required to exist.If the parameter value is surrounded by
'<'and'>'characters, this method strips them to obtain the URI.- Parameters:
name- the parameter name.- Returns:
- the URI associated to the parameter name.
- Throws:
WebApplicationException- if the parameter is not set in request parameters or if the value is not a valid URI.
-
requireNonNull
Convenient method to ensure a parameter is notnull. This shall be used to assert the presence of a value obtained with aQueryParamannotation on a method argument.- Type Parameters:
T- parameter's type.- Parameters:
parameter- parameter's value.name- parameter's name.- Returns:
- parameter's value.
- Throws:
WebApplicationException- ifparameterisnull.- Since:
- 1.14.0
-