javax.validation.ValidationException#getMessage ( )源码实例Demo

下面列出了javax.validation.ValidationException#getMessage ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: joyrpc   文件: IntfValidator.java
/**
 * 验证服务提供者接口
 *
 * @param config
 * @param clazz
 * @return
 */
protected Pair<String, String> valid(final ProviderConfig config, final Class clazz) {
    Object ref = config.getRef();
    if (ref != null && !clazz.isInstance(ref)) {
        return new Pair<>("interfaceClass", String.format("%s is not an instance of %s", ref.getClass().getName(), clazz.getName()));
    } else if (config.getEnableValidator() == null || !config.getEnableValidator()) {
        return null;
    } else {
        String validatorName = isEmpty(config.getInterfaceValidator()) ?
                Constants.INTERFACE_VALIDATOR_OPTION.get() :
                config.getInterfaceValidator();
        InterfaceValidator validator = INTERFACE_VALIDATOR.get(validatorName);
        if (validator == null) {
            return new Pair<>("interfaceValidator",
                    String.format("No such extension \'%s\' of %s", validatorName, InterfaceValidator.class.getName()));
        } else {
            try {
                validator.validate(clazz);
                return null;
            } catch (ValidationException e) {
                return new Pair<>("interfaceClass", e.getMessage());
            }
        }
    }
}
 
源代码2 项目: onedev   文件: ParamSupply.java
public static void validateParamMatrix(Map<String, ParamSpec> paramSpecMap, Map<String, List<List<String>>> paramMatrix) {
	validateParamNames(paramSpecMap.keySet(), paramMatrix.keySet());
	for (Map.Entry<String, List<List<String>>> entry: paramMatrix.entrySet()) {
		if (entry.getValue() != null) {
			try {
				validateParamValues(entry.getValue());
			} catch (ValidationException e) {
				throw new ValidationException("Error validating values of parameter '" 
						+ entry.getKey() + "': " + e.getMessage());
			}
			
			ParamSpec paramSpec = Preconditions.checkNotNull(paramSpecMap.get(entry.getKey()));
			for (List<String> value: entry.getValue()) 
				validateParamValue(paramSpec, entry.getKey(), value);
		}
	}
}
 
源代码3 项目: onedev   文件: RunJobAction.java
@Override
public void validateWithContext(BuildSpec buildSpec, Job job) {
	super.validateWithContext(buildSpec, job);
	
	Job jobToRun = buildSpec.getJobMap().get(jobName);
	if (jobToRun != null) {
		try {
			ParamSupply.validateParams(jobToRun.getParamSpecs(), jobParams);
		} catch (ValidationException e) {
			throw new ValidationException("Error validating parameters of run job '" 
					+ jobToRun.getName() + "': " + e.getMessage());
		}
	} else {
		throw new ValidationException("Run job not found: " + jobName);
	}
}
 
源代码4 项目: Spring-Boot-Book   文件: GlobalExceptionHandler.java
/**
 * 400 - Bad Request
 */
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(ValidationException.class)
public String handleValidationException(ValidationException e, Model model) {
    logger.error("参数验证失败", e);
    String message = "【参数验证失败】" + e.getMessage();
    model.addAttribute("message", message);
    model.addAttribute("code", 400);
    return viewName;
}
 
源代码5 项目: Spring-Boot-Book   文件: GlobalExceptionHandler.java
/**
 * 400 - Bad Request
 */
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(ValidationException.class)
public String handleValidationException(ValidationException e, Model model) {
    logger.error("参数验证失败", e);
    String message = "【参数验证失败】" + e.getMessage();
    model.addAttribute("message", message);
    model.addAttribute("code", 400);
    return viewName;
}
 
源代码6 项目: spring-boot-shiro   文件: GlobalExceptionHand.java
/**
 * 400 - Bad Request
 */
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(ValidationException.class)
public Response handleValidationException(ValidationException e) {
    String msg = e.getMessage();
    log.error("参数验证失败:", e);
    return new Response().failure(msg);
}
 
源代码7 项目: SENS   文件: GlobalExceptionHandler.java
/**
 * 400 - Bad Request
 */
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(ValidationException.class)
public String handleValidationException(ValidationException e, Model model) {
    log.error("参数验证失败", e);
    String message = "【参数验证失败】" + e.getMessage();
    model.addAttribute("message", message);
    model.addAttribute("code", 400);
    return viewName;
}
 
源代码8 项目: onedev   文件: CreateIssueAction.java
@Override
public void validateWithContext(BuildSpec buildSpec, Job job) {
	super.validateWithContext(buildSpec, job);
	
	GlobalIssueSetting issueSetting = OneDev.getInstance(SettingManager.class).getIssueSetting();
	try {
		FieldSupply.validateFields(issueSetting.getFieldSpecMap(getFieldNames()), issueFields);
	} catch (ValidationException e) {
		throw new ValidationException("Error validating issue fields: " + e.getMessage());
	}
	
}
 
