fixing bug on CatalogueResolver
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@174008 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
7983745cf6
commit
89076f4faf
|
@ -18,7 +18,7 @@ import java.util.List;
|
||||||
public enum ResourceCatalogueCodes {
|
public enum ResourceCatalogueCodes {
|
||||||
|
|
||||||
CTLG("ctlg","dataset", "Catalogue Product/Dataset"),
|
CTLG("ctlg","dataset", "Catalogue Product/Dataset"),
|
||||||
CTLGP("ctlg-p","dataset", "Catalogue Product"),
|
CTLGP("ctlg-p","product", "Catalogue Product"),
|
||||||
CTLGD("ctlg-d","dataset", "Catalogue Dataset"),
|
CTLGD("ctlg-d","dataset", "Catalogue Dataset"),
|
||||||
CTLGO("ctlg-o","organization", "Catalogue Organization"),
|
CTLGO("ctlg-o","organization", "Catalogue Organization"),
|
||||||
CTLGG("ctlg-g","group", "Catalogue Group");
|
CTLGG("ctlg-g","group", "Catalogue Group");
|
||||||
|
|
|
@ -63,11 +63,11 @@ public class LoadingCatalogueApplicationProfilesCache {
|
||||||
try{
|
try{
|
||||||
//PRE-POPULATE CACHE
|
//PRE-POPULATE CACHE
|
||||||
logger.info("Trying to pre-poluate catalogue resolver cache");
|
logger.info("Trying to pre-poluate catalogue resolver cache");
|
||||||
ScopeProvider.instance.set(UriResolverStartupListener.getContextScope());
|
ScopeProvider.instance.set(UriResolverStartupListener.getRootContextScope());
|
||||||
ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(UriResolverStartupListener.getContextScope(), true);
|
ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(UriResolverStartupListener.getRootContextScope(), true);
|
||||||
catalogueApplicationProfiles.asMap().putAll(appPrCatResolver.getHashVreNameScope());
|
catalogueApplicationProfiles.asMap().putAll(appPrCatResolver.getHashVreNameScope());
|
||||||
|
|
||||||
logger.info(LoadingCatalogueApplicationProfilesCache.class.getSimpleName() +" instancied");
|
logger.info("cache instancied");
|
||||||
logger.info("Pre-Loaded CatalogueApplicationProfiles cache is: "+catalogueApplicationProfiles.asMap().toString());
|
logger.info("Pre-Loaded CatalogueApplicationProfiles cache is: "+catalogueApplicationProfiles.asMap().toString());
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ public class LoadingCatalogueApplicationProfilesCache {
|
||||||
|
|
||||||
if(fullScope==null){
|
if(fullScope==null){
|
||||||
logger.debug("FullScope is null for VRE_NAME: "+vreName+" into Application Profile: "+ApplicationProfileReaderForCatalogueResolver.RESOURCE_NAME+", reading profile again");
|
logger.debug("FullScope is null for VRE_NAME: "+vreName+" into Application Profile: "+ApplicationProfileReaderForCatalogueResolver.RESOURCE_NAME+", reading profile again");
|
||||||
ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(UriResolverStartupListener.getContextScope(), true);
|
ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(UriResolverStartupListener.getRootContextScope(), true);
|
||||||
catalogueApplicationProfiles.asMap().putAll(appPrCatResolver.getHashVreNameScope());
|
catalogueApplicationProfiles.asMap().putAll(appPrCatResolver.getHashVreNameScope());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,5 +42,21 @@ public class CatalogueRequest {
|
||||||
return entity_name;
|
return entity_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Object#toString()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("CatalogueRequest [gcube_scope=");
|
||||||
|
builder.append(gcube_scope);
|
||||||
|
builder.append(", entity_context=");
|
||||||
|
builder.append(entity_context);
|
||||||
|
builder.append(", entity_name=");
|
||||||
|
builder.append(entity_name);
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class UriResolverStartupListener implements ServletContextListener {
|
||||||
public static final String ENV_SCOPE = "SCOPE"; //Environment Variable
|
public static final String ENV_SCOPE = "SCOPE"; //Environment Variable
|
||||||
|
|
||||||
|
|
||||||
private static String contextScope = null;
|
private static String rootContextScope = null;
|
||||||
|
|
||||||
private static ApplicationProfileGenericResourceReader gisViewerProfile;
|
private static ApplicationProfileGenericResourceReader gisViewerProfile;
|
||||||
private static ApplicationProfileGenericResourceReader geoExplorerProfile;
|
private static ApplicationProfileGenericResourceReader geoExplorerProfile;
|
||||||
|
@ -64,7 +64,7 @@ public class UriResolverStartupListener implements ServletContextListener {
|
||||||
public void contextInitialized(ServletContextEvent event) {
|
public void contextInitialized(ServletContextEvent event) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
contextScope = loadScopeFromEnvironment();
|
rootContextScope = loadScopeFromEnvironment();
|
||||||
ApplicationContext ctx = ContextProvider.get();
|
ApplicationContext ctx = ContextProvider.get();
|
||||||
String rootScope = ctx.container().configuration().infrastructure();
|
String rootScope = ctx.container().configuration().infrastructure();
|
||||||
logger.info("The ContextProvider returned the infrastructure name: "+rootScope);
|
logger.info("The ContextProvider returned the infrastructure name: "+rootScope);
|
||||||
|
@ -82,7 +82,7 @@ public class UriResolverStartupListener implements ServletContextListener {
|
||||||
new LoadingCatalogueApplicationProfilesCache();
|
new LoadingCatalogueApplicationProfilesCache();
|
||||||
|
|
||||||
logger.info("Context initialized with: ");
|
logger.info("Context initialized with: ");
|
||||||
logger.info("Scope: "+contextScope);
|
logger.info("Scope: "+rootContextScope);
|
||||||
logger.info("GisViewerProfile [ID: "+gisViewerProfile.getAppId() + ", Generic Resource Type: "+gisViewerProfile.getGenericResource()+"]");
|
logger.info("GisViewerProfile [ID: "+gisViewerProfile.getAppId() + ", Generic Resource Type: "+gisViewerProfile.getGenericResource()+"]");
|
||||||
logger.info("GeoExplorerProfile [ID: "+geoExplorerProfile. getAppId() + ", Generic Resource Type: "+geoExplorerProfile.getGenericResource()+"]");
|
logger.info("GeoExplorerProfile [ID: "+geoExplorerProfile. getAppId() + ", Generic Resource Type: "+geoExplorerProfile.getGenericResource()+"]");
|
||||||
}
|
}
|
||||||
|
@ -163,13 +163,13 @@ public class UriResolverStartupListener implements ServletContextListener {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the context scope.
|
* Gets the root context scope.
|
||||||
*
|
*
|
||||||
* @return the contextScope
|
* @return the root context scope
|
||||||
*/
|
*/
|
||||||
public static String getContextScope() {
|
public static String getRootContextScope() {
|
||||||
|
|
||||||
return contextScope;
|
return rootContextScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -122,7 +122,7 @@ public class CatalogueResolver {
|
||||||
new Thread(){
|
new Thread(){
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
boolean endPointUpdated = UpdateApplicationProfileCatalogueResolver.validateEndPoint(UriResolverStartupListener.getContextScope(), vreName, fullscope);
|
boolean endPointUpdated = UpdateApplicationProfileCatalogueResolver.validateEndPoint(UriResolverStartupListener.getRootContextScope(), vreName, fullscope);
|
||||||
logger.info("Is the Application profile for Catalogue Resolver updated? "+endPointUpdated);
|
logger.info("Is the Application profile for Catalogue Resolver updated? "+endPointUpdated);
|
||||||
// if(endPointUpdated)
|
// if(endPointUpdated)
|
||||||
// appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(fullscope, true);
|
// appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(fullscope, true);
|
||||||
|
|
|
@ -130,7 +130,7 @@ public class GisResolver {
|
||||||
|
|
||||||
}catch (InvalidCacheLoadException e) {
|
}catch (InvalidCacheLoadException e) {
|
||||||
logger.error("Error on getting GisViewer Portlet URL for scope: "+scope, 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);
|
//ExceptionManager.throwNotFoundException(req, "GisViewer Portlet URL not found in the scope: "+scope +". Please add it or contact the support", this.getClass(), help);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ public class GisResolver {
|
||||||
return Response.seeOther(new URI(geoExplorerPortletUrl)).build();
|
return Response.seeOther(new URI(geoExplorerPortletUrl)).build();
|
||||||
}catch (InvalidCacheLoadException e) {
|
}catch (InvalidCacheLoadException e) {
|
||||||
logger.error("Error on getting GeoExplorer Portlet URL for scope: "+scope, 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.throwNotFoundException(req, "GeoExplorer Portlet URL not found in the scope: "+scope +". Please add it or contact the support", this.getClass(), help);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -429,7 +429,7 @@ public class HTTPCallsUtils {
|
||||||
+ message
|
+ message
|
||||||
);
|
);
|
||||||
if(logger.isDebugEnabled())
|
if(logger.isDebugEnabled())
|
||||||
logger.debug("GeoNetwork response:\n"+badresponse);
|
logger.debug("Response is:\n"+badresponse);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (ConnectException e) {
|
} catch (ConnectException e) {
|
||||||
|
|
|
@ -17,6 +17,8 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
|
import org.gcube.datatransfer.resolver.util.HTTPCallsUtils;
|
||||||
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -160,46 +162,47 @@ public class TestResolvers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Storage hub test.
|
* Storage hub test.
|
||||||
// * @throws Exception
|
* @throws Exception
|
||||||
// */
|
*/
|
||||||
// @Test
|
@Test
|
||||||
// public void createCatalogueURLTest() throws Exception{
|
public void catalogueResolverCreateItemURLTest() throws Exception{
|
||||||
//
|
|
||||||
// String entityName = "sarda-sarda";
|
|
||||||
// String entityContext = "ctlg";
|
|
||||||
// String vreName = "devVRE";
|
|
||||||
//
|
|
||||||
// String url = String.format("%s/%s/%s/%s",URI_RESOLVER_SERVICE_ENDPOINT,entityContext, vreName, entityName);
|
|
||||||
// logger.info("Request to URL: "+url);
|
|
||||||
// URL toURL;
|
|
||||||
// int status;
|
|
||||||
// try {
|
|
||||||
// toURL = new URL(url);
|
|
||||||
// HttpURLConnection con = (HttpURLConnection) toURL.openConnection();
|
|
||||||
// con.setRequestMethod("GET");
|
|
||||||
// con.connect();
|
|
||||||
// status = con.getResponseCode();
|
|
||||||
// System.out.println("Response status is: "+status);
|
|
||||||
// if(status==HttpStatus.SC_OK){
|
|
||||||
// System.out.println("Response: \n"+getContentReponse(con.getInputStream()));
|
|
||||||
// }else{
|
|
||||||
// System.out.println("\nError on resolving the Catalogue URL: "+toURL);
|
|
||||||
// System.out.println("Response: \n"+getContentReponse(con.getInputStream()));
|
|
||||||
// }
|
|
||||||
// //con.setRequestProperty("Content-Type", "application/json");
|
|
||||||
// //con.setConnectTimeout(5000);
|
|
||||||
// //con.setReadTimeout(5000)
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// catch (Exception e) {
|
|
||||||
// // TODO Auto-generated catch block
|
|
||||||
// logger.error("Error: ",e);
|
|
||||||
// throw e;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
String entityName = "sarda-sarda";
|
||||||
|
String entityContext = "product";
|
||||||
|
String scope = "/gcube/devsec/devVRE";
|
||||||
|
|
||||||
|
String url = String.format("%s/%s",URI_RESOLVER_SERVICE_ENDPOINT,"catalogue");
|
||||||
|
logger.info("POST Request to URL: "+url);
|
||||||
|
try {
|
||||||
|
|
||||||
|
HTTPCallsUtils httCaller = new HTTPCallsUtils(null, null);
|
||||||
|
String jsonString =
|
||||||
|
"{" +
|
||||||
|
"\"gcube_scope\":\""+scope+"\"," +
|
||||||
|
"\"entity_context\":\""+entityContext+"\"," +
|
||||||
|
"\"entity_name\":\""+entityName+"\"" +
|
||||||
|
"}";
|
||||||
|
System.out.println("Sending JSON: "+jsonString);
|
||||||
|
// JSONObject json = new JSONObject();
|
||||||
|
// json.append("gcube_scope", scope);
|
||||||
|
// json.append("entity_context", entityContext);
|
||||||
|
// json.append("entity_name", entityName);
|
||||||
|
// System.out.println("Sending json object: "+json.toString());
|
||||||
|
InputStream response = httCaller.post(url, jsonString, "application/json");
|
||||||
|
System.out.println("Response: \n"+getContentReponse(response));
|
||||||
|
//con.setRequestProperty("Content-Type", "application/json");
|
||||||
|
//con.setConnectTimeout(5000);
|
||||||
|
//con.setReadTimeout(5000)
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
logger.error("Error: ",e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Gets the content reponse.
|
* Gets the content reponse.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue