#22385 Integrated with Catalogue Resolver and SHUB Resolver

This commit is contained in:
Francesco Mangiacrapa 2021-11-08 15:53:31 +01:00
parent 3039279092
commit 4b11aebf62
9 changed files with 234 additions and 137 deletions

View File

@ -7,7 +7,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Enhancement ### Enhancement
* [22385] Integrated with Catalogue Resolver * [22385] Integrated with Catalogue Resolver and SHUB Resolver
## [v1.4.2] - 2021-04-21 ## [v1.4.2] - 2021-04-21

11
pom.xml
View File

@ -37,9 +37,6 @@
<properties> <properties>
<distroDirectory>${project.basedir}/distro</distroDirectory> <distroDirectory>${project.basedir}/distro</distroDirectory>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory> <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<!-- Convenience property to set the GWT version -->
<gwtVersion>2.5.1</gwtVersion>
<!-- GWT needs at least java 1.5 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties> </properties>
@ -103,14 +100,14 @@
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId> <artifactId>slf4j-api</artifactId>
<version>1.6.4</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version> <version>1.7.25</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@ -30,16 +30,6 @@ import org.slf4j.LoggerFactory;
*/ */
public class UriResolverManager { public class UriResolverManager {
/**
* Time to reload Runtime Resource Configuration
*/
// public static int RESET_DELAY = 15*60*1000; //15 MINUTES
/**
* Time to reload Runtime Resource Configuration
*/
// public static int RESET_TIME = RESET_DELAY; //15 MINUTES
private UriResolverMapReader uriResolverMapReader; private UriResolverMapReader uriResolverMapReader;
private Map<String, Resolver> applicationTypes; private Map<String, Resolver> applicationTypes;
private String applicationType; private String applicationType;
@ -174,7 +164,7 @@ public class UriResolverManager {
throw new IllegalArgumentException("Application type is null"); throw new IllegalArgumentException("Application type is null");
Resolver resolver = this.applicationTypes.get(applicationType); Resolver resolver = this.applicationTypes.get(applicationType);
String link; String link = null;
if (parameters == null) if (parameters == null)
throw new IllegalArgumentException("Input Map parameters is null"); throw new IllegalArgumentException("Input Map parameters is null");
@ -201,7 +191,7 @@ public class UriResolverManager {
} }
List<ServiceParameter> resourceParameters = serviceAccessPoint.getServiceParameters(); List<ServiceParameter> resourceParameters = serviceAccessPoint.getServiceParameters();
LOG.debug("Service parameters are: " + resourceParameters);
// CHECK PARAMETERS // CHECK PARAMETERS
for (ServiceParameter serviceParameter : resourceParameters) { for (ServiceParameter serviceParameter : resourceParameters) {
if (serviceParameter.isMandatory()) { if (serviceParameter.isMandatory()) {
@ -215,36 +205,44 @@ public class UriResolverManager {
String baseURI = serviceAccessPoint.getServiceUrl(); String baseURI = serviceAccessPoint.getServiceUrl();
try { try {
return resolver.getLink(baseURI, parameters); link = resolver.getLink(baseURI, parameters);
} catch (NotImplementedException e) { if (shortLink)
LOG.info("Get Link not implemented, going to default implementation by GET Request"); return shortTheLink(link);
}
// Encoding only the query string return link;
} catch (NotImplementedException e) {
LOG.info("Specialized getLink not implemented, going to default implementation");
}
String linkDecoded = null; String linkDecoded = null;
String queryString = null; String queryString = null;
if (!shortLink) { if (!shortLink) {
// not shortening so returning the link with the query string with only the // not shortening so returning the link with the query string with only the
// parameters encoded // parameters encoded
LOG.info("getLink implemented via GET request and encoded query-string");
queryString = UrlEncoderUtil.encodeQuery(parameters); queryString = UrlEncoderUtil.encodeQuery(parameters);
String toReturn = String.format("%s?%s", baseURI, queryString); String toReturn = String.format("%s?%s", baseURI, queryString);
LOG.info("returning link with encoded parameters in the query string: " + toReturn); LOG.info("returning link with encoded parameters in the query string: " + toReturn);
return toReturn; return toReturn;
} }
// Not specialized getLink has been implemented
// Short link required
// Going to build the GET request with query string decoded
LOG.info("getLink implemented via GET request and (decoded) query-string");
queryString = UrlEncoderUtil.toQueryString(parameters); queryString = UrlEncoderUtil.toQueryString(parameters);
linkDecoded = String.format("%s?%s", baseURI, queryString); linkDecoded = String.format("%s?%s", baseURI, queryString);
link = linkDecoded; link = linkDecoded;
LOG.info("Created HTTP URI request (link): " + link);
LOG.info("Created HTTP link: " + link);
if (shortLink) { if (shortLink) {
try { try {
LOG.info("Short link requested, so encoding query string is required...");
String queryStringEncoded = UrlEncoderUtil.encodeString(queryString); String queryStringEncoded = UrlEncoderUtil.encodeString(queryString);
link = String.format("%s?%s", baseURI, queryStringEncoded); link = String.format("%s?%s", baseURI, queryStringEncoded);
LOG.info("Encoded link is: " + link); LOG.info("Encoded link is: " + link);
LOG.info("Shortner start.."); LOG.info("Shortner starts..");
UrlShortener shortener = new UrlShortener(); String shortedLink = shortTheLink(link);
String shortedLink = shortener.shorten(link);
LOG.info("Shorted link is: " + shortedLink); LOG.info("Shorted link is: " + shortedLink);
if (shortedLink != null && shortedLink.equals(link)) { if (shortedLink != null && shortedLink.equals(link)) {
// here the short link and the input link are identical // here the short link and the input link are identical
@ -275,6 +273,20 @@ public class UriResolverManager {
return link; return link;
} }
private String shortTheLink(String link) {
String toReturnLink = link;
try {
UrlShortener shortener = new UrlShortener();
String shortedLink = shortener.shorten(link);
LOG.info("Shorted link is: " + shortedLink);
toReturnLink = shortedLink;
} catch (Exception e) {
LOG.warn("Returning source link, an error occurred during link shortening: ", e);
}
return toReturnLink;
}
/** /**
* Gets the application types. * Gets the application types.
* *
@ -388,10 +400,4 @@ public class UriResolverManager {
reader = null; reader = null;
} }
/*
* public static void main(String[] args) { try { UriResolverManager manager =
* new UriResolverManager(); System.out.println(manager.getCapabilities());
* System.out.println(manager.getApplicationTypes()); } catch (Exception e) { //
* TODO Auto-generated catch block e.printStackTrace(); } }
*/
} }

View File

@ -22,12 +22,10 @@ import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The Class RuntimeResourceReader. * The Class RuntimeResourceReader.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Apr 30, 2015
* Apr 30, 2015
*/ */
public class RuntimeResourceReader { public class RuntimeResourceReader {
@ -39,7 +37,6 @@ public class RuntimeResourceReader {
private String entryName; private String entryName;
/** /**
* Instantiates a new runtime resource reader. * Instantiates a new runtime resource reader.
* *
@ -54,49 +51,53 @@ public class RuntimeResourceReader {
/** /**
* Read resource. * Read resource.
* *
* @param scope the scope * @param scope the scope
* @param resourceName the resource name * @param resourceName the resource name
* @return the application URI * @return the application URI
* @throws Exception the exception * @throws Exception the exception
*/ */
private void readResource(String resourceName) throws Exception { private void readResource(String resourceName) throws Exception {
try{ try {
String scope = ScopeProvider.instance.get(); String scope = ScopeProvider.instance.get();
logger.info("Trying to read resource: "+resourceName+", in the scope: "+scope); logger.info("Trying to read resource: " + resourceName + ", in the scope: " + scope);
this.resourceName = resourceName; this.resourceName = resourceName;
SimpleQuery query = queryFor(ServiceEndpoint.class); SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Name/string() eq '"+resourceName+"'"); query.addCondition("$resource/Profile/Name/string() eq '" + resourceName + "'");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class); DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> r = client.submit(query); List<ServiceEndpoint> r = client.submit(query);
if (r == null || r.isEmpty()) throw new Exception("Cannot retrieve the runtime resource with name: "+resourceName +" in the scope: "+scope); if (r == null || r.isEmpty())
throw new Exception(
"Cannot retrieve the runtime resource with name: " + resourceName + " in the scope: " + scope);
ServiceEndpoint se = r.get(0); ServiceEndpoint se = r.get(0);
if(se.profile()==null){ if (se.profile() == null) {
String msg = "Runtime reosource with resource name: "+resourceName +" is null in the scope: "+scope; String msg = "Runtime reosource with resource name: " + resourceName + " is null in the scope: "
+ scope;
logger.error(msg); logger.error(msg);
throw new Exception(msg); throw new Exception(msg);
} }
Group<AccessPoint> accessPoints = se.profile().accessPoints(); Group<AccessPoint> accessPoints = se.profile().accessPoints();
if(accessPoints.size()==0) throw new Exception("Accesspoint in resource "+resourceName+" not found"); if (accessPoints.size() == 0)
throw new Exception("Accesspoint in resource " + resourceName + " not found");
Iterator<AccessPoint> acIt = accessPoints.iterator(); Iterator<AccessPoint> acIt = accessPoints.iterator();
serviceAccessPoints = new ArrayList<ServiceAccessPoint>(accessPoints.size()); serviceAccessPoints = new ArrayList<ServiceAccessPoint>(accessPoints.size());
while(acIt.hasNext()){ while (acIt.hasNext()) {
AccessPoint ap = acIt.next(); AccessPoint ap = acIt.next();
Group<Property> properties = ap.properties(); Group<Property> properties = ap.properties();
if(properties.size()==0){ if (properties.size() == 0) {
logger.warn("Properties in resource "+resourceName+" not found"); logger.warn("Properties in resource " + resourceName + " not found");
}else{ } else {
List<ServiceParameter> serviceParameters = new ArrayList<ServiceParameter>(properties.size()); List<ServiceParameter> serviceParameters = new ArrayList<ServiceParameter>(properties.size());
@ -111,17 +112,19 @@ public class RuntimeResourceReader {
serviceAccessPoints.add(new ServiceAccessPoint(ap.name(), ap.address(), serviceParameters)); serviceAccessPoints.add(new ServiceAccessPoint(ap.name(), ap.address(), serviceParameters));
} }
}
// parameters.setUser(ap.username()); //username
//
// String decryptedPassword = StringEncrypter.getEncrypter().decrypt(ap.password());
//
// parameters.setPassword(decryptedPassword); //password
// Group<Property> properties = ap.properties();
}catch (Exception e) { }
logger.error("Sorry, an error occurred on reading the resource "+resourceName+ " Runtime Resource",e); logger.debug("Found properties: " + serviceAccessPoints);
throw new Exception("Sorry, an error occurred on reading the resource "+resourceName+ " Runtime Reosurce"); // parameters.setUser(ap.username()); //username
// String decryptedPassword =
// StringEncrypter.getEncrypter().decrypt(ap.password());
// parameters.setPassword(decryptedPassword); //password
// Group<Property> properties = ap.properties();
} catch (Exception e) {
logger.error("Sorry, an error occurred on reading the resource " + resourceName + " Runtime Resource", e);
throw new Exception(
"Sorry, an error occurred on reading the resource " + resourceName + " Runtime Reosurce");
} }
} }
@ -131,10 +134,10 @@ public class RuntimeResourceReader {
* @param entryName the entry name * @param entryName the entry name
* @return the service access point for entry name * @return the service access point for entry name
*/ */
public ServiceAccessPoint getServiceAccessPointForEntryName(String entryName){ public ServiceAccessPoint getServiceAccessPointForEntryName(String entryName) {
for (ServiceAccessPoint serviceAccessPoint : serviceAccessPoints) { for (ServiceAccessPoint serviceAccessPoint : serviceAccessPoints) {
if(serviceAccessPoint.getEntryName().equals(entryName)) if (serviceAccessPoint.getEntryName().equals(entryName))
return serviceAccessPoint; return serviceAccessPoint;
} }
return null; return null;
@ -167,7 +170,9 @@ public class RuntimeResourceReader {
return serviceAccessPoints; return serviceAccessPoints;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
*/ */
@Override @Override
@ -184,8 +189,6 @@ public class RuntimeResourceReader {
return builder.toString(); return builder.toString();
} }
// public static void main(String[] args) { // public static void main(String[] args) {
// try { // try {
// RuntimeResourceReader rr = new RuntimeResourceReader("/gcube", "Gis-Resolver"); // RuntimeResourceReader rr = new RuntimeResourceReader("/gcube", "Gis-Resolver");

View File

@ -14,7 +14,8 @@ import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.uriresolvermanager.entity.GenericResolver; import org.gcube.portlets.user.uriresolvermanager.entity.GenericResolver;
import org.gcube.portlets.user.uriresolvermanager.entity.Resolver; import org.gcube.portlets.user.uriresolvermanager.entity.Resolver;
import org.gcube.portlets.user.uriresolvermanager.resolvers.CatalogueResolverCaller; import org.gcube.portlets.user.uriresolvermanager.resolvers.CatalogueResolverCallBuilder;
import org.gcube.portlets.user.uriresolvermanager.resolvers.SHUBResolverCallBuilder;
import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.Query; import org.gcube.resources.discovery.client.queries.api.Query;
import org.gcube.resources.discovery.client.queries.impl.QueryBox; import org.gcube.resources.discovery.client.queries.impl.QueryBox;
@ -116,11 +117,13 @@ public class UriResolverMapReader {
String resoureName = resources.get(0); String resoureName = resources.get(0);
String entryName = entryNames.get(0); String entryName = entryNames.get(0);
Resolver resolver; Resolver resolver;
if (entryName.equals("ctlg")) { if (entryName.equalsIgnoreCase("ctlg")) {
resolver = new CatalogueResolverCaller(resoureName, entryName); resolver = new CatalogueResolverCallBuilder(resoureName, entryName);
} else } else if (entryName.equalsIgnoreCase("shub")) {
resolver = new SHUBResolverCallBuilder(resoureName, entryName);
} else {
resolver = new GenericResolver(resoureName, entryName); resolver = new GenericResolver(resoureName, entryName);
}
applicationTypes.put(at, resolver); applicationTypes.put(at, resolver);
logger.info("Stored: " + at + " -> Resolver: " + resolver); logger.info("Stored: " + at + " -> Resolver: " + resolver);
} else } else

View File

@ -15,39 +15,40 @@ import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The Class CatalogueResolverCaller. * The Class CatalogueResolverCallBuilder.
* *
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
* *
* Nov 5, 2021 * Nov 5, 2021
*/ */
public class CatalogueResolverCaller extends GenericResolver { public class CatalogueResolverCallBuilder extends GenericResolver {
public static final Logger LOG = LoggerFactory.getLogger(CatalogueResolverCaller.class); private static final int _60SEC = 60000;
public static final Logger LOG = LoggerFactory.getLogger(CatalogueResolverCallBuilder.class);
/** /**
* Instantiates a new catalogue resolver wrapper. * Instantiates a new catalogue resolver wrapper.
* *
* @param resourceName the resource name * @param resourceName the resource name
* @param entryName the entry name * @param entryName the entry name
*/ */
public CatalogueResolverCaller(String resourceName, String entryName) { public CatalogueResolverCallBuilder(String resourceName, String entryName) {
super(resourceName, entryName); super(resourceName, entryName);
} }
/** /**
* Gets the link. * Gets the link.
* *
* @param baseURI the base URI * @param baseURI the base URI
* @param parameters the parameters * @param parameters the parameters
* @return the link * @return the link
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override @Override
public String getLink(String baseURI, Map<String, String> parameters) throws Exception { public String getLink(String baseURI, Map<String, String> parameters) throws Exception {
LOG.debug("called getLink: " + baseURI + " parameters: "+parameters);
HttpURLConnection con = null; HttpURLConnection con = null;
String theResponse = null; String theResponse = null;
try { try {
@ -56,19 +57,19 @@ public class CatalogueResolverCaller extends GenericResolver {
con = (HttpURLConnection) urlObj.openConnection(); con = (HttpURLConnection) urlObj.openConnection();
con.setRequestMethod("POST"); con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
//con.setRequestProperty("Accept", "application/json"); // con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true); con.setDoOutput(true);
con.setReadTimeout(60000); con.setReadTimeout(_60SEC);
con.setConnectTimeout(60000); con.setConnectTimeout(_60SEC);
JSONObject jObj = new org.json.JSONObject(); JSONObject jObj = new org.json.JSONObject();
for (String key : parameters.keySet()) { for (String key : parameters.keySet()) {
jObj.put(key, parameters.get(key)); jObj.put(key, parameters.get(key));
} }
String toJSON = jObj.toString(); String toJSON = jObj.toString();
LOG.info("Submitting JSON: "+toJSON); LOG.info("Submitting JSON: " + toJSON);
Integer code = null; Integer code = null;
try { try {
@ -89,6 +90,7 @@ public class CatalogueResolverCaller extends GenericResolver {
} }
} catch (Exception e) { } catch (Exception e) {
LOG.error(CatalogueResolverCallBuilder.class.getSimpleName() + " error: ", e);
throw e; throw e;
} finally { } finally {
try { try {

View File

@ -0,0 +1,66 @@
package org.gcube.portlets.user.uriresolvermanager.resolvers;
import java.util.Map;
import org.gcube.portlets.user.uriresolvermanager.entity.GenericResolver;
import org.gcube.portlets.user.uriresolvermanager.util.UrlEncoderUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class SHUBResolverCallBuilder.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Nov 8, 2021
*/
public class SHUBResolverCallBuilder extends GenericResolver {
public static final Logger LOG = LoggerFactory.getLogger(SHUBResolverCallBuilder.class);
/**
* Instantiates a new catalogue resolver wrapper.
*
* @param resourceName the resource name
* @param entryName the entry name
*/
public SHUBResolverCallBuilder(String resourceName, String entryName) {
super(resourceName, entryName);
}
/**
* Gets the link.
*
* @param baseURI the base URI
* @param parameters the parameters
* @return the link
* @throws Exception the exception
*/
@Override
public String getLink(String baseURI, Map<String, String> parameters) throws Exception {
LOG.debug("called getLink: " + baseURI + " parameters: "+parameters);
String toReturn = null;
try {
String idValue = parameters.get("id");
String pathURI = baseURI;
if (idValue != null) {
pathURI = String.format("%s/%s", pathURI, idValue);
parameters.remove("id");
}
toReturn = pathURI;
String queryString = UrlEncoderUtil.encodeQuery(parameters);
if(!queryString.isEmpty())
toReturn = String.format("%s?%s", pathURI, queryString);
} catch (Exception e) {
LOG.error(SHUBResolverCallBuilder.class.getSimpleName() + " error: ", e);
throw e;
}
LOG.info("Got Link: " + toReturn);
return toReturn;
}
}

View File

@ -62,7 +62,7 @@ public class UrlEncoderUtil {
String encodedQuery = ""; String encodedQuery = "";
if (theString == null || theString.isEmpty()) if (theString == null || theString.isEmpty())
return theString; return encodedQuery;
try { try {
encodedQuery = URLEncoder.encode(theString, charset); encodedQuery = URLEncoder.encode(theString, charset);

View File

@ -17,9 +17,9 @@ import org.junit.Test;
* *
*/ */
public class UriResolverManagerTest { public class UriResolverManagerTest {
//@Test // @Test
public void testUriResolverManger(){ public void testUriResolverManger() {
UriResolverManager manager; UriResolverManager manager;
try { try {
ScopeProvider.instance.set("/gcube/devsec/devVRE"); ScopeProvider.instance.set("/gcube/devsec/devVRE");
@ -35,29 +35,49 @@ public class UriResolverManagerTest {
} }
} }
//@Test
public void testCTLG(){
try { //@Test
public void testCTLG() {
try {
ScopeProvider.instance.set("/gcube/devsec/devVRE"); ScopeProvider.instance.set("/gcube/devsec/devVRE");
UriResolverManager resolver; UriResolverManager resolver;
resolver = new UriResolverManager("CTLG"); resolver = new UriResolverManager("CTLG");
Map<String, String> params = new HashMap<String, String>(); Map<String, String> params = new HashMap<String, String>();
params.put("gcube_scope","/gcube/devsec/devVRE"); params.put("gcube_scope", "/gcube/devsec/devVRE");
params.put("entity_context","dataset"); params.put("entity_context", "dataset");
params.put("entity_name","sarda-sarda"); params.put("entity_name", "sarda-sarda");
String shortLink = resolver.getLink(params, true); //true, link is shorted otherwise none String shortLink = resolver.getLink(params, true); // true, link is shorted otherwise none
System.out.println(shortLink); System.out.println(shortLink);
} catch (UriResolverMapException e) { } catch (UriResolverMapException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
e.printStackTrace(); e.printStackTrace();
}catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
//@Test
public void testSHUB() {
try {
ScopeProvider.instance.set("/gcube/devsec/devVRE");
UriResolverManager resolver;
resolver = new UriResolverManager("SHUB");
Map<String, String> params = new HashMap<String, String>();
params.put("id", "1dac6703-8eb0-4838-83a8-5006f5074e9b");
params.put("content-disposition", "inline");
String shortLink = resolver.getLink(params, true); // true, link is shorted otherwise none
System.out.println(shortLink);
} catch (UriResolverMapException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
//@Test //@Test
public void testGIS() { public void testGIS() {
@ -69,59 +89,59 @@ public class UriResolverManagerTest {
params.put("gis-UUID", "1a657005-29c6-4528-a115-69640c4c2900"); params.put("gis-UUID", "1a657005-29c6-4528-a115-69640c4c2900");
params.put("scope", "/pred4s/preprod/preVRE"); params.put("scope", "/pred4s/preprod/preVRE");
String shortLink = resolver.getLink(params, false); String shortLink = resolver.getLink(params, false);
System.out.println(shortLink); //true, link is shorted otherwise none System.out.println(shortLink); // true, link is shorted otherwise none
} catch (UriResolverMapException e) { } catch (UriResolverMapException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
e.printStackTrace(); e.printStackTrace();
}catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
// @Test // @Test
public void testSMP() { public void testSMP() {
try { try {
ScopeProvider.instance.set("/gcube/devsec/devVRE"); ScopeProvider.instance.set("/gcube/devsec/devVRE");
UriResolverManager resolver = new UriResolverManager("SMP"); UriResolverManager resolver = new UriResolverManager("SMP");
Map<String, String> params = new HashMap<String, String>(); Map<String, String> params = new HashMap<String, String>();
params.put("smp-uri","smp://Wikipedia_logo_silver.png?5ezvFfBOLqaqBlwCEtAvz4ch5BUu1ag3yftpCvV gayz9bAtSsnO1/sX6pemTKbDe0qbchLexXeWgGcJlskYE8td9QSDXSZj5VSl9kdN9SN0/LRYaWUZuP4Q1J7lEiwkU4GKPsiD6PDRVcT4QAqTEy5hSIbr6o4Y"); params.put("smp-uri",
"smp://Wikipedia_logo_silver.png?5ezvFfBOLqaqBlwCEtAvz4ch5BUu1ag3yftpCvV gayz9bAtSsnO1/sX6pemTKbDe0qbchLexXeWgGcJlskYE8td9QSDXSZj5VSl9kdN9SN0/LRYaWUZuP4Q1J7lEiwkU4GKPsiD6PDRVcT4QAqTEy5hSIbr6o4Y");
params.put("fileName", "wikipediaLogo"); params.put("fileName", "wikipediaLogo");
params.put("contentType", ""); params.put("contentType", "");
String shortLink = resolver.getLink(params, true); //true, link is shorted otherwise none String shortLink = resolver.getLink(params, true); // true, link is shorted otherwise none
System.out.println(shortLink); System.out.println(shortLink);
} catch (UriResolverMapException e) { } catch (UriResolverMapException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
e.printStackTrace(); e.printStackTrace();
}catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
/** /**
* Thread safe * Thread safe
*/ */
// @Test // @Test
public void testSMPID(){ public void testSMPID() {
try { try {
ScopeProvider.instance.set("/gcube/devsec/devVRE"); ScopeProvider.instance.set("/gcube/devsec/devVRE");
UriResolverManager resolver; UriResolverManager resolver;
resolver = new UriResolverManager("SMP-ID"); resolver = new UriResolverManager("SMP-ID");
Map<String, String> params = new HashMap<String, String>(); Map<String, String> params = new HashMap<String, String>();
params.put("geo-exp","553f9265e4b0567b75021fce"); params.put("geo-exp", "553f9265e4b0567b75021fce");
// params.put("fileName", "dog"); // params.put("fileName", "dog");
// params.put("contentType", "image/jpg"); // params.put("contentType", "image/jpg");
String shortLink = resolver.getLink(params, true); //true, link is shorted otherwise none String shortLink = resolver.getLink(params, true); // true, link is shorted otherwise none
System.out.println(shortLink); System.out.println(shortLink);
} catch (UriResolverMapException e) { } catch (UriResolverMapException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
e.printStackTrace(); e.printStackTrace();
}catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -129,45 +149,45 @@ public class UriResolverManagerTest {
/** /**
* Thread safe * Thread safe
*/ */
//@Test // @Test
public void test2(){ public void test2() {
// create thread to print counter value
Thread t = new Thread(new Runnable() {
//create thread to print counter value @Override
Thread t = new Thread(new Runnable() { public void run() {
while (true) {
try {
@Override ScopeProvider.instance.set("/gcube/devsec/devVRE");
public void run() { UriResolverManager resolver;
while (true) {
try {
ScopeProvider.instance.set("/gcube/devsec/devVRE");
UriResolverManager resolver;
resolver = new UriResolverManager("GIS"); resolver = new UriResolverManager("GIS");
Map<String, String> params = new HashMap<String, String>(); Map<String, String> params = new HashMap<String, String>();
params.put("gis-UUID", "eb1a1b63-f324-47ee-9522-b8f5803e19ec"); params.put("gis-UUID", "eb1a1b63-f324-47ee-9522-b8f5803e19ec");
params.put("scope", "/gcube/devsec/devVRE"); params.put("scope", "/gcube/devsec/devVRE");
String shortLink = resolver.getLink(params, true); String shortLink = resolver.getLink(params, true);
System.out.println(shortLink); //true, link is shorted otherwise none System.out.println(shortLink); // true, link is shorted otherwise none
System.out.println("Thread "+Thread.currentThread().getId() +" reading counter is: " + resolver.countReaders()); System.out.println("Thread " + Thread.currentThread().getId() + " reading counter is: "
Thread.sleep(1000); + resolver.countReaders());
} catch (InterruptedException ex) { Thread.sleep(1000);
ex.printStackTrace(); } catch (InterruptedException ex) {
}catch (UriResolverMapException e) { ex.printStackTrace();
} catch (UriResolverMapException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
}); });
t.start(); t.start();
try { try {
Thread.sleep(1000); Thread.sleep(1000);