From c8b415bebd4bae0aa0d0c25c596a4872c49ef814 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Tue, 6 Nov 2018 13:24:33 +0000 Subject: [PATCH] handled GisResolver errors git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@173981 82a268e6-3cf1-43bd-a215-b396298e98cf --- ...LoadingGeoExplorerApplicationURLCache.java | 2 +- .../LoadingGeonetworkInstanceCache.java | 8 ++- .../resolver/gis/GeonetworkInstance.java | 20 ------- .../resolver/services/GisResolver.java | 57 ++++++++++++------- 4 files changed, 41 insertions(+), 46 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGeoExplorerApplicationURLCache.java b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGeoExplorerApplicationURLCache.java index 87aeda9..ac79256 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGeoExplorerApplicationURLCache.java +++ b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGeoExplorerApplicationURLCache.java @@ -38,7 +38,7 @@ public class LoadingGeoExplorerApplicationURLCache { @Override public String load(String scope) throws Exception { - logger.info(LoadingGeoExplorerApplicationURLCache.class.getSimpleName() +" loaded"); + logger.info("Loading the cache for scope: "+scope); return loadGeoExplorerApplicationURL(scope); } }; diff --git a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGeonetworkInstanceCache.java b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGeonetworkInstanceCache.java index 0b35627..a1a9194 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGeonetworkInstanceCache.java +++ b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGeonetworkInstanceCache.java @@ -39,7 +39,7 @@ public class LoadingGeonetworkInstanceCache { @Override public GeonetworkInstance load(String scope) throws Exception { - logger.info(LoadingGeonetworkInstanceCache.class.getSimpleName() +" loaded"); + logger.info("Loading the cache for scope: "+scope); return loadGeonetworkInstance(scope); } }; @@ -80,8 +80,10 @@ public class LoadingGeonetworkInstanceCache { public static GeonetworkInstance loadGeonetworkInstance(String scope) throws GeonetworkInstanceException { - if (scope == null || scope.isEmpty()) - logger.warn("Scope is null or ermpty, skipping loadGeonetworkInstance"); + if (scope == null || scope.isEmpty()){ + logger.warn("Scope is null or empty, returning GeonetworkInstance as null"); + return null; + } GeonetworkAccessParameter gntwAccess = new GeonetworkAccessParameter(scope); GeonetworkInstance gnInstance = gntwAccess.getGeonetworkInstance(true, GeonetworkLoginLevel.ADMIN); diff --git a/src/main/java/org/gcube/datatransfer/resolver/gis/GeonetworkInstance.java b/src/main/java/org/gcube/datatransfer/resolver/gis/GeonetworkInstance.java index 8c56d34..3e32b91 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/gis/GeonetworkInstance.java +++ b/src/main/java/org/gcube/datatransfer/resolver/gis/GeonetworkInstance.java @@ -48,26 +48,6 @@ public class GeonetworkInstance { this(scope, false, null, null); } -// /** -// * Creates a new configuration for Gis publisher with parameter passed in input. Executes the login on geonetwork instance if authenticate param is true, no otherwise -// * Use scope found in ScopeProvider -// * -// * @param authenticate the authenticate -// * @param level the level -// * @throws Exception the exception -// */ -// public GeonetworkInstance(boolean authenticate, LoginLevel level) throws Exception { -// try { -// this.level = level; -// createInstanceGeonetworkPublisher(authenticate, level); -// } catch (Exception e) { -// logger.error("Sorry, an error occurred in getting geonetwork instance",e); -// throw new Exception("Sorry, an error occurred in getting geonetwork instance",e); -// } -// } - - - /** * Instantiates a new geonetwork instance. * diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GisResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GisResolver.java index fc2c4a4..0680267 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GisResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GisResolver.java @@ -26,6 +26,8 @@ import org.gcube.datatransfer.resolver.services.error.ExceptionManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.cache.CacheLoader.InvalidCacheLoadException; + /** * The Class GisResolver. @@ -108,36 +110,47 @@ public class GisResolver { layerTitle = URLEncoder.encode(gisLayerItem.getCitationTitle(), UTF_8); logger.info("layer Title encoded is: " + layerTitle); - String gisViewerPortletUrl = LoadingGisViewerApplicationURLCache.getCache().get(scope); - //CHECKING IF THE GisViewer Portlet URL is valid - if(gisViewerPortletUrl==null || gisViewerPortletUrl.isEmpty()) - ExceptionManager.throwNotFoundException(req, "GisViewer Portlet URL not found in the scope: "+scope +". Please contact the support", this.getClass(), help); - logger.info("Gis Viewer Application url is: " + gisViewerPortletUrl); - gisViewerPortletUrl+="?rid="+new Random().nextLong() - +"&wmsrequest="+wmsRequest - +"&uuid="+URLEncoder.encode(gisUUID, UTF_8); + try{ + String gisViewerPortletUrl = LoadingGisViewerApplicationURLCache.getCache().get(scope); + //CHECKING IF THE GisViewer Portlet URL is valid + if(gisViewerPortletUrl==null || gisViewerPortletUrl.isEmpty()) + ExceptionManager.throwNotFoundException(req, "GisViewer Portlet URL not found in the scope: "+scope +". Please contact the support", this.getClass(), help); - if(layerTitle!=null) - gisViewerPortletUrl+="&layertitle="+layerTitle; + logger.info("Gis Viewer Application url is: " + gisViewerPortletUrl); + gisViewerPortletUrl+="?rid="+new Random().nextLong() + +"&wmsrequest="+wmsRequest + +"&uuid="+URLEncoder.encode(gisUUID, UTF_8); - logger.info("Redirecting to: "+gisViewerPortletUrl); - return Response.seeOther(new URI(gisViewerPortletUrl)).build(); + if(layerTitle!=null) + gisViewerPortletUrl+="&layertitle="+layerTitle; + + logger.info("Redirecting to: "+gisViewerPortletUrl); + return Response.seeOther(new URI(gisViewerPortletUrl)).build(); + + }catch (InvalidCacheLoadException e) { + logger.error("Error on getting GisViewer Portlet URL for scope: "+scope, e); + ExceptionManager.throwNotFoundException(req, "GisViewer Portlet URL not found in the scope: "+scope +". Please add it or contact the support", this.getClass(), help); + } } if(isGeoExplorerLink){ ScopeProvider.instance.set(scope); + try{ + String geoExplorerPortletUrl = LoadingGeoExplorerApplicationURLCache.getCache().get(scope); + //CHECKING IF THE GeoExplorer Portlet URL is valid + if(geoExplorerPortletUrl==null || geoExplorerPortletUrl.isEmpty()) + ExceptionManager.throwNotFoundException(req, "GeoExplorer Portlet URL not found in the scope: "+scope +". Please contact the support", this.getClass(), help); - String geoExplorerPortletUrl = LoadingGeoExplorerApplicationURLCache.getCache().get(scope); - //CHECKING IF THE GeoExplorer Portlet URL is valid - if(geoExplorerPortletUrl==null || geoExplorerPortletUrl.isEmpty()) - ExceptionManager.throwNotFoundException(req, "GeoExplorer Portlet URL not found in the scope: "+scope +". Please contact the support", this.getClass(), help); - - logger.info("GeoExplorer Application url is: " + geoExplorerPortletUrl); - geoExplorerPortletUrl+="?rid="+new Random().nextLong() - +"&luuid="+URLEncoder.encode(geoExplorerUUID, UTF_8); - //urlRedirect(req, resp, geoExplorerPortletUrl); - return Response.seeOther(new URI(geoExplorerPortletUrl)).build(); + logger.info("GeoExplorer Application url is: " + geoExplorerPortletUrl); + geoExplorerPortletUrl+="?rid="+new Random().nextLong() + +"&luuid="+URLEncoder.encode(geoExplorerUUID, UTF_8); + //urlRedirect(req, resp, geoExplorerPortletUrl); + return Response.seeOther(new URI(geoExplorerPortletUrl)).build(); + }catch (InvalidCacheLoadException e) { + logger.error("Error on getting GeoExplorer Portlet URL for scope: "+scope, e); + ExceptionManager.throwNotFoundException(req, "GeoExplorer Portlet URL not found in the scope: "+scope +". Please add it or contact the support", this.getClass(), help); + } } ExceptionManager.throwBadRequestException(req, GIS_UUID+" or "+GEO_EXPLORER_LAYER_UUID+" not found or empty in the query string", this.getClass(), help);