resourceExists now checks if the URL is reachable and print the error

master
Francesco Mangiacrapa 4 years ago
parent ec8c6182d4
commit b7816983f1

@ -667,8 +667,16 @@ public class DataCatalogueImpl implements DataCatalogue{
checkNotNull(resourceBean);
checkNotNull(apiKey);
checkArgument(!apiKey.isEmpty());
boolean isReachableURL = true;
try {
isReachableURL = CatalogueUtilMethods.resourceExists(resourceBean.getUrl());
} catch (Exception e) {
throw new Exception("It seems the resource at this url " + resourceBean.getUrl()+" is not reachable. Error: "+e.getMessage());
}
if(CatalogueUtilMethods.resourceExists(resourceBean.getUrl())){
if(isReachableURL){
// in order to avoid errors, the username is always converted
String ckanUsername = CatalogueUtilMethods.fromUsernameToCKanUsername(resourceBean.getOwner());
@ -698,6 +706,7 @@ public class DataCatalogueImpl implements DataCatalogue{
}
}else
throw new Exception("It seems there is no resource at this url " + resourceBean.getUrl());
return null;
}

@ -103,8 +103,9 @@ public class CatalogueUtilMethods {
* Utility method to check if a something at this url actually exists
* @param URLName
* @return
* @throws Exception
*/
public static boolean resourceExists(String URLName){
public static boolean resourceExists(String URLName) throws Exception{
if(URLName == null || URLName.isEmpty())
return false;
@ -125,7 +126,7 @@ public class CatalogueUtilMethods {
}
catch (Exception e) {
logger.error("Exception while checking url", e);
return false;
throw new Exception(e);
}
}

Loading…
Cancel
Save