Exemple #1
0
  private void fillValidatorMetadata(ApiAction action, Method method) throws ApiException {
    RequestValidator requestValidatorAnnotation = method.getAnnotation(RequestValidator.class);
    if (requestValidatorAnnotation != null) {
      final Class<? extends ParamsValidator>[] validatorClasses =
          requestValidatorAnnotation.value();
      if (validatorClasses.length == 0) {
        throw new ApiException("Validator is not specified for " + action);
      }

      addValidators(action, requestValidatorAnnotation, validatorClasses);
    }

    RequestParamsValidator paramsValidatorAnnotation =
        method.getAnnotation(RequestParamsValidator.class);
    if (paramsValidatorAnnotation != null) {
      final String[] required = paramsValidatorAnnotation.required();
      action.addRequestValidator(new SimpleRequestParamsValidator(required));
    }
  }
Exemple #2
0
  private void addValidators(
      ApiAction action,
      RequestValidator requestValidatorAnnotation,
      Class<? extends ParamsValidator>[] validatorTypes)
      throws ApiException {
    final String[] customParams = requestValidatorAnnotation.params();
    for (Class<? extends ParamsValidator> each : validatorTypes) {
      final ParamsValidator validator = getParamsValidator(each, customParams);

      if (validator != null) {
        action.addRequestValidator(validator);
      }
    }
  }