public class FormEncodedParser extends java.lang.Object implements RequestParser
HttpServletRequest
.
By default, this RequestParser
overwrite parameter occurrences in
the map: that's to say if a parameter is provided several times, only the
last value will be kept. This behavior can be changed by overwriting the
function consumeParameter(String, Object, Map)
of this class.
Note:
When HTTP-POST is used, these parameters are actually already extracted by
the server application (like Apache/Tomcat) and are available with
ServletRequest.getParameterMap()
. However, when using HTTP-PUT,
the parameters are extracted manually from the request content.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
EXPECTED_CONTENT_TYPE
HTTP content-type for HTTP request formated in url-form-encoded.
|
Constructor and Description |
---|
FormEncodedParser() |
Modifier and Type | Method and Description |
---|---|
protected void |
consumeParameter(java.lang.String name,
java.lang.Object value,
java.util.Map<java.lang.String,java.lang.Object> allParams)
Consume the specified parameter: add it inside the given map.
|
static boolean |
isFormEncodedRequest(javax.servlet.http.HttpServletRequest request)
Utility method that determines whether the content of the given request is a application/x-www-form-urlencoded.
|
java.util.Map<java.lang.String,java.lang.Object> |
parse(javax.servlet.http.HttpServletRequest request)
Extract parameters from the given HTTP request.
|
public static final java.lang.String EXPECTED_CONTENT_TYPE
public final java.util.Map<java.lang.String,java.lang.Object> parse(javax.servlet.http.HttpServletRequest request) throws UWSException
RequestParser
Extract parameters from the given HTTP request.
These parameters can be fetched from ServletRequest.getParameterMap()
or directly from the full request content. In this last case, a parsing is necessary ;
hence this function.
In case a parameter is provided several times with the same time and the same case,
the request parser can choose to keep only the last occurrence or all occurrences.
If all occurrences are kept, this function MUST return an array of Object
s
(in which types may be mixed), otherwise a map value MUST be an elementary object.
Note: A parameter item can be a simple value (e.g. String, integer, ...) or a more complex object (e.g. File, InputStream, ...).
IMPORTANT:
This function MUST NOT be used to check the parameters' value.
It only aims to parse the given request in order to extract its embedded parameters.
Consequently, if this function throws an exception, it could be only because the request
can not be read, and not because a parameter format or value is incorrect.
Parameter checks should be done in UWSParameters
and more particularly by
an InputParamController
.
parse
in interface RequestParser
request
- An HTTP request.Object
s (in which types can be mixed).UWSException
- If any error provides this function to read the parameters.protected void consumeParameter(java.lang.String name, java.lang.Object value, java.util.Map<java.lang.String,java.lang.Object> allParams)
Consume the specified parameter: add it inside the given map.
By default, this function is just putting the given value inside the map. So, if the parameter already exists in the map, its old value will be overwritten by the given one.
name
- Name of the parameter to consume.value
- Its value.allParams
- The list of all parameters read until now.public static final boolean isFormEncodedRequest(javax.servlet.http.HttpServletRequest request)
Utility method that determines whether the content of the given request is a application/x-www-form-urlencoded.
Important: This function just test the content-type of the request. The HTTP method (e.g. GET, POST, ...) is not tested.
request
- The servlet request to be evaluated. Must be non-null.