Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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: 23640
48
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!