[Download] | [Documentation Home] | [Release Note]
Input validation allows data services to validate the input parameter values that are presented in a request. This allows to stops the execution of the request, if the input has not met the required criteria. WSO2 Data Services Server provides a set of built-in validators which will be sufficient for the mostly used use cases. And also it provides an extension mechanism, where custom validators can be written.
The validators can be set at the "Edit Input Mapping" page for each individual input mappings, which is at "Edit Query" -> "Input Mappings" -> "Edit".
The following sections explains the pre-defined standard validators that are available, the validators have to be added to individual input mappings in a query.
This validator validates an integer value, to check if it is in the specified range. The validator requires the minimum and the maximum value of the range to be validated. Figure 1 shows the addition of a Long Range Validator.
Figure 1: Adding a Long Range Validator.
This validator validates an floating point value, to check if it is in the specified range. The validator requires the minimum and the maximum value of the range to be validated. Figure 2 shows the addition of a Double Range Validator.
Figure 2: Adding a Double Range Validator.
This validator validates the string length of the given parameter. The validator requires the length to be passed in for validation. Figure 3 shows the step in adding a Length Validator.
Figure 3: Adding a Length Validator.
The pattern validator validates the string value of the parameter against a given regular expression. If the regular expression matches the target parameter, the validator succeeds, or else fails. The validator requires the regular expression to be passed in for validation. Figure 4 shows the step used in adding a Pattern Validator.
Figure 4: Adding a Pattern Validator.
Validators feature in WSO2 Data Services Server allows the user to instroduce custom validation logic by adding Custom Validators. For defining a custom validator, the user must implement the interface "org.wso2.carbon.dataservices.core.validation.Validator". Below contains the definition of the interface.
public interface Validator { public void validate(ValidationContext context, String name, ParamValue value) throws ValidationException; }
For a demonstration of the usage of validators, refer to the validators demo in the samples.