This commit is contained in:
Francesco Mangiacrapa 2019-05-21 15:37:00 +00:00
parent 5cc9343aeb
commit f24080c06b
1 changed files with 63 additions and 1 deletions

View File

@ -29,6 +29,7 @@ import org.gcube.datatransfer.resolver.ConstantsResolver;
import org.gcube.datatransfer.resolver.caches.LoadingGeonetworkInstanceCache; import org.gcube.datatransfer.resolver.caches.LoadingGeonetworkInstanceCache;
import org.gcube.datatransfer.resolver.gis.GeonetworkAccessParameter.AccountType; import org.gcube.datatransfer.resolver.gis.GeonetworkAccessParameter.AccountType;
import org.gcube.datatransfer.resolver.gis.GeonetworkAccessParameter.GeonetworkLoginLevel; 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.GeonetworkInstance;
import org.gcube.datatransfer.resolver.gis.geonetwork.FilterGetRecords; import org.gcube.datatransfer.resolver.gis.geonetwork.FilterGetRecords;
import org.gcube.datatransfer.resolver.gis.geonetwork.GNAuthentication; import org.gcube.datatransfer.resolver.gis.geonetwork.GNAuthentication;
@ -166,6 +167,67 @@ public class GeonetworkResolver {
} }
logger.info("Remaining path is: "+remainPath); 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 { try {
//I'M LOADING THE GN CONFIGURATIONS (ENDPOINT, USER, PWD AND SO ON..) FROM GN LIBRARY BY GENERAL CONSTRUCTOR THAT PERFORMS AUTHENTICATION ON GN, //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); logger.error("Exception:", e);
String error = "Sorry, an error occurred on resolving geonetwork request with scope "+scope+". Please, contact support!"; String error = "Sorry, an error occurred on resolving geonetwork request with scope "+scope+". Please, contact support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }*/
}catch (Exception e) { }catch (Exception e) {