Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Validates a floating point value and checks if it is in the specified range. The validator requires minimum and the maximum values of the range to be validated. For example,

Length Validator

Validates the string length of a given parameter. The length should be given for validation. For example,

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; else it fails. The validator requires the regular expression to be passed in for validation.

Custom Validators

...

The WSO2 Data Services Server allows the user to instroduce custom validation logic by adding Custom Validators. To define a custom validator, the user must implement the interface "org.wso2.carbon.dataservices.core.validation.Validator".

The definition of the interface is as follows:

Code Block

public interface Validator {
    public void validate(ValidationContext context, String name, ParamValue value) throws ValidationException;
}

When defining a custom validator, this interface should be implemented. The validate method in the interface is defined to throw an exception of type ValidationException if the validation fails. If the validation is successful, nothing happens.

  • context : This parameter is of type "ValidationContext", which contains information about the full set of parameters passed into the request. When the validation logic depends on other parameters, the validation context can be used to check the names/values of the rest of the parameters.
  • name : This is a string value which represents the name of the parameter to be validated.
  • value : This parameter is of type "ParamType", which represents the value of the parameter to be validated. This can be either a SCALAR or an ARRAY.

After a custom validator class is created, it must be packaged in a jar archive file and put in the server's classpath location for external libraries which is DSS_HOME/repository/component/lib.