For each request, a list of request parameters are supported
by default. For more details on supported parameters see
Introducing JViews Web
application exchange protocols and securities. Under some circumstances,
you might need to customize the request parameters: for example, to
add or to remove some parameters for a specific request in the application.
You can perform such customization by using a request parameter handler.
The following example shows how to add a customized request parameter
called
testParameter
for an
image
request
by overriding the
getServletParametersHandler method in the parent class.
public class MyServletParamValidationListener extends
IlvManagerServletParameterValidationListener {
...
public IlvServletParameterHandler getServletParametersHandler(
ServletRequest request) {
String type = request.getParameter("request");
IlvServletParameterHandler handler = null;
// if you want to add more customized parameters for specific
// request types such as "image"
if ("image".equals(type)) {
// get the default parameter handler for the image request
// by using the factory class.
handler = IlvManagerServletParameterHandlerFactory.getInstance()
.getServletParametersHandler(request);
// add a non-mandatory testing paramter called "testParameter"
// and an expected value of "expectedValue" under the specific
// comparator "List"
handler.addParameter("testParameter", false, "expectedValue",
true,IlvRequestParameter.Comparator.LIST);
} else {
handler = super.getServletParametersHandler(request);
}
return handler;
}
}
For the image
request, you
must get the default parameter handler by using parameter handler
factory class, then you must add a non-mandatory testing parameter
called testParameter
and the expected value
called expectedValue
under the specific
comparator List
. This comparator will compare
the list of expected values with the requested parameter for validation.
For each request, the parameter handler is provided by
default, which support parameters operations such as adding or removing
some parameters. For more details on supported operations, see
IlvServletParameterHandler. To customize your request parameter,
you must first get the default parameter handler. You can use the
parameter handler factory classes to get the specific parameter handler
for your specific request.
To get the default parameter handler:
To specify the comparator:
You can also specify how to compare the parameter value
by setting a specific comparator to
true
.
The default comparator is
EQUALS
which
means that the requested parameter value should be equal to expected
value. Here is a list of supported comparators and sample code fragments
to show you how to use them. For more details on supported comparators
see
IlvRequestParameter.
Name |
Description |
Example code |
EQUALS |
The parameter value is equal to the expected value. |
addParameter("format", true, "json", true,
IlvRequestParameter.Comparator.EQUALS); |
CONTAINS |
The parameter value contains the expected value. |
addParameter("res", false, "data", true, IlvRequestParameter.Comparator.CONTAINS); |
NOT_CONTAINS |
The parameter value does not contain the expected value. |
addParameter("image", false, "script", true,
IlvRequestParameter.Comparator.NOT_CONTAINS); |
STARTS_WITH |
The parameter value starts with one of the listed expected
values, the value is separated by a semicolon in the string. |
addParameter("res", true, "ilog", true, IlvRequestParameter.Comparator.STARTS_WITH); |
ENDS_WITH |
The parameter value ends with one of the listed expected
values, the value is separated by semicolon in the string. |
addParameter("res", true, ".gif;.jpg;.jpeg;.png;.js;.css",
true, IlvRequestParameter.Comparator.ENDS_WITH); |
LIST |
The parameter value is one in the list of expected values,
the value is separated by semicolon in the string. |
addParameter("format", true, "JPEG;PNG;GIF;JPG",
true, IlvRequestParameter.Comparator.LIST); |