public class RequestParameters extends Object
UriInfo and MultivaluedMap from the JAX-RS API. E.g. if you have a REST
query operation for a collection URI you can use UriInfo in case you want to support a mixture of optional
and required parameters. The methods provided here throw according exceptions such as BadRequestException and
already support conversion of values.| Modifier and Type | Field and Description |
|---|---|
private javax.ws.rs.core.MultivaluedMap<String,String> |
parameters |
| Constructor and Description |
|---|
RequestParameters(javax.ws.rs.core.MultivaluedMap<String,String> parameters)
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected <T> T |
convertValue(String value,
Class<T> targetType)
Converts the given
value to the given targetType. |
static RequestParameters |
fromPath(javax.ws.rs.core.UriInfo uriInfo) |
static RequestParameters |
fromQuery(javax.ws.rs.core.UriInfo uriInfo) |
String |
get(String key)
Gets the parameter as single value with the given
key as String. |
<T> T |
get(String key,
Class<T> targetType,
boolean required)
Gets the single parameter in a generic and flexible way.
|
String |
getFirst(String key)
Gets the parameter with the given
key as String. |
List<String> |
getList(String key)
Gets the
List of all value for the parameter with with the given key. |
public <T> T get(String key, Class<T> targetType, boolean required) throws javax.ws.rs.WebApplicationException
T - is the generic type of targetType.key - is the key of the parameter to get.targetType - is the Class reflecting the type to convert the value to. Supports common Java standard
types such as String, Long, Double, BigDecimal, etc.required - - true if the value is required and a BadRequestException is thrown if it is not
present, false otherwise (if optional).key converted to the given targetType. May be
null if required is false .javax.ws.rs.WebApplicationException - if an error occurred. E.g. BadRequestException if a required parameter is
missing or InternalServerErrorException if the given targetType is not supported.protected <T> T convertValue(String value, Class<T> targetType) throws ParseException
value to the given targetType.T - is the generic type of targetType.value - is the value to convert.targetType - is the Class reflecting the type to convert the value to.ParseException - if parsing of the given value failed while converting.public String get(String key) throws javax.ws.rs.BadRequestException
key as String.key - is the key of the parameter to get.null if the parameter is not present.javax.ws.rs.BadRequestException - if the parameter is defined multiple times (see getList(String)).public String getFirst(String key)
key as String. Unlike get(String) this method will
not throw an exception if the parameter is multi-valued but just return the first value.key - is the key of the parameter to get.null if the parameter is not present.public List<String> getList(String key)
List of all value for the parameter with with the given key. In general you should
avoid multi-valued parameters (e.g. http://host/path?query=a&query=b). The JAX-RS API supports this exotic case as
first citizen so we expose it here but only use it if you know exactly what you are doing.key - is the key of the parameter to get.List with all values of the requested parameter. Will be an empty list if the parameter is not present.public static RequestParameters fromQuery(javax.ws.rs.core.UriInfo uriInfo)
uriInfo - is the UriInfo.RequestParameters for UriInfo.getQueryParameters().public static RequestParameters fromPath(javax.ws.rs.core.UriInfo uriInfo)
uriInfo - is the UriInfo.RequestParameters for UriInfo.getPathParameters().Copyright © 2014–2019 devon4j-Team. All rights reserved.