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
24
pom.xml
24
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"
|
||||
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>
|
||||
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>
|
||||
|
||||
<groupId>org.gcube.portlets.user</groupId>
|
||||
<artifactId>uri-resolver-manager</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<groupId>org.gcube.portlets.user</groupId>
|
||||
<artifactId>uri-resolver-manager</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<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>
|
||||
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/${project.artifactId}</url>
|
||||
</scm>
|
||||
|
@ -72,10 +72,18 @@
|
|||
</dependency>
|
||||
<!-- 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>
|
||||
<groupId>commons-httpclient</groupId>
|
||||
<artifactId>commons-httpclient</artifactId>
|
||||
<version>3.1</version>
|
||||
<scope>compile</scope>
|
||||
</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.UriResolverMapReader;
|
||||
import org.gcube.portlets.user.uriresolvermanager.util.UrlEncoderUtil;
|
||||
import org.gcube.portlets.user.urlshortener.UrlShortener;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -30,9 +31,9 @@ public class UriResolverManager {
|
|||
private Map<String, String> applicationTypes;
|
||||
private String scope;
|
||||
private String applicationType;
|
||||
private Object infra;
|
||||
|
||||
public static final Logger logger = LoggerFactory.getLogger(UriResolverManager.class);
|
||||
|
||||
/**
|
||||
* Instance a UriResolverManager
|
||||
* 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 link;
|
||||
|
||||
if(parameters==null){
|
||||
throw new IllegalArgumentException("Input Map parameters is null");
|
||||
|
@ -89,26 +99,31 @@ public class UriResolverManager {
|
|||
String baseURI = reader.getServiceBaseURI();
|
||||
|
||||
String params = UrlEncoderUtil.encodeQuery(parameters);
|
||||
String uriRequest = reader.getServiceBaseURI()+"?"+params;
|
||||
logger.info("Created HTTP URI request: "+uriRequest);
|
||||
|
||||
// baseURI = "http://pc-mangiacrapa.isti.cnr.it:8080/uri-resolver-1.2.0-SNAPSHOT/gis";
|
||||
//
|
||||
// HttpCallerUtil httpCaller = new HttpCallerUtil(baseURI, "", "");
|
||||
// httpCaller.callGet("", parameters);
|
||||
link = baseURI+"?"+params;
|
||||
logger.info("Created HTTP URI request (link): "+link);
|
||||
|
||||
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){
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
logger.error("Uri Resolver error: ", e);
|
||||
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(){
|
||||
return this.applicationTypes.keySet();
|
||||
|
@ -126,11 +141,12 @@ public class UriResolverManager {
|
|||
|
||||
try {
|
||||
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
||||
UriResolverManager resolver = new UriResolverManager("GIS");
|
||||
UriResolverManager resolver = new UriResolverManager("SMP");
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("gis-UUID", "12345");
|
||||
params.put("scope", "/gcube");
|
||||
resolver.getLink(params);
|
||||
params.put("smp-uri", "12345");
|
||||
params.put("fileName", "/gcube");
|
||||
params.put("contentType", "/gcube");
|
||||
resolver.getLink(params, true);
|
||||
} catch (UriResolverMapException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
|
Loading…
Reference in New Issue