Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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: 16083
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: 23506
47
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.
 
Seriously Rick? Seriously? You might as well just read this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!