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
This commit is contained in:
Francesco Mangiacrapa 2018-11-06 13:24:33 +00:00
parent ff223b3b16
commit c8b415bebd
4 changed files with 41 additions and 46 deletions

View File

@ -38,7 +38,7 @@ public class LoadingGeoExplorerApplicationURLCache {
@Override @Override
public String load(String scope) public String load(String scope)
throws Exception { throws Exception {
logger.info(LoadingGeoExplorerApplicationURLCache.class.getSimpleName() +" loaded"); logger.info("Loading the cache for scope: "+scope);
return loadGeoExplorerApplicationURL(scope); return loadGeoExplorerApplicationURL(scope);
} }
}; };

View File

@ -39,7 +39,7 @@ public class LoadingGeonetworkInstanceCache {
@Override @Override
public GeonetworkInstance load(String scope) public GeonetworkInstance load(String scope)
throws Exception { throws Exception {
logger.info(LoadingGeonetworkInstanceCache.class.getSimpleName() +" loaded"); logger.info("Loading the cache for scope: "+scope);
return loadGeonetworkInstance(scope); return loadGeonetworkInstance(scope);
} }
}; };
@ -80,8 +80,10 @@ public class LoadingGeonetworkInstanceCache {
public static GeonetworkInstance loadGeonetworkInstance(String scope) public static GeonetworkInstance loadGeonetworkInstance(String scope)
throws GeonetworkInstanceException { throws GeonetworkInstanceException {
if (scope == null || scope.isEmpty()) if (scope == null || scope.isEmpty()){
logger.warn("Scope is null or ermpty, skipping loadGeonetworkInstance"); logger.warn("Scope is null or empty, returning GeonetworkInstance as null");
return null;
}
GeonetworkAccessParameter gntwAccess = new GeonetworkAccessParameter(scope); GeonetworkAccessParameter gntwAccess = new GeonetworkAccessParameter(scope);
GeonetworkInstance gnInstance = gntwAccess.getGeonetworkInstance(true, GeonetworkLoginLevel.ADMIN); GeonetworkInstance gnInstance = gntwAccess.getGeonetworkInstance(true, GeonetworkLoginLevel.ADMIN);

View File

@ -48,26 +48,6 @@ public class GeonetworkInstance {
this(scope, false, null, null); 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. * Instantiates a new geonetwork instance.
* *

View File

@ -26,6 +26,8 @@ import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
/** /**
* The Class GisResolver. * The Class GisResolver.
@ -108,36 +110,47 @@ public class GisResolver {
layerTitle = URLEncoder.encode(gisLayerItem.getCitationTitle(), UTF_8); layerTitle = URLEncoder.encode(gisLayerItem.getCitationTitle(), UTF_8);
logger.info("layer Title encoded is: " + layerTitle); 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); try{
gisViewerPortletUrl+="?rid="+new Random().nextLong() String gisViewerPortletUrl = LoadingGisViewerApplicationURLCache.getCache().get(scope);
+"&wmsrequest="+wmsRequest //CHECKING IF THE GisViewer Portlet URL is valid
+"&uuid="+URLEncoder.encode(gisUUID, UTF_8); 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) logger.info("Gis Viewer Application url is: " + gisViewerPortletUrl);
gisViewerPortletUrl+="&layertitle="+layerTitle; gisViewerPortletUrl+="?rid="+new Random().nextLong()
+"&wmsrequest="+wmsRequest
+"&uuid="+URLEncoder.encode(gisUUID, UTF_8);
logger.info("Redirecting to: "+gisViewerPortletUrl); if(layerTitle!=null)
return Response.seeOther(new URI(gisViewerPortletUrl)).build(); 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){ if(isGeoExplorerLink){
ScopeProvider.instance.set(scope); 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); logger.info("GeoExplorer Application url is: " + geoExplorerPortletUrl);
//CHECKING IF THE GeoExplorer Portlet URL is valid geoExplorerPortletUrl+="?rid="+new Random().nextLong()
if(geoExplorerPortletUrl==null || geoExplorerPortletUrl.isEmpty()) +"&luuid="+URLEncoder.encode(geoExplorerUUID, UTF_8);
ExceptionManager.throwNotFoundException(req, "GeoExplorer Portlet URL not found in the scope: "+scope +". Please contact the support", this.getClass(), help); //urlRedirect(req, resp, geoExplorerPortletUrl);
return Response.seeOther(new URI(geoExplorerPortletUrl)).build();
logger.info("GeoExplorer Application url is: " + geoExplorerPortletUrl); }catch (InvalidCacheLoadException e) {
geoExplorerPortletUrl+="?rid="+new Random().nextLong() logger.error("Error on getting GeoExplorer Portlet URL for scope: "+scope, e);
+"&luuid="+URLEncoder.encode(geoExplorerUUID, UTF_8); ExceptionManager.throwNotFoundException(req, "GeoExplorer Portlet URL not found in the scope: "+scope +". Please add it or contact the support", this.getClass(), help);
//urlRedirect(req, resp, geoExplorerPortletUrl); }
return Response.seeOther(new URI(geoExplorerPortletUrl)).build();
} }
ExceptionManager.throwBadRequestException(req, GIS_UUID+" or "+GEO_EXPLORER_LAYER_UUID+" not found or empty in the query string", this.getClass(), help); ExceptionManager.throwBadRequestException(req, GIS_UUID+" or "+GEO_EXPLORER_LAYER_UUID+" not found or empty in the query string", this.getClass(), help);