当前位置: 首页>>代码示例>>Java>>正文


Java ExecutableValidator.validateParameters方法代码示例

本文整理汇总了Java中javax.validation.executable.ExecutableValidator.validateParameters方法的典型用法代码示例。如果您正苦于以下问题:Java ExecutableValidator.validateParameters方法的具体用法?Java ExecutableValidator.validateParameters怎么用?Java ExecutableValidator.validateParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.validation.executable.ExecutableValidator的用法示例。


在下文中一共展示了ExecutableValidator.validateParameters方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import javax.validation.executable.ExecutableValidator; //导入方法依赖的package包/类
public static void main(String[] args) throws NoSuchMethodException, SecurityException {
	AutoRunHelper.run(App.class);
	
	// 测试参数校验
	App app = new App();
	
	ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
	ExecutableValidator executableValidator = factory.getValidator().forExecutables();
	Method method = App.class.getMethod("showEmail", String.class);
	
	Object[] parameterValues = {"email"};
	Set<ConstraintViolation<App>> violations = executableValidator.validateParameters(app, method, parameterValues);
	String message = violations.iterator().hasNext() ? violations.iterator().next().getMessage() : "";
	System.out.println("values:" + parameterValues[0].toString() + " size: " + violations.size() + " msg:" + message);
	
	Object[] parameterValues2 = {"abc"};
	violations = executableValidator.validateParameters(app, method, parameterValues2);
	message = violations.iterator().hasNext() ? violations.iterator().next().getMessage() : "";
	System.out.println("values:" + parameterValues2[0].toString() + " size: " + violations.size() + " msg:" + message);

}
 
开发者ID:zhoukekestar,项目名称:java-notes,代码行数:22,代码来源:App.java

示例2: verifyMethod

import javax.validation.executable.ExecutableValidator; //导入方法依赖的package包/类
/**
 * Validate the method parameters based on javax.validation: Hibernate Validator.
 *
 * @param proxy  The checked target object.
 * @param method The checked target method.
 * @param args   The checked target method's parameters.
 * @param <T>    The target object type: Generic types.
 */