源代码9 项目: jweb-cms   文件: ValidationWebExceptionMapper.java
@Override
public Response toResponse(ValidationException exception) {
    ValidationWebExceptionResponse response = new ValidationWebExceptionResponse();
    if (exception instanceof ConstraintViolationException) {
        ConstraintViolation<?> violation = ((ConstraintViolationException) exception).getConstraintViolations().iterator().next();
        response.field = violation.getPropertyPath().toString();
        response.errorMessage = violation.getMessage();
    } else {
        response.errorMessage = exception.getMessage();
    }
    return Response.status(400).entity(response)
        .type(MediaType.APPLICATION_JSON).build();
}
 
源代码10 项目: jweb-cms   文件: ValidationExceptionMapper.java
@Override
public Response toResponse(ValidationException exception) {
    ValidationExceptionResponse response = new ValidationExceptionResponse();
    if (exception instanceof ConstraintViolationException) {
        ConstraintViolation<?> violation = ((ConstraintViolationException) exception).getConstraintViolations().iterator().next();
        response.path = violation.getPropertyPath().toString();
        response.errorMessage = violation.getMessage();
    } else {
        response.errorMessage = exception.getMessage();
    }
    return Response.status(400).entity(response)
        .type(MediaType.APPLICATION_JSON).build();
}
 
源代码11 项目: frpMgr   文件: CasAuthorizingRealm.java
@Override
protected User getUserInfo(FormToken token) {
	
	User user = super.getUserInfo(token);
	if (user == null){
		Map<String, Object> attrs = token.getParams();
		
		// 如果允许客户端创建账号,则创建账号
		if (ObjectUtils.toBoolean(attrs.get("isAllowClientCreateUser"))){

			// 获取CAS传递过来的用户属性信息
			user = new User(EncodeUtils.decodeUrl(ObjectUtils.toString(attrs.get("userCode"))));
			user.setLoginCode(EncodeUtils.decodeUrl(ObjectUtils.toString(attrs.get("loginCode"))));
			user.setPassword(EncodeUtils.decodeUrl(ObjectUtils.toString(attrs.get("password"))));
			user.setUserName(EncodeUtils.decodeUrl(ObjectUtils.toString(attrs.get("userName"))));
			user.setEmail(EncodeUtils.decodeUrl(ObjectUtils.toString(attrs.get("email"))));
			user.setMobile(EncodeUtils.decodeUrl(ObjectUtils.toString(attrs.get("mobile"))));
			user.setPhone(EncodeUtils.decodeUrl(ObjectUtils.toString(attrs.get("phone"))));
			user.setUserType(EncodeUtils.decodeUrl(ObjectUtils.toString(attrs.get("userType"))));
			user.setRefCode(EncodeUtils.decodeUrl(ObjectUtils.toString(attrs.get("refCode"))));
			user.setRefName(EncodeUtils.decodeUrl(ObjectUtils.toString(attrs.get("refName"))));
			user.setMgrType(EncodeUtils.decodeUrl(ObjectUtils.toString(attrs.get("mgrType"))));
			user.setStatus(EncodeUtils.decodeUrl(ObjectUtils.toString(attrs.get("status"))));
			
			// 如果是员工类型,则平台自动创建
			if (User.USER_TYPE_EMPLOYEE.equals(user.getUserType())){
				
				// 保存员工和用户
				try{
					EmpUser empUser = new EmpUser();
					empUser.setIsNewRecord(true);
					empUser.setMobile(user.getMobile());
					empUser.setEmail(user.getEmail());
					empUser.setPhone(user.getPhone());
					empUser.getEmployee().getCompany().setCompanyCode(EncodeUtils
							.decodeUrl(ObjectUtils.toString(attrs.get("companyCode"))));
					empUser.getEmployee().getOffice().setOfficeCode(EncodeUtils
							.decodeUrl(ObjectUtils.toString(attrs.get("officeCode"))));
					getEmpUserService().save(empUser);
				}catch(ValidationException ve){
					throw new AuthenticationException("msg:" + ve.getMessage());
				}
				
				// 重新获取用户登录
				user = UserUtils.getByLoginCode(token.getUsername()/*, corpCode*/);
				if (user != null) {
					return user;
				}
				
			}
			
			// 其它类型,根据项目需要自行创建
			else{
				try{
					CasCreateUser casCreateUser = SpringUtils.getBean(CasCreateUser.class);
					if(casCreateUser != null){
						casCreateUser.createUser(user, attrs);
					}
				}catch(NoSuchBeanDefinitionException e){
					throw new AuthenticationException("msg:用户 “" + token.getUsername()
							+ "”, 类型 “" + user.getUserType() + "” 在本系统中不存在, 请联系管理员.");
				}
			}
		}else{
			throw new AuthenticationException("msg:用户 “" + token.getUsername() + "” 在本系统中不存在, 请联系管理员.");
		}
	}
	return user;
}
 
 同类方法