String[] schemes = {"http","https"};
UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_ALL_SCHEMES);
System.out.println(urlValidator.isValid(myUrl));
the following URL says, invalid. Any one know why is that. the localnet is a localnetwork. But this works for any other public network (it seems).
http://aunt.localnet/songs/barnbeat.ogg
The class you're using is deprecated. The replacement is
org.apache.commons.validator.routines.UrlValidator
Which is more flexible. You can pass the flag ALLOW_LOCAL_URLS to the constructor which would allow most addresses like the one you are using. In our case, we had authentication data preceeding the address, so we had to use the even-more-flexible UrlValidator(RegexValidator authorityValidator, long options) constructor.
As I thought, its failing on the top level;
String topLevel = domainSegment[segmentCount - 1];
if (topLevel.length() < 2 || topLevel.length() > 4) {
return false;
}
your top level is localnet
.
This is fixed in the 1.4.1 release of the Apache Validator:
https://issues.apache.org/jira/browse/VALIDATOR-342 https://issues.apache.org/jira/browse/VALIDATOR/fixforversion/12320156
A simple upgrade to the latest version of the validator should fix things nicely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With