added uri shortener
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/uri-resolver-manager@100696 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
1767471cae
commit
0066d24180
28
pom.xml
28
pom.xml
|
@ -1,16 +1,16 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<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.0.0-SNAPSHOT</version>
|
<version>1.0.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>
|
||||||
<scm>
|
<scm>
|
||||||
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/${project.artifactId}</url>
|
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/${project.artifactId}</url>
|
||||||
</scm>
|
</scm>
|
||||||
|
@ -71,11 +71,19 @@
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- END FWS -->
|
<!-- END FWS -->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.portlets.user</groupId>
|
||||||
|
<artifactId>gcube-url-shortener</artifactId>
|
||||||
|
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-httpclient</groupId>
|
<groupId>commons-httpclient</groupId>
|
||||||
<artifactId>commons-httpclient</artifactId>
|
<artifactId>commons-httpclient</artifactId>
|
||||||
<version>3.1</version>
|
<version>3.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -15,6 +15,7 @@ import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapExcept
|
||||||
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;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.util.UrlEncoderUtil;
|
import org.gcube.portlets.user.uriresolvermanager.util.UrlEncoderUtil;
|
||||||
|
import org.gcube.portlets.user.urlshortener.UrlShortener;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -30,9 +31,9 @@ public class UriResolverManager {
|
||||||
private Map<String, String> applicationTypes;
|
private Map<String, String> applicationTypes;
|
||||||
private String scope;
|
private String scope;
|
||||||
private String applicationType;
|
private String applicationType;
|
||||||
private Object infra;
|
|
||||||
|
|
||||||
public static final Logger logger = LoggerFactory.getLogger(UriResolverManager.class);
|
public static final Logger logger = LoggerFactory.getLogger(UriResolverManager.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instance a UriResolverManager
|
* Instance a UriResolverManager
|
||||||
* Precondition: set the scope provider {@link ScopeProvider.instance.get()}
|
* Precondition: set the scope provider {@link ScopeProvider.instance.get()}
|
||||||
|
@ -64,9 +65,18 @@ public class UriResolverManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLink(Map<String, String> parameters) throws IllegalArgumentException, UriResolverMapException{
|
/**
|
||||||
|
*
|
||||||
|
* @param parameters the map of the parameters sent with HTTP request (link) generated
|
||||||
|
* @param shortLink if true the link is shorted otherwise none
|
||||||
|
* @return
|
||||||
|
* @throws IllegalArgumentException
|
||||||
|
* @throws UriResolverMapException
|
||||||
|
*/
|
||||||
|
public String getLink(Map<String, String> parameters, boolean shortLink) throws IllegalArgumentException, UriResolverMapException{
|
||||||
|
|
||||||
String resourceName = this.applicationTypes.get(applicationType);
|
String resourceName = this.applicationTypes.get(applicationType);
|
||||||
|
String link;
|
||||||
|
|
||||||
if(parameters==null){
|
if(parameters==null){
|
||||||
throw new IllegalArgumentException("Input Map parameters is null");
|
throw new IllegalArgumentException("Input Map parameters is null");
|
||||||
|
@ -89,26 +99,31 @@ public class UriResolverManager {
|
||||||
String baseURI = reader.getServiceBaseURI();
|
String baseURI = reader.getServiceBaseURI();
|
||||||
|
|
||||||
String params = UrlEncoderUtil.encodeQuery(parameters);
|
String params = UrlEncoderUtil.encodeQuery(parameters);
|
||||||
String uriRequest = reader.getServiceBaseURI()+"?"+params;
|
link = baseURI+"?"+params;
|
||||||
logger.info("Created HTTP URI request: "+uriRequest);
|
logger.info("Created HTTP URI request (link): "+link);
|
||||||
|
|
||||||
// baseURI = "http://pc-mangiacrapa.isti.cnr.it:8080/uri-resolver-1.2.0-SNAPSHOT/gis";
|
|
||||||
//
|
|
||||||
// HttpCallerUtil httpCaller = new HttpCallerUtil(baseURI, "", "");
|
|
||||||
// httpCaller.callGet("", parameters);
|
|
||||||
|
|
||||||
|
if(shortLink){
|
||||||
|
try{
|
||||||
|
logger.info("Shortner start..");
|
||||||
|
UrlShortener shortener = new UrlShortener(this.scope);
|
||||||
|
link = shortener.shorten(link);
|
||||||
|
logger.info("Shorted link is: "+link);
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.warn("An error occurred on shortener the link ",e);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (IllegalArgumentException e){
|
} catch (IllegalArgumentException e){
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Uri Resolver error: ", e);
|
logger.error("Uri Resolver error: ", e);
|
||||||
throw new UriResolverMapException("Uri Resolver error: " +e.getMessage());
|
throw new UriResolverMapException("Uri Resolver error: " +e.getMessage());
|
||||||
}
|
}
|
||||||
return "";
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return the Application Types availables
|
* @return the Application Types available
|
||||||
*/
|
*/
|
||||||
public Set<String> getApplicationTypes(){
|
public Set<String> getApplicationTypes(){
|
||||||
return this.applicationTypes.keySet();
|
return this.applicationTypes.keySet();
|
||||||
|
@ -126,11 +141,12 @@ public class UriResolverManager {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
||||||
UriResolverManager resolver = new UriResolverManager("GIS");
|
UriResolverManager resolver = new UriResolverManager("SMP");
|
||||||
Map<String, String> params = new HashMap<String, String>();
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
params.put("gis-UUID", "12345");
|
params.put("smp-uri", "12345");
|
||||||
params.put("scope", "/gcube");
|
params.put("fileName", "/gcube");
|
||||||
resolver.getLink(params);
|
params.put("contentType", "/gcube");
|
||||||
|
resolver.getLink(params, true);
|
||||||
} catch (UriResolverMapException e) {
|
} catch (UriResolverMapException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
Loading…
Reference in New Issue