public final class RequestQuery extends LinkedHashMap<String,String[]>
Similar in functionality to the ServletRequest.getParameter(String)
except only looks in the URL string, not parameters from
URL-Encoded FORM posts.
This can be useful in cases where you're using GET parameters on FORM POSTs, and you don't want the body of the request to be read.
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Modifier and Type | Method and Description |
---|---|
RequestQuery |
addDefault(Map<String,Object> defaultEntries)
Adds default entries to these query parameters.
|
RequestQuery |
addDefault(String name,
Object value)
Adds a default entries to these query parameters.
|
String |
asQueryString()
Converts this object to a query string.
|
boolean |
containsAnyKeys(String... params)
Returns
|
<T> T |
get(HttpPartParserSession parser,
HttpPartSchema schema,
String name,
Class<T> type)
Same as
get(String, Class) but allows you to override the part parser. |
<T> T |
get(HttpPartParserSession parser,
HttpPartSchema schema,
String name,
T def,
Class<T> type)
Same as
get(String, Object, Class) but allows you to override the part parser. |
<T> T |
get(HttpPartParserSession parser,
HttpPartSchema schema,
String name,
T def,
Type type,
Type... args)
Same as
get(String, Object, Type, Type...) but allows you to override the part parser. |
<T> T |
get(HttpPartParserSession parser,
HttpPartSchema schema,
String name,
Type type,
Type... args)
Same as
get(String, Type, Type...) but allows you to override the part parser. |
String[] |
get(String name,
boolean caseInsensitive)
Same as
LinkedHashMap.get(Object) but allows you to find the query parameter using a case-insensitive match. |
<T> T |
get(String name,
Class<T> type)
Returns the specified query parameter value converted to a POJO using the
HttpPartParser registered with the resource. |
<T> T |
get(String name,
T def,
Class<T> type)
Same as
get(String, Class) except returns a default value if not found. |
<T> T |
get(String name,
T def,
Type type,
Type... args)
Same as
get(String, Class) except returns a default value if not found. |
<T> T |
get(String name,
Type type,
Type... args)
Returns the specified query parameter value converted to a POJO using the
HttpPartParser registered with the resource. |
<T> T |
getAll(HttpPartParserSession parser,
HttpPartSchema schema,
String name,
Type type,
Type... args)
Same as
getAll(String, Type, Type...) but allows you to override the part parser. |
<T> T |
getAll(String name,
Class<T> c)
Same as
get(String, Class) except for use on multi-part parameters
(e.g. |
<T> T |
getAll(String name,
Type type,
Type... args)
Same as
get(String, Type, Type...) except for use on multi-part parameters
(e.g. |
boolean |
getBoolean(String name)
Same as
getString(String) but converts the value to a boolean. |
boolean |
getBoolean(String name,
boolean def)
Same as
getString(String,String) but converts the value to a boolean. |
int |
getInt(String name)
Same as
getString(String) but converts the value to an integer. |
int |
getInt(String name,
int def)
Same as
getString(String,String) but converts the value to an integer. |
SearchArgs |
getSearchArgs()
Locates the special search query arguments in the query and returns them as a
SearchArgs object. |
String |
getString(String name)
Returns a query parameter value as a string.
|
String |
getString(String name,
boolean caseInsensitive)
Same as
getString(String) but allows you to search for the query parameter using case-insensitive matching. |
String |
getString(String name,
String def)
Same as
getString(String) but returns the specified default value if the query parameter was not
specified. |
boolean |
hasAny(String... paramNames)
Returns
|
void |
put(String name,
Object value)
Sets a request query parameter value.
|
String |
toString() |
String |
toString(boolean sorted)
Converts the query parameters to a readable string.
|
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, removeEldestEntry, replaceAll, values
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
equals, hashCode
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
public RequestQuery addDefault(Map<String,Object> defaultEntries)
This includes the default queries defined at the resource and method levels.
defaultEntries
- The default entries.
public RequestQuery addDefault(String name, Object value)
Similar to put(String, Object)
but doesn't override existing values.
name
- The query parameter name.value
- The query parameter value.
public String[] get(String name, boolean caseInsensitive)
LinkedHashMap.get(Object)
but allows you to find the query parameter using a case-insensitive match.name
- The query parameter name.caseInsensitive
- If public void put(String name, Object value)
This overwrites any existing value.
name
- The parameter name.value
- The parameter value.
public String getString(String name)
If multiple query parameters have the same name, this returns only the first instance.
name
- The URL parameter name.public String getString(String name, boolean caseInsensitive)
getString(String)
but allows you to search for the query parameter using case-insensitive matching.
If multiple query parameters have the same name, this returns only the first instance.
name
- The URL parameter name.caseInsensitive
- If public String getString(String name, String def)
getString(String)
but returns the specified default value if the query parameter was not
specified.name
- The URL parameter name.def
- The default value.public int getInt(String name)
getString(String)
but converts the value to an integer.name
- The URL parameter name.public int getInt(String name, int def)
getString(String,String)
but converts the value to an integer.name
- The URL parameter name.def
- The default value.public boolean getBoolean(String name)
getString(String)
but converts the value to a boolean.name
- The URL parameter name.public boolean getBoolean(String name, boolean def)
getString(String,String)
but converts the value to a boolean.name
- The URL parameter name.def
- The default value.public <T> T get(String name, Class<T> type) throws BadRequest, InternalServerError
HttpPartParser
registered with the resource.
T
- The class type to convert the parameter value to.name
- The parameter name.type
- The class type to convert the parameter value to.BadRequest
- Thrown if input could not be parsed.InternalServerError
- Thrown if any other exception occurs.public <T> T get(HttpPartParserSession parser, HttpPartSchema schema, String name, Class<T> type) throws BadRequest, InternalServerError
get(String, Class)
but allows you to override the part parser.T
- The class type to convert the parameter value to.parser
- The parser to use for parsing the string value.
schema
- The schema object that defines the format of the input.
HttpPartSchema.DEFAULT
.
OpenApiParser
).name
- The parameter name.type
- The class type to convert the parameter value to.BadRequest
- Thrown if input could not be parsed or fails schema validation.InternalServerError
- Thrown if any other exception occurs.public <T> T get(String name, T def, Class<T> type) throws BadRequest, InternalServerError
get(String, Class)
except returns a default value if not found.T
- The class type to convert the parameter value to.name
- The parameter name.def
- The default value if the parameter was not specified or is type
- The class type to convert the parameter value to.BadRequest
- Thrown if input could not be parsed.InternalServerError
- Thrown if any other exception occurs.public <T> T get(HttpPartParserSession parser, HttpPartSchema schema, String name, T def, Class<T> type) throws BadRequest, InternalServerError
get(String, Object, Class)
but allows you to override the part parser.T
- The class type to convert the parameter value to.parser
- The parser to use for parsing the string value.
schema
- The schema object that defines the format of the input.
HttpPartSchema.DEFAULT
.
OpenApiParser
).name
- The parameter name.def
- The default value if the parameter was not specified or is type
- The class type to convert the parameter value to.BadRequest
- Thrown if input could not be parsed or fails schema validation.InternalServerError
- Thrown if any other exception occurs.public <T> T get(String name, Type type, Type... args) throws BadRequest, InternalServerError
HttpPartParser
registered with the resource.
Similar to get(String,Class)
but allows for complex collections of POJOs to be created.
T
- The class type to convert the parameter value to.name
- The parameter name.type
- The type of object to create.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
args
- The type arguments of the class if it's a collection or map.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
BadRequest
- Thrown if input could not be parsed.InternalServerError
- Thrown if any other exception occurs.public <T> T get(HttpPartParserSession parser, HttpPartSchema schema, String name, Type type, Type... args) throws BadRequest, InternalServerError
get(String, Type, Type...)
but allows you to override the part parser.T
- The class type to convert the parameter value to.parser
- The parser to use for parsing the string value.
schema
- The schema object that defines the format of the input.
HttpPartSchema.DEFAULT
.
OpenApiParser
).name
- The parameter name.type
- The type of object to create.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
args
- The type arguments of the class if it's a collection or map.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
BadRequest
- Thrown if input could not be parsed or fails schema validation.InternalServerError
- Thrown if any other exception occurs.public <T> T get(String name, T def, Type type, Type... args) throws BadRequest, InternalServerError
get(String, Class)
except returns a default value if not found.T
- The class type to convert the parameter value to.name
- The parameter name.type
- The type of object to create.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
args
- The type arguments of the class if it's a collection or map.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
def
- The default value if the parameter was not specified or is BadRequest
- Thrown if input could not be parsed.InternalServerError
- Thrown if any other exception occurs.public <T> T get(HttpPartParserSession parser, HttpPartSchema schema, String name, T def, Type type, Type... args) throws BadRequest, InternalServerError
get(String, Object, Type, Type...)
but allows you to override the part parser.T
- The class type to convert the parameter value to.parser
- The parser to use for parsing the string value.
schema
- The schema object that defines the format of the input.
HttpPartSchema.DEFAULT
.
OpenApiParser
).name
- The parameter name.type
- The type of object to create.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
args
- The type arguments of the class if it's a collection or map.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
def
- The default value if the parameter was not specified or is BadRequest
- Thrown if input could not be parsed or fails schema validation.InternalServerError
- Thrown if any other exception occurs.public <T> T getAll(String name, Class<T> c) throws BadRequest, InternalServerError
get(String, Class)
except for use on multi-part parameters
(e.g. This method must only be called when parsing into classes of type Collection or array.
T
- The class type to convert the parameter value to.name
- The query parameter name.c
- The class type to convert the parameter value to.BadRequest
- Thrown if input could not be parsed.InternalServerError
- Thrown if any other exception occurs.public <T> T getAll(String name, Type type, Type... args) throws BadRequest, InternalServerError
get(String, Type, Type...)
except for use on multi-part parameters
(e.g. This method must only be called when parsing into classes of type Collection or array.
T
- The class type to convert the parameter value to.name
- The query parameter name.type
- The type of object to create.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
args
- The type arguments of the class if it's a collection or map.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
BadRequest
- Thrown if input could not be parsed.InternalServerError
- Thrown if any other exception occurs.public <T> T getAll(HttpPartParserSession parser, HttpPartSchema schema, String name, Type type, Type... args) throws BadRequest, InternalServerError
getAll(String, Type, Type...)
but allows you to override the part parser.T
- The class type to convert the parameter value to.parser
- The parser to use for parsing the string value.
schema
- The schema object that defines the format of the input.
HttpPartSchema.DEFAULT
.
OpenApiParser
).name
- The query parameter name.type
- The type of object to create.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
args
- The type arguments of the class if it's a collection or map.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
BadRequest
- Thrown if input could not be parsed or fails schema validation.InternalServerError
- Thrown if any other exception occurs.public boolean containsAnyKeys(String... params)
params
- The list of parameters to check for.public SearchArgs getSearchArgs()
SearchArgs
object.
The query arguments are as follows:
SearchArgs
object initialized with the special search query arguments.
public boolean hasAny(String... paramNames)
paramNames
- The parameter names to check for.public String toString(boolean sorted)
sorted
- Sort the query parameters by name.public String asQueryString()
Returned query string does not start with
Copyright © 2016–2020 The Apache Software Foundation. All rights reserved.