public <T> void verifyMethod(
        final T proxy,
        final Method method,
        final Object[] args) {
    // 1. Get method validator
    final ExecutableValidator validatorParam
            = VALIDATOR.forExecutables();
    // 2. Create new params that wait for validation
    final Set<ConstraintViolation<T>> constraints
            = validatorParam.validateParameters(proxy, method, args);
    // 3. Throw out exception
    if (!constraints.isEmpty()) {
        final ConstraintViolation<T> item = constraints.iterator().next();
        if (null != item) {
            final WebException error
                    = new _400ValidationException(getClass(),
                    proxy.getClass(), method, item.getMessage());
            error.setReadible(item.getMessage());
            throw error;
        }
    }
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:31,代码来源:Validator.java

示例3: testMethodParameters

import javax.validation.executable.ExecutableValidator; //导入方法依赖的package包/类
@Test
public void testMethodParameters() throws NoSuchMethodException {
    ExecutableValidator executableValidator = validator.forExecutables();
    Method method = RentalStation.class.getMethod("rentCar", String.class, Date.class,
            Integer.TYPE);
    RentalStation station = new RentalStation("hertz", "");
    Set<ConstraintViolation<RentalStation>> violations = executableValidator.validateParameters(
            station, method, new Object[]{"Clement", new Date(System.currentTimeMillis() + 10000), 1});
    assertThat(violations.size()).isEqualTo(0);
    violations = executableValidator.validateParameters(
            station, method, new Object[]{"Clement", new Date(System.currentTimeMillis() - 10000), 1});
    assertThat(violations.size()).isEqualTo(1);
    violations = executableValidator.validateParameters(
            station, method, new Object[]{"Clement", new Date(System.currentTimeMillis() - 10000), 0});
    assertThat(violations.size()).isEqualTo(2);
    violations = executableValidator.validateParameters(
            station, method, new Object[]{null, new Date(System.currentTimeMillis() - 10000), 0});
    assertThat(violations.size()).isEqualTo(3);
}
 
开发者ID:wisdom-framework,项目名称:wisdom,代码行数:20,代码来源:ValidationTest.java

示例4: handleMessage

import javax.validation.executable.ExecutableValidator; //导入方法依赖的package包/类
@Override
public void handleMessage(Message message) {
    final List<Object> arguments = MessageContentsList.getContentsList(message);
    if (!arguments.isEmpty()) {
        final Object instance = message.getExchange().get(Message.SERVICE_OBJECT);
        final Method method = (Method) message.get(METHOD_KEY);
        final ExecutableValidator methodValidator = validator.forExecutables();
        final Class<?>[] groups = Optional.ofNullable(method.getAnnotation(Groups.class)).map(Groups::value).orElse(DEFAULT_GROUPS);
        final Set<ConstraintViolation<Object>> violations = methodValidator.validateParameters(instance, method, arguments.toArray(), groups);
        if (!violations.isEmpty()) {
            message.put(FaultListener.class.getName(), new NoOpFaultListener());
            throw new JaxrsServerValidationException(violations);
        }
    }
}
 
开发者ID:Microbule,项目名称:microbule,代码行数:16,代码来源:ValidationInterceptor.java

示例5: validateMethodParameters

import javax.validation.executable.ExecutableValidator; //导入方法依赖的package包/类
protected void validateMethodParameters(ProceedingJoinPoint ctx,
                                        @Nullable ValidateServiceMethodContext validatedContext) {
    if (validatedContext != null) {
        log.trace("Validating service call params: {}", ctx.getSignature());

        ExecutableValidator validator = validatedContext.getValidator();

        Class[] constraintGroups = validatedContext.getGroups();
        if (constraintGroups.length == 0) {
            constraintGroups = new Class[]{Default.class, ServiceParametersChecks.class};
        }

        Set<ConstraintViolation<Object>> violations = validator.validateParameters(
                validatedContext.getTarget(),
                validatedContext.getMethod(),
                validatedContext.getArgs(),
                constraintGroups);

        if (!violations.isEmpty()) {
            Class serviceInterface = ctx.getSignature().getDeclaringType();
            Set<ConstraintViolation<Object>> resultViolations = violations.stream()
                    .map(violation -> new ServiceMethodConstraintViolation(serviceInterface, violation))
                    .collect(Collectors.toSet());

            throw new MethodParametersValidationException("Service method parameters validation failed", resultViolations);
        }
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:29,代码来源:ServiceInterceptor.java

示例6: validate

import javax.validation.executable.ExecutableValidator; //导入方法依赖的package包/类
public <T> void validate(final Method method, final Object[] arguments, final T instance) {
    if (validator == null) {
        log.warn("Bean Validation provider could not be found, no validation will be performed");
        return;
    }

    ExecutableValidator methodValidator = validator.forExecutables();
    Set<ConstraintViolation<T>> violations = methodValidator.validateParameters(instance,
            method, arguments);

    if (!violations.isEmpty()) {
        throw new ConstraintViolationException(violations);
    }
}
 
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:15,代码来源:ValidationInterceptor.java

示例7: validate

import javax.validation.executable.ExecutableValidator; //导入方法依赖的package包/类
private void validate(Object target, Method method, Object[] args) {
  ExecutableValidator executableValidator = VALIDATOR.forExecutables();
  Set<ConstraintViolation<Object>> violations = executableValidator.validateParameters(target, method, args);
  if (violations.isEmpty()) {
    return;
  }

  throw new ParameterValidationException(violations);
}
 
开发者ID:orctom,项目名称:laputa,代码行数:10,代码来源:DefaultRequestProcessor.java

示例8: validateParameters

import javax.validation.executable.ExecutableValidator; //导入方法依赖的package包/类
@Override
public void validateParameters(final Object instanceOrClass, final Method method, final Object[] parameters) {
    if (instanceOrClass == null) { // bval 11 doesnt support it
        return;
    }
    final ExecutableValidator executableValidator = validatorFactory.getValidator().forExecutables();
    final Set<ConstraintViolation<Object>> violations = executableValidator.validateParameters(instanceOrClass, method, parameters);
    if (!violations.isEmpty()) {
        throw new ConstraintViolationException(violations);
    }
}
 
开发者ID:tomitribe,项目名称:crest,代码行数:12,代码来源:BeanValidation11.java


注:本文中的javax.validation.executable.ExecutableValidator.validateParameters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。