Merge pull request 'task_22385' (!1) from task_22385 into master
Reviewed-on: #1
This commit is contained in:
commit
0b9c233d71
13
.classpath
13
.classpath
|
@ -6,6 +6,12 @@
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="test" value="true"/>
|
<attribute name="test" value="true"/>
|
||||||
|
@ -13,12 +19,6 @@
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
<attribute name="test" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
@ -30,5 +30,6 @@
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
|
<classpathentry kind="lib" path="/home/francescomangiacrapa/config-work-isti/log4jconfiguration"/>
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -3,6 +3,11 @@
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [v1.5.0-SNAPSHOT] - 2021-11-05
|
||||||
|
|
||||||
|
### Enhancement
|
||||||
|
|
||||||
|
* [22385] Integrated with Catalogue Resolver and SHUB Resolver
|
||||||
|
|
||||||
## [v1.4.2] - 2021-04-21
|
## [v1.4.2] - 2021-04-21
|
||||||
|
|
||||||
|
|
13
pom.xml
13
pom.xml
|
@ -11,7 +11,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.gcube.portlets.user</groupId>
|
<groupId>org.gcube.portlets.user</groupId>
|
||||||
<artifactId>uri-resolver-manager</artifactId>
|
<artifactId>uri-resolver-manager</artifactId>
|
||||||
<version>1.4.2</version>
|
<version>1.5.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>uri-resolver-manager</name>
|
<name>uri-resolver-manager</name>
|
||||||
<description>The URI Resolver Manager</description>
|
<description>The URI Resolver Manager</description>
|
||||||
|
@ -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>
|
||||||
|
@ -101,13 +98,19 @@
|
||||||
<version>20090211</version>
|
<version>20090211</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- LOGGER -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-log4j12</artifactId>
|
||||||
|
<version>1.7.25</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- JUNIT -->
|
<!-- JUNIT -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
|
|
|
@ -14,6 +14,7 @@ import org.gcube.portlets.user.uriresolvermanager.entity.Resolver;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.entity.ServiceAccessPoint;
|
import org.gcube.portlets.user.uriresolvermanager.entity.ServiceAccessPoint;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.entity.ServiceParameter;
|
import org.gcube.portlets.user.uriresolvermanager.entity.ServiceParameter;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
|
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.exception.NotImplementedException;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
|
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.readers.RuntimeResourceReader;
|
import org.gcube.portlets.user.uriresolvermanager.readers.RuntimeResourceReader;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.readers.UriResolverMapReader;
|
import org.gcube.portlets.user.uriresolvermanager.readers.UriResolverMapReader;
|
||||||
|
@ -25,21 +26,10 @@ import org.slf4j.LoggerFactory;
|
||||||
/**
|
/**
|
||||||
* The Class UriResolverManager.
|
* The Class UriResolverManager.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Sep 6, 2016
|
||||||
* Sep 6, 2016
|
|
||||||
*/
|
*/
|
||||||
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;
|
||||||
|
@ -77,13 +67,15 @@ public class UriResolverManager {
|
||||||
return usingReader;
|
return usingReader;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Logger logger = LoggerFactory.getLogger(UriResolverManager.class);
|
public static final Logger LOG = LoggerFactory.getLogger(UriResolverManager.class);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new uri resolver manager.
|
* Instantiates a new uri resolver manager. Precondition: set the scope into
|
||||||
* Precondition: set the scope into ScopeProvider {@link ScopeProvider#get()}
|
* ScopeProvider {@link ScopeProvider#get()} The scope is used to look up the
|
||||||
* The scope is used to look up the generic resource with name: {@link UriResolverMapReader#URI_RESOLVER_MAP_RESOURCE_NAME}, secondary type: {@link UriResolverMapReader#URIRESOLVERMAP_SECONDARY_TYPE} from IS to map ApplicationType with its Resolver
|
* generic resource with name:
|
||||||
|
* {@link UriResolverMapReader#URI_RESOLVER_MAP_RESOURCE_NAME}, secondary type:
|
||||||
|
* {@link UriResolverMapReader#URIRESOLVERMAP_SECONDARY_TYPE} from IS to map
|
||||||
|
* ApplicationType with its Resolver
|
||||||
*
|
*
|
||||||
* @throws UriResolverMapException the uri resolver map exception
|
* @throws UriResolverMapException the uri resolver map exception
|
||||||
* @throws IllegalArgumentException the illegal argument exception
|
* @throws IllegalArgumentException the illegal argument exception
|
||||||
|
@ -92,7 +84,7 @@ public class UriResolverManager {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = ScopeProvider.instance.get();
|
||||||
logger.info("UriResolverManager is using scope: "+scope+", read from ScopeProvider");
|
LOG.info("UriResolverManager is using scope: " + scope + ", read from ScopeProvider");
|
||||||
|
|
||||||
if (scope == null)
|
if (scope == null)
|
||||||
throw new UriResolverMapException("Scope is null, set scope into ScopeProvider!");
|
throw new UriResolverMapException("Scope is null, set scope into ScopeProvider!");
|
||||||
|
@ -101,10 +93,10 @@ public class UriResolverManager {
|
||||||
this.applicationTypes = uriResolverMapReader.getApplicationTypes();
|
this.applicationTypes = uriResolverMapReader.getApplicationTypes();
|
||||||
// this.setTimerUriResolverReader(RESET_DELAY, RESET_TIME);
|
// this.setTimerUriResolverReader(RESET_DELAY, RESET_TIME);
|
||||||
} catch (UriResolverMapException e) {
|
} catch (UriResolverMapException e) {
|
||||||
logger.error("UriResolverMapException: ",e);
|
LOG.error("UriResolverMapException: ", e);
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("UriResolverManager: ",e);
|
LOG.error("UriResolverManager: ", e);
|
||||||
throw new UriResolverMapException("Map Application Type - Resources not found in IS");
|
throw new UriResolverMapException("Map Application Type - Resources not found in IS");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,18 +109,21 @@ public class UriResolverManager {
|
||||||
*/
|
*/
|
||||||
public void setApplicationType(String applicationType) throws IllegalArgumentException {
|
public void setApplicationType(String applicationType) throws IllegalArgumentException {
|
||||||
if (!this.applicationTypes.containsKey(applicationType)) {
|
if (!this.applicationTypes.containsKey(applicationType)) {
|
||||||
throw new IllegalArgumentException("Application type '"+applicationType +"' not found in Application Types: "+getApplicationTypes());
|
throw new IllegalArgumentException("Application type '" + applicationType
|
||||||
|
+ "' not found in Application Types: " + getApplicationTypes());
|
||||||
|
|
||||||
}
|
}
|
||||||
this.applicationType = applicationType;
|
this.applicationType = applicationType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instance a UriResolverManager
|
* Instance a UriResolverManager Precondition: set the scope provider
|
||||||
* Precondition: set the scope provider {@link ScopeProvider.instance.get()}
|
* {@link ScopeProvider.instance.get()} The scope is used to look up the generic
|
||||||
* The scope is used to look up the generic resource {@link UriResolverMapReader#URI_RESOLVER_MAP} available in the infrastructure to map ApplicationType with its Resolver
|
* resource {@link UriResolverMapReader#URI_RESOLVER_MAP} available in the
|
||||||
|
* infrastructure to map ApplicationType with its Resolver
|
||||||
*
|
*
|
||||||
* @param applicationType a (valid) key Application Type {@link UriResolverManager#getApplicationTypes()}
|
* @param applicationType a (valid) key Application Type
|
||||||
|
* {@link UriResolverManager#getApplicationTypes()}
|
||||||
* @throws UriResolverMapException the uri resolver map exception
|
* @throws UriResolverMapException the uri resolver map exception
|
||||||
* @throws IllegalArgumentException the illegal argument exception
|
* @throws IllegalArgumentException the illegal argument exception
|
||||||
*/
|
*/
|
||||||
|
@ -137,8 +132,6 @@ public class UriResolverManager {
|
||||||
setApplicationType(applicationType);
|
setApplicationType(applicationType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the link.
|
* Gets the link.
|
||||||
*
|
*
|
||||||
|
@ -149,7 +142,8 @@ public class UriResolverManager {
|
||||||
* @throws IllegalArgumentException the illegal argument exception
|
* @throws IllegalArgumentException the illegal argument exception
|
||||||
* @throws UriResolverMapException the uri resolver map exception
|
* @throws UriResolverMapException the uri resolver map exception
|
||||||
*/
|
*/
|
||||||
public String getLink(String applicationType, Map<String, String> parameters, boolean shortLink) throws IllegalArgumentException, UriResolverMapException{
|
public String getLink(String applicationType, Map<String, String> parameters, boolean shortLink)
|
||||||
|
throws IllegalArgumentException, UriResolverMapException {
|
||||||
this.applicationType = applicationType;
|
this.applicationType = applicationType;
|
||||||
return getLink(parameters, shortLink);
|
return getLink(parameters, shortLink);
|
||||||
}
|
}
|
||||||
|
@ -163,13 +157,14 @@ public class UriResolverManager {
|
||||||
* @throws IllegalArgumentException the illegal argument exception
|
* @throws IllegalArgumentException the illegal argument exception
|
||||||
* @throws UriResolverMapException the uri resolver map exception
|
* @throws UriResolverMapException the uri resolver map exception
|
||||||
*/
|
*/
|
||||||
public String getLink(Map<String, String> parameters, boolean shortLink) throws IllegalArgumentException, UriResolverMapException{
|
public String getLink(Map<String, String> parameters, boolean shortLink)
|
||||||
|
throws IllegalArgumentException, UriResolverMapException {
|
||||||
|
|
||||||
if (applicationType == null)
|
if (applicationType == null)
|
||||||
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");
|
||||||
|
@ -179,86 +174,119 @@ public class UriResolverManager {
|
||||||
// lockReader();
|
// lockReader();
|
||||||
|
|
||||||
if (reader == null) {
|
if (reader == null) {
|
||||||
logger.info("Runtime Resource Reader is null, istancing...");
|
LOG.info("Runtime Resource Reader is null, istancing...");
|
||||||
reader = new RuntimeResourceReader(resolver.getResourceName());
|
reader = new RuntimeResourceReader(resolver.getResourceName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resolver.getEntryName() == null || resolver.getEntryName().isEmpty()) {
|
if (resolver.getEntryName() == null || resolver.getEntryName().isEmpty()) {
|
||||||
logger.warn("The entryname to "+resolver.getResourceName() +" is null or empty, reading first Access Point!!");
|
LOG.warn("The entryname to " + resolver.getResourceName()
|
||||||
|
+ " is null or empty, reading first Access Point!!");
|
||||||
serviceAccessPoint = reader.getServiceAccessPoints().get(0);
|
serviceAccessPoint = reader.getServiceAccessPoints().get(0);
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Reading Access Point for Entry Name: "+resolver.getEntryName());
|
LOG.warn("Reading Access Point for Entry Name: " + resolver.getEntryName());
|
||||||
serviceAccessPoint = reader.getServiceAccessPointForEntryName(resolver.getEntryName());
|
serviceAccessPoint = reader.getServiceAccessPointForEntryName(resolver.getEntryName());
|
||||||
if (serviceAccessPoint == null)
|
if (serviceAccessPoint == null)
|
||||||
throw new UriResolverMapException("Entry Name "+resolver.getEntryName() +" not found in Resource name: "+resolver.getResourceName());
|
throw new UriResolverMapException("Entry Name " + resolver.getEntryName()
|
||||||
|
+ " not found in Resource name: " + resolver.getResourceName());
|
||||||
}
|
}
|
||||||
|
|
||||||
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()) {
|
||||||
if (!parameters.containsKey(serviceParameter.getKey())) {
|
if (!parameters.containsKey(serviceParameter.getKey())) {
|
||||||
throw new IllegalArgumentException("Mandatory service key (parameter) '"+serviceParameter.getKey() +"' not found into input map");
|
throw new IllegalArgumentException("Mandatory service key (parameter) '"
|
||||||
|
+ serviceParameter.getKey() + "' not found into input map");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String baseURI = serviceAccessPoint.getServiceUrl();
|
String baseURI = serviceAccessPoint.getServiceUrl();
|
||||||
//Encoding only the query string
|
|
||||||
|
try {
|
||||||
|
link = resolver.getLink(baseURI, parameters);
|
||||||
|
if (shortLink)
|
||||||
|
return shortTheLink(link);
|
||||||
|
|
||||||
|
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 parameters encoded
|
// not shortening so returning the link with the query string with only the
|
||||||
|
// 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);
|
||||||
logger.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;
|
||||||
logger.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);
|
||||||
logger.info("Encoded link is: "+link);
|
LOG.info("Encoded link is: " + link);
|
||||||
logger.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);
|
||||||
logger.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
|
||||||
// so the shortening did not work
|
// so the shortening did not work
|
||||||
// I'm returning the decoded link because it is directly consumable via browser
|
// I'm returning the decoded link because it is directly consumable via browser
|
||||||
logger.debug("Shorted link is equal to input link, returning decoded link: "+linkDecoded);
|
LOG.debug("Shorted link is equal to input link, returning decoded link: " + linkDecoded);
|
||||||
link = linkDecoded;
|
link = linkDecoded;
|
||||||
} else {
|
} else {
|
||||||
// here the link is really shorted
|
// here the link is really shorted
|
||||||
logger.debug("The link is really shorted, returning it");
|
LOG.debug("The link is really shorted, returning it");
|
||||||
link = shortedLink;
|
link = shortedLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.warn("An error occurred during link shortening: ",e);
|
LOG.warn("An error occurred during link shortening: ", e);
|
||||||
// here I'm returning the decoded link in case of error on shortening it
|
// here I'm returning the decoded link in case of error on shortening it
|
||||||
link = linkDecoded;
|
link = linkDecoded;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
logger.error("Uri Resolver IllegalArgumentException: ", e);
|
LOG.error("Uri Resolver IllegalArgumentException: ", e);
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Uri Resolver Exception: ", e);
|
LOG.error("Uri Resolver Exception: ", e);
|
||||||
throw new UriResolverMapException("Uri Resolver error: " + e.getMessage());
|
throw new UriResolverMapException("Uri Resolver error: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
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.
|
||||||
*
|
*
|
||||||
|
@ -276,11 +304,12 @@ public class UriResolverManager {
|
||||||
* @throws IllegalArgumentException the illegal argument exception
|
* @throws IllegalArgumentException the illegal argument exception
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public List<ServiceParameter> discoveryServiceParameters(Resolver resolver) throws IllegalArgumentException, Exception{
|
public List<ServiceParameter> discoveryServiceParameters(Resolver resolver)
|
||||||
|
throws IllegalArgumentException, Exception {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = ScopeProvider.instance.get();
|
||||||
logger.info("SiscoveryServiceParameters is using scope: "+scope+", read from ScopeProvider");
|
LOG.info("SiscoveryServiceParameters is using scope: " + scope + ", read from ScopeProvider");
|
||||||
|
|
||||||
if (scope == null)
|
if (scope == null)
|
||||||
throw new UriResolverMapException("Scope is null, set scope into ScopeProvider!");
|
throw new UriResolverMapException("Scope is null, set scope into ScopeProvider!");
|
||||||
|
@ -292,18 +321,20 @@ public class UriResolverManager {
|
||||||
|
|
||||||
ServiceAccessPoint serviceAccessPoint = null;
|
ServiceAccessPoint serviceAccessPoint = null;
|
||||||
if (resolver.getEntryName() == null || resolver.getEntryName().isEmpty()) {
|
if (resolver.getEntryName() == null || resolver.getEntryName().isEmpty()) {
|
||||||
logger.warn("The entryname to "+resolver.getResourceName() +" is null or empty, reading first Access Point!!");
|
LOG.warn("The entryname to " + resolver.getResourceName()
|
||||||
|
+ " is null or empty, reading first Access Point!!");
|
||||||
serviceAccessPoint = reader.getServiceAccessPoints().get(0);
|
serviceAccessPoint = reader.getServiceAccessPoints().get(0);
|
||||||
} else {
|
} else {
|
||||||
logger.info("Reading Access Point for entryname: "+resolver.getEntryName());
|
LOG.info("Reading Access Point for entryname: " + resolver.getEntryName());
|
||||||
serviceAccessPoint = reader.getServiceAccessPointForEntryName(resolver.getEntryName());
|
serviceAccessPoint = reader.getServiceAccessPointForEntryName(resolver.getEntryName());
|
||||||
if (serviceAccessPoint == null)
|
if (serviceAccessPoint == null)
|
||||||
throw new UriResolverMapException("Entry Name "+resolver.getEntryName() +" not found in Resource name: "+resolver.getResourceName());
|
throw new UriResolverMapException("Entry Name " + resolver.getEntryName()
|
||||||
|
+ " not found in Resource name: " + resolver.getResourceName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return serviceAccessPoint.getServiceParameters();
|
return serviceAccessPoint.getServiceParameters();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Uri Resolver error: ", e);
|
LOG.error("Uri Resolver error: ", e);
|
||||||
throw new UriResolverMapException("Uri Resolver error: " + e.getMessage());
|
throw new UriResolverMapException("Uri Resolver error: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -342,20 +373,18 @@ public class UriResolverManager {
|
||||||
timer.schedule(new TimerTask() {
|
timer.schedule(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
logger.info("Timer Reset Runtime Resource running..");
|
LOG.info("Timer Reset Runtime Resource running..");
|
||||||
int counters = countReaders();
|
int counters = countReaders();
|
||||||
if (counters == 0) {
|
if (counters == 0) {
|
||||||
logger.info("Reader not locked, resetting");
|
LOG.info("Reader not locked, resetting");
|
||||||
reader = null;
|
reader = null;
|
||||||
} else
|
} else
|
||||||
logger.info("Reader locked, counters is/are:"+counters+", skipping");
|
LOG.info("Reader locked, counters is/are:" + counters + ", skipping");
|
||||||
|
|
||||||
}
|
}
|
||||||
}, delay, period);
|
}, delay, period);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel timer uri resolver reader.
|
* Cancel timer uri resolver reader.
|
||||||
*/
|
*/
|
||||||
|
@ -364,7 +393,6 @@ public class UriResolverManager {
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalid uri resolver reader.
|
* Invalid uri resolver reader.
|
||||||
*/
|
*/
|
||||||
|
@ -372,15 +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();
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,101 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.portlets.user.uriresolvermanager.entity;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.exception.NotImplementedException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class Resolver.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it May 4, 2015
|
||||||
|
*/
|
||||||
|
public class GenericResolver implements Resolver {
|
||||||
|
|
||||||
|
private String resourceName;
|
||||||
|
private String entryName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new resolver.
|
||||||
|
*
|
||||||
|
* @param resourceName the resource name
|
||||||
|
* @param entryName the entry name
|
||||||
|
*/
|
||||||
|
public GenericResolver(String resourceName, String entryName) {
|
||||||
|
super();
|
||||||
|
this.resourceName = resourceName;
|
||||||
|
this.entryName = entryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the resource name.
|
||||||
|
*
|
||||||
|
* @return the resourceName
|
||||||
|
*/
|
||||||
|
public String getResourceName() {
|
||||||
|
return resourceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the entry name.
|
||||||
|
*
|
||||||
|
* @return the entryName
|
||||||
|
*/
|
||||||
|
public String getEntryName() {
|
||||||
|
return entryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the resource name.
|
||||||
|
*
|
||||||
|
* @param resourceName the resourceName to set
|
||||||
|
*/
|
||||||
|
public void setResourceName(String resourceName) {
|
||||||
|
this.resourceName = resourceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the entry name.
|
||||||
|
*
|
||||||
|
* @param entryName the entryName to set
|
||||||
|
*/
|
||||||
|
public void setEntryName(String entryName) {
|
||||||
|
this.entryName = entryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the link.
|
||||||
|
*
|
||||||
|
* @param baseURI the base URI
|
||||||
|
* @param parameters the parameters
|
||||||
|
* @return the link
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
public String getLink(String baseURI, Map<String, String> parameters) throws Exception{
|
||||||
|
throw new NotImplementedException("getLink Method not Implement");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To string.
|
||||||
|
*
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see java.lang.Object#toString()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("Resolver [resourceName=");
|
||||||
|
builder.append(resourceName);
|
||||||
|
builder.append(", entryName=");
|
||||||
|
builder.append(entryName);
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,78 +1,38 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.gcube.portlets.user.uriresolvermanager.entity;
|
package org.gcube.portlets.user.uriresolvermanager.entity;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class Resolver.
|
* The Interface Resolver.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
* May 4, 2015
|
|
||||||
*/
|
|
||||||
public class Resolver {
|
|
||||||
|
|
||||||
private String resourceName;
|
|
||||||
private String entryName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new resolver.
|
|
||||||
*
|
*
|
||||||
* @param resourceName the resource name
|
* Nov 5, 2021
|
||||||
* @param entryName the entry name
|
|
||||||
*/
|
*/
|
||||||
public Resolver(String resourceName, String entryName) {
|
public interface Resolver {
|
||||||
super();
|
|
||||||
this.resourceName = resourceName;
|
|
||||||
this.entryName = entryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the resource name.
|
* Gets the resource name.
|
||||||
*
|
*
|
||||||
* @return the resourceName
|
* @return the resource name
|
||||||
*/
|
*/
|
||||||
public String getResourceName() {
|
public String getResourceName();
|
||||||
return resourceName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the entry name.
|
* Gets the entry name.
|
||||||
*
|
*
|
||||||
* @return the entryName
|
* @return the entry name
|
||||||
*/
|
*/
|
||||||
public String getEntryName() {
|
public String getEntryName();
|
||||||
return entryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the resource name.
|
* Gets the link.
|
||||||
*
|
*
|
||||||
* @param resourceName the resourceName to set
|
* @param baseURI the base URI
|
||||||
|
* @param parameters the parameters
|
||||||
|
* @return the link
|
||||||
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public void setResourceName(String resourceName) {
|
public String getLink(String baseURI, Map<String, String> parameters) throws Exception;
|
||||||
this.resourceName = resourceName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the entry name.
|
|
||||||
*
|
|
||||||
* @param entryName the entryName to set
|
|
||||||
*/
|
|
||||||
public void setEntryName(String entryName) {
|
|
||||||
this.entryName = entryName;
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see java.lang.Object#toString()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append("Resolver [resourceName=");
|
|
||||||
builder.append(resourceName);
|
|
||||||
builder.append(", entryName=");
|
|
||||||
builder.append(entryName);
|
|
||||||
builder.append("]");
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package org.gcube.portlets.user.uriresolvermanager.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class NotImplementedException.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Nov 5, 2021
|
||||||
|
*/
|
||||||
|
public class NotImplementedException extends Exception {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -7350078577553202213L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new not implemented exception.
|
||||||
|
*/
|
||||||
|
public NotImplementedException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new not implemented exception.
|
||||||
|
*
|
||||||
|
* @param message the message
|
||||||
|
*/
|
||||||
|
public NotImplementedException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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.
|
||||||
*
|
*
|
||||||
|
@ -63,7 +60,7 @@ public class RuntimeResourceReader {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = ScopeProvider.instance.get();
|
||||||
logger.info("Tentative read resource: "+resourceName+", scope: "+scope);
|
logger.info("Trying to read resource: " + resourceName + ", in the scope: " + scope);
|
||||||
|
|
||||||
this.resourceName = resourceName;
|
this.resourceName = resourceName;
|
||||||
|
|
||||||
|
@ -73,17 +70,21 @@ public class RuntimeResourceReader {
|
||||||
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());
|
||||||
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
logger.debug("Found properties: " + serviceAccessPoints);
|
||||||
// parameters.setUser(ap.username()); //username
|
// parameters.setUser(ap.username()); //username
|
||||||
//
|
// String decryptedPassword =
|
||||||
// String decryptedPassword = StringEncrypter.getEncrypter().decrypt(ap.password());
|
// StringEncrypter.getEncrypter().decrypt(ap.password());
|
||||||
//
|
|
||||||
// parameters.setPassword(decryptedPassword); //password
|
// parameters.setPassword(decryptedPassword); //password
|
||||||
// Group<Property> properties = ap.properties();
|
// Group<Property> properties = ap.properties();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Sorry, an error occurred on reading the resource " + resourceName + " Runtime Resource", 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");
|
throw new Exception(
|
||||||
|
"Sorry, an error occurred on reading the resource " + resourceName + " Runtime Reosurce");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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");
|
||||||
|
|
|
@ -12,7 +12,10 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
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.Resolver;
|
import org.gcube.portlets.user.uriresolvermanager.entity.Resolver;
|
||||||
|
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;
|
||||||
|
@ -21,12 +24,10 @@ import org.slf4j.LoggerFactory;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class UriResolverMapReader.
|
* The Class UriResolverMapReader.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it May 4, 2015
|
||||||
* May 4, 2015
|
|
||||||
*/
|
*/
|
||||||
public class UriResolverMapReader {
|
public class UriResolverMapReader {
|
||||||
|
|
||||||
|
@ -36,15 +37,15 @@ public class UriResolverMapReader {
|
||||||
public static final String URIRESOLVERMAP_SECONDARY_TYPE = "UriResolverMap";
|
public static final String URIRESOLVERMAP_SECONDARY_TYPE = "UriResolverMap";
|
||||||
public static final String URI_RESOLVER_MAP_RESOURCE_NAME = "Uri-Resolver-Map";
|
public static final String URI_RESOLVER_MAP_RESOURCE_NAME = "Uri-Resolver-Map";
|
||||||
|
|
||||||
// private Logger logger = LoggerFactory.getLogger(UriResolverMapReader.class);
|
// private Logger LOG = LoggerFactory.getLogger(UriResolverMapReader.class);
|
||||||
//TODO TEMP SOLUTION IN ORDER TO PRINT USING ALSO LOG4J INTO GEOEXPLORER PORTLET
|
// TODO TEMP SOLUTION IN ORDER TO PRINT USING ALSO LOG4J INTO GEOEXPLORER
|
||||||
|
// PORTLET
|
||||||
private Logger logger = LoggerFactory.getLogger(UriResolverMapReader.class);
|
private Logger logger = LoggerFactory.getLogger(UriResolverMapReader.class);
|
||||||
private String secondaryType;
|
private String secondaryType;
|
||||||
private String scope;
|
private String scope;
|
||||||
private String resourceName;
|
private String resourceName;
|
||||||
private Map<String, Resolver> applicationTypes; // A map ApplicationType - Resolver
|
private Map<String, Resolver> applicationTypes; // A map ApplicationType - Resolver
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new uri resolver map reader.
|
* Instantiates a new uri resolver map reader.
|
||||||
*
|
*
|
||||||
|
@ -57,10 +58,11 @@ public class UriResolverMapReader {
|
||||||
readProfileFromInfrastrucure();
|
readProfileFromInfrastrucure();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this method looks up the generic resource among the ones available in the infrastructure using scope provider {@link ScopeProvider.instance.get()}
|
* this method looks up the generic resource among the ones available in the
|
||||||
* resource name {@value #URI_RESOLVER_MAP_RESOURCE_NAME} and secondaryType {@value #URIRESOLVERMAP_SECONDARY_TYPE}
|
* infrastructure using scope provider {@link ScopeProvider.instance.get()}
|
||||||
|
* resource name {@value #URI_RESOLVER_MAP_RESOURCE_NAME} and secondaryType
|
||||||
|
* {@value #URIRESOLVERMAP_SECONDARY_TYPE}
|
||||||
*
|
*
|
||||||
* @return the applicationProfile profile
|
* @return the applicationProfile profile
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
|
@ -69,7 +71,8 @@ public class UriResolverMapReader {
|
||||||
|
|
||||||
String queryString = getGcubeGenericQueryString(secondaryType, resourceName);
|
String queryString = getGcubeGenericQueryString(secondaryType, resourceName);
|
||||||
|
|
||||||
logger.info("Trying to fetch in the scope: "+ScopeProvider.instance.get()+" the Generic Resouce with name: "+resourceName + " secondary type: "+secondaryType);
|
logger.info("Trying to fetch in the scope: " + ScopeProvider.instance.get() + " the Generic Resouce with name: "
|
||||||
|
+ resourceName + " secondary type: " + secondaryType);
|
||||||
logger.info(queryString);
|
logger.info(queryString);
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -82,8 +85,11 @@ public class UriResolverMapReader {
|
||||||
logger.debug("submit query works");
|
logger.debug("submit query works");
|
||||||
|
|
||||||
if (appUriResolverMap == null || appUriResolverMap.size() == 0) {
|
if (appUriResolverMap == null || appUriResolverMap.size() == 0) {
|
||||||
logger.error("ApplicationProfile with secondaryType: "+secondaryType+" and name: "+resourceName+" is not registered in the infrastructure, scope: "+ScopeProvider.instance.get());
|
logger.error("ApplicationProfile with secondaryType: " + secondaryType + " and name: " + resourceName
|
||||||
throw new ApplicationProfileException("ApplicationProfile with secondaryType: "+secondaryType+" and name: "+resourceName+" is not registered in the scope: "+ScopeProvider.instance.get());
|
+ " is not registered in the infrastructure, scope: " + ScopeProvider.instance.get());
|
||||||
|
throw new ApplicationProfileException(
|
||||||
|
"ApplicationProfile with secondaryType: " + secondaryType + " and name: " + resourceName
|
||||||
|
+ " is not registered in the scope: " + ScopeProvider.instance.get());
|
||||||
} else {
|
} else {
|
||||||
logger.info("Building map applications type - resource");
|
logger.info("Building map applications type - resource");
|
||||||
logger.debug("Building new DocumentBuilder..");
|
logger.debug("Building new DocumentBuilder..");
|
||||||
|
@ -103,10 +109,21 @@ public class UriResolverMapReader {
|
||||||
for (String at : currValue) {
|
for (String at : currValue) {
|
||||||
logger.info("Application Type " + at);
|
logger.info("Application Type " + at);
|
||||||
// currValue = helper.evaluate("/Resource/Profile/Body/EndPoint[Scope='"+scope.toString()+"']/Scope/text()");
|
// currValue = helper.evaluate("/Resource/Profile/Body/EndPoint[Scope='"+scope.toString()+"']/Scope/text()");
|
||||||
List<String> resources = helper.evaluate("/Resource/Profile/Body/access_point[application_type='"+at+"']/resource/text()");
|
List<String> resources = helper.evaluate(
|
||||||
List<String> entryNames = helper.evaluate("/Resource/Profile/Body/access_point[application_type='"+at+"']/entryname/text()");
|
"/Resource/Profile/Body/access_point[application_type='" + at + "']/resource/text()");
|
||||||
|
List<String> entryNames = helper.evaluate(
|
||||||
|
"/Resource/Profile/Body/access_point[application_type='" + at + "']/entryname/text()");
|
||||||
if (resources != null && resources.size() > 0) {
|
if (resources != null && resources.size() > 0) {
|
||||||
Resolver resolver = new Resolver(resources.get(0), entryNames.get(0));
|
String resoureName = resources.get(0);
|
||||||
|
String entryName = entryNames.get(0);
|
||||||
|
Resolver resolver;
|
||||||
|
if (entryName.equalsIgnoreCase("ctlg")) {
|
||||||
|
resolver = new CatalogueResolverCallBuilder(resoureName, entryName);
|
||||||
|
} else if (entryName.equalsIgnoreCase("shub")) {
|
||||||
|
resolver = new SHUBResolverCallBuilder(resoureName, entryName);
|
||||||
|
} else {
|
||||||
|
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
|
||||||
|
@ -116,8 +133,10 @@ public class UriResolverMapReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Error while trying to fetch Generic Resource with secondaryType: "+secondaryType+" and name "+resourceName+" from the infrastructure", e);
|
logger.error("Error while trying to fetch Generic Resource with secondaryType: " + secondaryType
|
||||||
throw new ApplicationProfileException("Error while trying to fetch Generic Resourc with secondaryType: "+secondaryType+" and name "+resourceName+" from the infrastructure");
|
+ " and name " + resourceName + " from the infrastructure", e);
|
||||||
|
throw new ApplicationProfileException("Error while trying to fetch Generic Resourc with secondaryType: "
|
||||||
|
+ secondaryType + " and name " + resourceName + " from the infrastructure");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -131,10 +150,9 @@ public class UriResolverMapReader {
|
||||||
*/
|
*/
|
||||||
public static String getGcubeGenericQueryString(String secondaryType, String name) {
|
public static String getGcubeGenericQueryString(String secondaryType, String name) {
|
||||||
|
|
||||||
return "for $profile in collection('/db/Profiles/GenericResource')//Resource " +
|
return "for $profile in collection('/db/Profiles/GenericResource')//Resource "
|
||||||
"where $profile/Profile/SecondaryType/string() eq '"+secondaryType+"' and $profile/Profile/Name/string() " +
|
+ "where $profile/Profile/SecondaryType/string() eq '" + secondaryType
|
||||||
" eq '" + name + "'" +
|
+ "' and $profile/Profile/Name/string() " + " eq '" + name + "'" + "return $profile";
|
||||||
"return $profile";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +174,6 @@ public class UriResolverMapReader {
|
||||||
return secondaryType;
|
return secondaryType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the scope.
|
* Gets the scope.
|
||||||
*
|
*
|
||||||
|
@ -175,7 +192,9 @@ public class UriResolverMapReader {
|
||||||
return resourceName;
|
return resourceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,128 @@
|
||||||
|
package org.gcube.portlets.user.uriresolvermanager.resolvers;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.entity.GenericResolver;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class CatalogueResolverCallBuilder.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Nov 5, 2021
|
||||||
|
*/
|
||||||
|
public class CatalogueResolverCallBuilder extends GenericResolver {
|
||||||
|
|
||||||
|
private static final int _60SEC = 60000;
|
||||||
|
public static final Logger LOG = LoggerFactory.getLogger(CatalogueResolverCallBuilder.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new catalogue resolver wrapper.
|
||||||
|
*
|
||||||
|
* @param resourceName the resource name
|
||||||
|
* @param entryName the entry name
|
||||||
|
*/
|
||||||
|
public CatalogueResolverCallBuilder(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);
|
||||||
|
|
||||||
|
HttpURLConnection con = null;
|
||||||
|
String theResponse = null;
|
||||||
|
try {
|
||||||
|
|
||||||
|
URL urlObj = new URL(baseURI);
|
||||||
|
con = (HttpURLConnection) urlObj.openConnection();
|
||||||
|
con.setRequestMethod("POST");
|
||||||
|
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
||||||
|
// con.setRequestProperty("Accept", "application/json");
|
||||||
|
|
||||||
|
con.setDoOutput(true);
|
||||||
|
con.setReadTimeout(_60SEC);
|
||||||
|
con.setConnectTimeout(_60SEC);
|
||||||
|
|
||||||
|
JSONObject jObj = new org.json.JSONObject();
|
||||||
|
for (String key : parameters.keySet()) {
|
||||||
|
jObj.put(key, parameters.get(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
String toJSON = jObj.toString();
|
||||||
|
LOG.info("Submitting JSON: " + toJSON);
|
||||||
|
Integer code = null;
|
||||||
|
try {
|
||||||
|
|
||||||
|
OutputStream os = con.getOutputStream();
|
||||||
|
os.write(toJSON.getBytes("UTF-8"));
|
||||||
|
os.close();
|
||||||
|
|
||||||
|
code = con.getResponseCode();
|
||||||
|
theResponse = readResponse(con.getInputStream());
|
||||||
|
|
||||||
|
if (!((200 <= code) && (code <= 208))) {
|
||||||
|
throw new Exception("CatalogueResolver returned code: " + code + ". Response is: " + theResponse);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
theResponse = readResponse(con.getInputStream());
|
||||||
|
LOG.error("CatalogueResolver returned code: " + code + ". Response is: " + theResponse);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error(CatalogueResolverCallBuilder.class.getSimpleName() + " error: ", e);
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (con != null)
|
||||||
|
con.disconnect();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// silent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOG.info("Got Link: " + theResponse);
|
||||||
|
return theResponse;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read response.
|
||||||
|
*
|
||||||
|
* @param ris the ris
|
||||||
|
* @return the string
|
||||||
|
* @throws IOException Signals that an I/O exception has occurred.
|
||||||
|
*/
|
||||||
|
private String readResponse(InputStream ris) throws IOException {
|
||||||
|
// Receive the response from the server
|
||||||
|
InputStream in = new BufferedInputStream(ris);
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
result.append(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,22 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.gcube.portlets.user.uriresolvermanager.resolvers;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
||||||
* @Oct 14, 2014
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class GisResolverManager implements LinkResolver{
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.gcube.portlets.user.uriresolvermanager.LinkResolver#getLink()
|
|
||||||
*/
|
|
||||||
public String getLink() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.gcube.portlets.user.uriresolvermanager.resolvers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
||||||
* @Oct 14, 2014
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface LinkResolver {
|
|
||||||
String getLink();
|
|
||||||
}
|
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class HttpRequestUtil {
|
||||||
}else
|
}else
|
||||||
logger.warn("status code is "+code+" - on url connection: "+urlConn);
|
logger.warn("status code is "+code+" - on url connection: "+urlConn);
|
||||||
|
|
||||||
// logger.trace("result: "+result);
|
// LOG.trace("result: "+result);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
logger.error("error - not a http request!");
|
logger.error("error - not a http request!");
|
||||||
|
|
|
@ -6,10 +6,6 @@ import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
|
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
|
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
* @Oct 20, 2014
|
* @Oct 20, 2014
|
||||||
|
@ -21,7 +17,7 @@ public class UriResolverManagerTest {
|
||||||
public void testUriResolverManger() {
|
public void testUriResolverManger() {
|
||||||
UriResolverManager manager;
|
UriResolverManager manager;
|
||||||
try {
|
try {
|
||||||
ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab");
|
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
||||||
manager = new UriResolverManager();
|
manager = new UriResolverManager();
|
||||||
System.out.println(manager.getCapabilities());
|
System.out.println(manager.getCapabilities());
|
||||||
System.out.println(manager.getApplicationTypes());
|
System.out.println(manager.getApplicationTypes());
|
||||||
|
@ -35,6 +31,49 @@ public class UriResolverManagerTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Test
|
||||||
|
public void testCTLG() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
||||||
|
UriResolverManager resolver;
|
||||||
|
resolver = new UriResolverManager("CTLG");
|
||||||
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
|
params.put("gcube_scope", "/gcube/devsec/devVRE");
|
||||||
|
params.put("entity_context", "dataset");
|
||||||
|
params.put("entity_name", "sarda-sarda");
|
||||||
|
String shortLink = resolver.getLink(params, true);
|
||||||
|
System.out.println(shortLink);
|
||||||
|
} catch (UriResolverMapException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (Exception e) {
|
||||||
|
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);
|
||||||
|
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() {
|
||||||
|
|
||||||
|
@ -45,7 +84,7 @@ 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);
|
||||||
} catch (UriResolverMapException e) {
|
} catch (UriResolverMapException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
@ -62,7 +101,8 @@ public class UriResolverManagerTest {
|
||||||
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
|
||||||
|
@ -76,7 +116,6 @@ public class UriResolverManagerTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thread safe
|
* Thread safe
|
||||||
*/
|
*/
|
||||||
|
@ -108,7 +147,6 @@ public class UriResolverManagerTest {
|
||||||
// @Test
|
// @Test
|
||||||
public void test2() {
|
public void test2() {
|
||||||
|
|
||||||
|
|
||||||
// create thread to print counter value
|
// create thread to print counter value
|
||||||
Thread t = new Thread(new Runnable() {
|
Thread t = new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@ -127,7 +165,8 @@ public class UriResolverManagerTest {
|
||||||
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: "
|
||||||
|
+ resolver.countReaders());
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
|
|
Loading…
Reference in New Issue