just changed some comments
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@179504 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e44a57bb4e
commit
70e5adc94d
|
@ -90,6 +90,12 @@ public class LoadingGeonetworkInstanceCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
GeonetworkAccessParameter gntwAccess = new GeonetworkAccessParameter(scope);
|
GeonetworkAccessParameter gntwAccess = new GeonetworkAccessParameter(scope);
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* !!!!!!!DOES NOT AUTHENTICATE NEVER!!!!!!
|
||||||
|
*
|
||||||
|
*/
|
||||||
GeonetworkInstance geoInstance = gntwAccess.getGeonetworkInstance(false, GeonetworkLoginLevel.CKAN, AccountType.CKAN);
|
GeonetworkInstance geoInstance = gntwAccess.getGeonetworkInstance(false, GeonetworkLoginLevel.CKAN, AccountType.CKAN);
|
||||||
logger.info("Loaded "+geoInstance+" for scope: " + scope);
|
logger.info("Loaded "+geoInstance+" for scope: " + scope);
|
||||||
return geoInstance;
|
return geoInstance;
|
||||||
|
|
|
@ -27,9 +27,6 @@ import org.apache.commons.io.IOUtils;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.datatransfer.resolver.ConstantsResolver;
|
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.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;
|
||||||
|
@ -171,6 +168,8 @@ public class GeonetworkResolver {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
//I'M LOADING GN CONFIGURATIONS (ENDPOINT, USER, PWD AND SO ON..) FOR PASSED SCOPE FROM GN LIBRARY BY A GENERAL METHOD WITHOUT TO PERFORM AUTHENTICATION ON GN,
|
||||||
|
//AFTER THAT I'M USING THEM TO PERFORM AUTHENTICATION ON GN VIA HTTP_CLIENTS IF NEEDED
|
||||||
GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope);
|
GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope);
|
||||||
logger.info("set scope provider "+scope);
|
logger.info("set scope provider "+scope);
|
||||||
ScopeProvider.instance.set(scope);
|
ScopeProvider.instance.set(scope);
|
||||||
|
@ -180,22 +179,15 @@ public class GeonetworkResolver {
|
||||||
Configuration config = gnInstance.getConfig()!=null?gnInstance.getConfig():null;
|
Configuration config = gnInstance.getConfig()!=null?gnInstance.getConfig():null;
|
||||||
|
|
||||||
if(account==null || account.getUser()==null || account.getPassword()==null || config==null) {
|
if(account==null || account.getUser()==null || account.getPassword()==null || config==null) {
|
||||||
logger.info("Loading GN istance and configurations via Geonetwork Library...");
|
logger.info("Loading GN instance and configurations via Geonetwork Library...");
|
||||||
logger.info("set scope provider "+scope);
|
|
||||||
ScopeProvider.instance.set(scope);
|
|
||||||
config = gnInstance.getGeonetworkPublisher().getConfiguration();
|
config = gnInstance.getGeonetworkPublisher().getConfiguration();
|
||||||
account = config.getScopeConfiguration().getAccounts().get(Type.CKAN);
|
account = config.getScopeConfiguration().getAccounts().get(Type.CKAN);
|
||||||
version = config.getGeoNetworkVersion();
|
version = config.getGeoNetworkVersion();
|
||||||
geonetworkUrl = config.getGeoNetworkEndpoint();
|
geonetworkUrl = config.getGeoNetworkEndpoint();
|
||||||
}
|
}
|
||||||
logger.info("set scope provider "+scope);
|
|
||||||
ScopeProvider.instance.set(scope);
|
|
||||||
logger.info("SCOPE: {}, CKAN user used is: {}",scope, account.getUser(), account.getPassword());
|
|
||||||
logger.info("SCOPE: {}, GN EndPoint: {}",scope, geonetworkUrl);
|
|
||||||
|
|
||||||
// GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope);
|
logger.info("SCOPE: {}, CKAN user used is: {}, GN EndPoint: {}",scope, account.getUser(), geonetworkUrl);
|
||||||
// ScopeProvider.instance.set(scope);
|
|
||||||
|
|
||||||
HTTPCallsUtils httpUtils = new HTTPCallsUtils();
|
HTTPCallsUtils httpUtils = new HTTPCallsUtils();
|
||||||
|
|
||||||
if(visibility.equals(VISIBILITY.PRV.name())){
|
if(visibility.equals(VISIBILITY.PRV.name())){
|
||||||
|
@ -217,9 +209,6 @@ public class GeonetworkResolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Configuration config = gnInstance.getGeonetworkPublisher().getConfiguration();
|
|
||||||
//String geonetworkUrl = config.getGeoNetworkEndpoint();
|
|
||||||
// String geonetworkUrl = gnInstance.getEndPoint();
|
|
||||||
String baseURL = remainPath==null ||remainPath.isEmpty()?geonetworkUrl+"/"+CSW_SERVER:geonetworkUrl+"/"+CSW_SERVER+remainPath;
|
String baseURL = remainPath==null ||remainPath.isEmpty()?geonetworkUrl+"/"+CSW_SERVER:geonetworkUrl+"/"+CSW_SERVER+remainPath;
|
||||||
logger.info("The base URL is: "+baseURL);
|
logger.info("The base URL is: "+baseURL);
|
||||||
String queryString = req.getQueryString()==null || req.getQueryString().isEmpty()?"":"?"+req.getQueryString();
|
String queryString = req.getQueryString()==null || req.getQueryString().isEmpty()?"":"?"+req.getQueryString();
|
||||||
|
@ -253,106 +242,7 @@ public class GeonetworkResolver {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
try {
|
|
||||||
|
|
||||||
//I'M LOADING THE GN CONFIGURATIONS (ENDPOINT, USER, PWD AND SO ON..) FROM GN LIBRARY BY GENERAL CONSTRUCTOR THAT PERFORMS AUTHENTICATION ON GN,
|
|
||||||
//THEN THE CONGIGURATIONS LAODED, USER TO PERFORM AUTHENTICATION AND SO ON ARE MANAGE VIA HTTP_CLIENTS.
|
|
||||||
//I'M LOADING THE GN CONFIGURATIONS (ENDPOINT, USER, PWD AND SO ON..) FROM GN LIBRARY BY GENERAL CONSTRUCTOR THAT PERFORMS AUTHENTICATION ON GN,
|
|
||||||
//THEN THE CONGIGURATIONS LAODED, USER TO PERFORM AUTHENTICATION AND SO ON ARE MANAGE VIA HTTP_CLIENTS.
|
|
||||||
logger.info("set scope provider "+scope);
|
|
||||||
ScopeProvider.instance.set(scope);
|
|
||||||
GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope, GeonetworkLoginLevel.CKAN, AccountType.CKAN);
|
|
||||||
Account account = gnInstance.getAccount();
|
|
||||||
Version version = gnInstance.getVersion();
|
|
||||||
String geonetworkUrl = gnInstance.getEndPoint();
|
|
||||||
Configuration config = gnInstance.getConfig()!=null?gnInstance.getConfig():null;
|
|
||||||
|
|
||||||
if(account==null || account.getUser()==null || account.getPassword()==null || config==null) {
|
|
||||||
logger.info("Loading GN istance and configurations via Geonetwork Library...");
|
|
||||||
logger.info("set scope provider "+scope);
|
|
||||||
ScopeProvider.instance.set(scope);
|
|
||||||
config = gnInstance.getGeonetworkPublisher().getConfiguration();
|
|
||||||
account = config.getScopeConfiguration().getAccounts().get(Type.CKAN);
|
|
||||||
version = config.getGeoNetworkVersion();
|
|
||||||
geonetworkUrl = config.getGeoNetworkEndpoint();
|
|
||||||
}
|
|
||||||
//logger.info("set scope provider "+scope);
|
|
||||||
//ScopeProvider.instance.set(scope);
|
|
||||||
logger.info("SCOPE: {}, CKAN user owner is: {}",scope, account.getUser());
|
|
||||||
logger.info("SCOPE: {}, GN EndPoint: {}",scope, geonetworkUrl);
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
// Account account = config.getScopeConfiguration().getAccounts().get(Type.CKAN);
|
|
||||||
|
|
||||||
if(account.getUser()!=null){
|
|
||||||
switch (version) {
|
|
||||||
case DUE:
|
|
||||||
boolean authorized = GNAuthentication.login(httpUtils, geonetworkUrl, account.getUser(), account.getPassword());
|
|
||||||
logger.info("Authorized on GN2 "+geonetworkUrl +" ? "+authorized);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
httpUtils = new HTTPCallsUtils(account.getUser(), account.getPassword());
|
|
||||||
logger.info("Authorized on GN3 via HTTCallsUtils...");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
logger.warn("I'm not able to perform authentication, the user read from config with "+Type.CKAN+" is null");
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
|
|
||||||
|
@ -449,13 +339,8 @@ public class GeonetworkResolver {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
//MANUALLY INSTANCING THE GEONETWORK TO MANGE LOGIN IF NEEDED AND SO ON..
|
//I'M LOADING GN CONFIGURATIONS (ENDPOINT, USER, PWD AND SO ON..) FOR PASSED SCOPE FROM GN LIBRARY BY A GENERAL METHOD WITHOUT TO PERFORM AUTHENTICATION ON GN,
|
||||||
//DO NOT USE THE LOADING_CACHE OF GEONETWORK
|
//AFTER THAT I'M USING THEM TO PERFORM AUTHENTICATION ON GN VIA HTTP_CLIENTS IF NEEDED
|
||||||
// GeonetworkServiceInterface gntwAccess = new GeonetworkAccessParameter(scope);
|
|
||||||
// GeonetworkInstance gnInstance = gntwAccess.getGeonetworkInstance(false, null, null);
|
|
||||||
|
|
||||||
//I'M LOADING THE GN CONFIGURATIONS (ENDPOINT, USER, PWD AND SO ON..) FROM GN LIBRARY BY GENERAL CONSTRUCTOR THAT PERFORMS AUTHENTICATION ON GN,
|
|
||||||
//THEN THE CONGIGURATIONS LAODED, USER TO PERFORM AUTHENTICATION AND SO ON ARE MANAGE VIA HTTP_CLIENTS.
|
|
||||||
GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope);
|
GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope);
|
||||||
logger.info("set scope provider "+scope);
|
logger.info("set scope provider "+scope);
|
||||||
ScopeProvider.instance.set(scope);
|
ScopeProvider.instance.set(scope);
|
||||||
|
@ -465,18 +350,13 @@ public class GeonetworkResolver {
|
||||||
Configuration config = gnInstance.getConfig()!=null?gnInstance.getConfig():null;
|
Configuration config = gnInstance.getConfig()!=null?gnInstance.getConfig():null;
|
||||||
|
|
||||||
if(account==null || account.getUser()==null || account.getPassword()==null || config==null) {
|
if(account==null || account.getUser()==null || account.getPassword()==null || config==null) {
|
||||||
logger.info("Loading GN istance and configurations via Geonetwork Library...");
|
logger.info("Loading GN instance and configurations via Geonetwork Library...");
|
||||||
logger.info("set scope provider "+scope);
|
|
||||||
ScopeProvider.instance.set(scope);
|
|
||||||
config = gnInstance.getGeonetworkPublisher().getConfiguration();
|
config = gnInstance.getGeonetworkPublisher().getConfiguration();
|
||||||
account = config.getScopeConfiguration().getAccounts().get(Type.CKAN);
|
account = config.getScopeConfiguration().getAccounts().get(Type.CKAN);
|
||||||
version = config.getGeoNetworkVersion();
|
version = config.getGeoNetworkVersion();
|
||||||
geonetworkUrl = config.getGeoNetworkEndpoint();
|
geonetworkUrl = config.getGeoNetworkEndpoint();
|
||||||
}
|
}
|
||||||
logger.info("set scope provider "+scope);
|
logger.info("SCOPE: {}, CKAN user used is: {}, GN EndPoint: {}",scope, account.getUser(), geonetworkUrl);
|
||||||
ScopeProvider.instance.set(scope);
|
|
||||||
logger.info("SCOPE: {}, CKAN user used is: {}",scope, account.getUser(), account.getPassword());
|
|
||||||
logger.info("SCOPE: {}, GN EndPoint: {}",scope, geonetworkUrl);
|
|
||||||
|
|
||||||
// logger.info("Parameters..");
|
// logger.info("Parameters..");
|
||||||
// for (Enumeration<String> e = req.getParameterNames(); e.hasMoreElements();){
|
// for (Enumeration<String> e = req.getParameterNames(); e.hasMoreElements();){
|
||||||
|
@ -508,7 +388,7 @@ public class GeonetworkResolver {
|
||||||
}else
|
}else
|
||||||
IOUtils.copy(req.getInputStream(), byteArray);
|
IOUtils.copy(req.getInputStream(), byteArray);
|
||||||
}else{
|
}else{
|
||||||
logger.info("IS NOT A REQUEST TO "+SRV_EN_MEF_EXPORT);
|
logger.debug("IS NOT A REQUEST TO "+SRV_EN_MEF_EXPORT);
|
||||||
gnCSWlURL = remainPath==null || remainPath.isEmpty()?geonetworkUrl+"/"+CSW_SERVER:geonetworkUrl+"/"+CSW_SERVER+remainPath;
|
gnCSWlURL = remainPath==null || remainPath.isEmpty()?geonetworkUrl+"/"+CSW_SERVER:geonetworkUrl+"/"+CSW_SERVER+remainPath;
|
||||||
IOUtils.copy(req.getInputStream(), byteArray);
|
IOUtils.copy(req.getInputStream(), byteArray);
|
||||||
}
|
}
|
||||||
|
@ -559,7 +439,7 @@ public class GeonetworkResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Sending CSW POST request to URL: "+gnCSWlURL);
|
logger.info("Sending CSW POST request to URL: "+gnCSWlURL);
|
||||||
logger.info("Content-Type: "+req.getContentType());
|
logger.debug("Content-Type: "+req.getContentType());
|
||||||
|
|
||||||
//DEBUG
|
//DEBUG
|
||||||
//logger.debug("POST - BODY : "+byteArray.toString());
|
//logger.debug("POST - BODY : "+byteArray.toString());
|
||||||
|
@ -661,15 +541,11 @@ public class GeonetworkResolver {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* !!!!!USE ONLY IN GET METHOD
|
|
||||||
*
|
|
||||||
* Gets the geonetwork instance for scope.
|
* Gets the geonetwork instance for scope.
|
||||||
*
|
*
|
||||||
* @param scope the scope
|
* @param scope the scope
|
||||||
* @param loginLevel the login level
|
|
||||||
* @param accountType the account type
|
|
||||||
* @return the geonetwork instance for scope
|
* @return the geonetwork instance for scope
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue