String url = getUrl();
try{
Connection con = getConnection(url, username, pwd);
}catch(ConnectionException e){
cleanUpUrl(url);
url = getUrl();
con = getConnection(url, username, pwd);
}
I've to do something like above. if I don't get Connection with one URL then I'll be trying with another URL. Likewise there are 10URLs which I've to try one after the other.
How will I write the method recursively?
getUrl()
has the logic to read the properties file and gives you random URL out of 10.
cleanUpUrl(url)
has something to do with the setting the expiry time of the URL, if the url is invalid, some property will be set etc etc.
EDIT: Sorry I think I missed something. Recursive because I've do make the method calls until (I get the connection) or (all the URLs are invalid and a different exception is thrown). Looping 10times might not help because the getUrl()'s random logic might pick the same URL more than once.
Does the following makes sense?
Connection con = null;
do{
String url = getUrl();
try{
Connection con = getConnection(url, username, pwd);
}catch(ConnectionException e){
cleanUpUrl(url);
continue;
}catch(Exception e){
return null;
}
}while(con !=null);
getUrl() will throw exception when all urls are invalid.