@Test public void testInvalidIpAddress() { Assert.assertFalse(validator.isValid("192.168.1.500", context)); }
@Override public boolean isValid(String value, ConstraintValidatorContext context) { if (value == null) { return false; } if (!InetAddressValidator.getInstance().isValid(value) && !DomainValidator.getInstance().isValid(value)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(String.format("%s is invalid IP or Domain Address", value)) .addConstraintViolation(); return false; } return true; }
DomainOrIPValidator implements ConstraintValidator<DomainOrIP, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (value == null) { return false; } if (!InetAddressValidator.getInstance().isValid(value) && !DomainValidator.getInstance().isValid(value)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(String.format("%s is invalid IP or Domain Address", value)) .addConstraintViolation(); return false; } return true; } }
DomainOrIPValidator implements ConstraintValidator<DomainOrIP, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (value == null) { return false; } if (!InetAddressValidator.getInstance().isValid(value) && !DomainValidator.getInstance().isValid(value)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(String.format("%s is invalid IP or Domain Address", value)) .addConstraintViolation(); return false; } return true; } @Inject  DomainOrIPValidator(); }
DomainOrIPValidator implements ConstraintValidator<DomainOrIP, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (value == null) { return false; } if (!InetAddressValidator.getInstance().isValid(value) && !DomainValidator.getInstance().isValid(value)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(String.format("%s is invalid IP or Domain Address", value)) .addConstraintViolation(); return false; } return true; } @Inject  DomainOrIPValidator(); @Override void initialize(DomainOrIP constraintAnnotation); @Override boolean isValid(String value, ConstraintValidatorContext context); }
DomainOrIPValidator implements ConstraintValidator<DomainOrIP, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (value == null) { return false; } if (!InetAddressValidator.getInstance().isValid(value) && !DomainValidator.getInstance().isValid(value)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(String.format("%s is invalid IP or Domain Address", value)) .addConstraintViolation(); return false; } return true; } @Inject  DomainOrIPValidator(); @Override void initialize(DomainOrIP constraintAnnotation); @Override boolean isValid(String value, ConstraintValidatorContext context);  }