Groovy Help - Validate URL
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2008
06:13 PM
05-21-2008
06:13 PM
Groovy Help - Validate URL
hello,
One of my services has a a list or URLs in the response. These URL point to images located on some server.
I want to validate that these URLs are valid and that there is actually an image located at this URL.
Can you help me with some groovy code that some validates that these are valid URL.
thanks
Ali
One of my services has a a list or URLs in the response. These URL point to images located on some server.
I want to validate that these URLs are valid and that there is actually an image located at this URL.
Can you help me with some groovy code that some validates that these are valid URL.
thanks
Ali
4 REPLIES 4
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2008
04:02 PM
05-22-2008
04:02 PM
Hi Ali,
hmm.. maybe you could try
if you get an exception, that (probably) means that the URL is not available..
let me know if this works ok!?
regards,
/Ole
eviware.com
hmm.. maybe you could try
try
{
def in = new java.net.URL( urlToImage ).openStream()
in.close()
}
catch( Exception e )
{
// not available!?
}
if you get an exception, that (probably) means that the URL is not available..
let me know if this works ok!?
regards,
/Ole
eviware.com
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2008
04:53 PM
05-22-2008
04:53 PM
it works just had to change the code to
def foo = new java.net.URL( urlToImage ).openStream()
I guess 'in' is some reserved word.
Thanks for you help
Ali
def foo = new java.net.URL( urlToImage ).openStream()
I guess 'in' is some reserved word.
Thanks for you help
Ali
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2008
04:59 PM
05-22-2008
04:59 PM
I had a follow up question on this actually.
so my response looks something like this
....
would it be possible to use groovy utils or something else so that I can stores all the URL into some list and then iterate through the list to verify that each of the URL is valid.
Thanks in advance.
Ali
so my response looks something like this
....
would it be possible to use groovy utils or something else so that I can stores all the URL into some list and then iterate through the list to verify that each of the URL is valid.
Thanks in advance.
Ali
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2008
12:50 AM
05-23-2008
12:50 AM
Hi Ali,
you can use the XmlHolder.getNodeValues( xpath ) method which will return an array of all values matching the xpath. Then use standard groovy iteration of this array for your validations..
regards!
/Ole
eviware.com
you can use the XmlHolder.getNodeValues( xpath ) method which will return an array of all values matching the xpath. Then use standard groovy iteration of this array for your validations..
regards!
/Ole
eviware.com
