From f24080c06ba9e9ff77ef325fad5149e73a1f2d85 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Tue, 21 May 2019 15:37:00 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@179497 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../resolver/services/GeonetworkResolver.java | 64 ++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeonetworkResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeonetworkResolver.java index 3ad6657..3642e71 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeonetworkResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeonetworkResolver.java @@ -29,6 +29,7 @@ import org.gcube.datatransfer.resolver.ConstantsResolver; import org.gcube.datatransfer.resolver.caches.LoadingGeonetworkInstanceCache; import org.gcube.datatransfer.resolver.gis.GeonetworkAccessParameter.AccountType; import org.gcube.datatransfer.resolver.gis.GeonetworkAccessParameter.GeonetworkLoginLevel; +import org.gcube.datatransfer.resolver.gis.GeonetworkAccessParameter; import org.gcube.datatransfer.resolver.gis.GeonetworkInstance; import org.gcube.datatransfer.resolver.gis.geonetwork.FilterGetRecords; import org.gcube.datatransfer.resolver.gis.geonetwork.GNAuthentication; @@ -166,6 +167,67 @@ public class GeonetworkResolver { } logger.info("Remaining path is: "+remainPath); + + + try { + + GeonetworkAccessParameter gntwAccess = new GeonetworkAccessParameter(scope); + GeonetworkInstance gnInstance = gntwAccess.getGeonetworkInstance(true, null,null); + + ScopeProvider.instance.set(scope); + + HTTPCallsUtils httpUtils = new HTTPCallsUtils(); + Configuration config = gnInstance.getGeonetworkPublisher().getConfiguration(); + String geonetworkUrl = config.getGeoNetworkEndpoint(); + String baseURL = remainPath==null ||remainPath.isEmpty()?geonetworkUrl+"/"+CSW_SERVER:geonetworkUrl+"/"+CSW_SERVER+remainPath; + logger.info("The base URL is: "+baseURL); + String queryString = req.getQueryString()==null || req.getQueryString().isEmpty()?"":"?"+req.getQueryString(); + gnGetlURL = baseURL+queryString; + logger.info("Sending get request to URL: "+gnGetlURL); + HttpResponse proxedGNResponse = httpUtils.get(gnGetlURL); + + switch(proxedGNResponse.getStatus()){ + case HttpServletResponse.SC_OK: + + //Building the response + InputStream streamToWrite = IOUtils.toInputStream(proxedGNResponse.getResponse()); + StreamingOutput so = new SingleFileStreamingOutput(streamToWrite); + + logger.info("Response return Content-Type: "+httpUtils.getLastContentType()); + + ResponseBuilder responseBuilder = Response + .ok(so) + .header(ConstantsResolver.CONTENT_TYPE, httpUtils.getLastContentType()); + return responseBuilder.build(); + + case HttpServletResponse.SC_FORBIDDEN: + throw ExceptionManager.forbiddenException(req, "You are not authorized to perform the request "+gnGetlURL, this.getClass(), helpURI); + + default: + throw ExceptionManager.internalErrorException(req, "Sorry, an error occurred performing the geonetwork request "+gnGetlURL+" with scope "+scope, this.getClass(), helpURI); + } + + } catch (Exception e) { + logger.error("Exception:", e); + String error = "Sorry, an error occurred on resolving geonetwork request with scope "+scope+". Please, contact support!"; + throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); + } + + + + + + + + + + + + + + + + /* try { //I'M LOADING THE GN CONFIGURATIONS (ENDPOINT, USER, PWD AND SO ON..) FROM GN LIBRARY BY GENERAL CONSTRUCTOR THAT PERFORMS AUTHENTICATION ON GN, @@ -249,7 +311,7 @@ public class GeonetworkResolver { logger.error("Exception:", e); String error = "Sorry, an error occurred on resolving geonetwork request with scope "+scope+". Please, contact support!"; throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); - } + }*/ }catch (Exception e) {