It not only verifies the format but that the URL is actually valid.
The problem is I don't want to add this associated jar file to my project.
Java has some other implementations but it appears to only verify the syntax and i would probably have to make a number of other calls to actually verify the URL works.
I am looking for a single call (or maybe two) in which to verify the URL is valid and actually works AND uses the standard java objects.
Why does it have to be one or two calls? If it were more complicated than that, you could put the code in a method and then simply call that method whenever you want to validate a URL.
Paul Clapham wrote:You need to provide your definition of "valid". From the code fragment you have there, it seems to involve actually connecting to the URL. That's different from most ordinary definitions of "valid", which tend to only concern themselves with whether the URL is well-formed. Seeing if you can connect to the URL opens up a big can of worms. Like: what if the URL requires authentication? How long do you want to wait if there's no response before timing out, and then what? How many minutes (hours, days) do you want to retry over until you're convinced that the URL's host is not just down for maintenance or something?
Not sure exactly what is being done behind the scenes but the original object (UrlValidator ) did some sort of validation.
It appears to attempt to connect.
Only attempted it against non-verification type pages so your point about what if the URL prompts for username/pwd would it hang or something.
May just still with format of the URL simply being well formed.