• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Looking for a different method to validate a URL.  RSS feed

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following code works great.
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.

Any ideas?

 
Java Cowboy
Sheriff
Posts: 16084
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where exactly does UrlValidator come from and what exactly does it do? If you don't explain us these things, it's very hard to explain you how to do the same thing with the standard Java classes.

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.
 
Sheriff
Posts: 23714
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Tom Landry
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!