UrlValidator extends Validator<String> { @Override public boolean execute(String content) { if (StringUtils.isBlank(content)) { return false; } String[] schemes = {"http", "https"}; org.apache.commons.validator.UrlValidator urlValidator = new org.apache.commons.validator.UrlValidator(schemes, org.apache.commons.validator.UrlValidator.ALLOW_2_SLASHES); if (content.startsWith("http")) { return urlValidator.isValid(content); } return execute("http: }  @Override boolean execute(String content);  }
@Test public void testExecute() throws Exception { UrlValidator validator = new UrlValidator(); assertEquals(false, validator.execute("")); assertEquals(false, validator.execute(" ")); assertEquals(false, validator.execute(null)); assertEquals(true, validator.execute("http: assertEquals(true, validator.execute("https: assertEquals(true, validator.execute("/to/page.cfm?a=1&b=2#bar")); assertEquals(true, validator.execute("/to/page.cfm?a=%00%foo&b=2#bar")); assertEquals(false, validator.execute("/to/page.cfm?a=ü&b=2#bar")); assertEquals(false, validator.execute("https: assertEquals(false, validator.execute("https: }