diff --git a/.classpath b/.classpath
index 502bd4a..c732b73 100644
--- a/.classpath
+++ b/.classpath
@@ -8,11 +8,12 @@
+
-
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
index 4e4a3ad..cac0df4 100644
--- a/.settings/org.eclipse.jdt.core.prefs
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -3,7 +3,9 @@ org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
diff --git a/changelog.xml b/changelog.xml
index 370b062..0e0660a 100644
--- a/changelog.xml
+++ b/changelog.xml
@@ -1,20 +1,42 @@
-
+
+ [Bug #19215] UriResolverManager: request to DL (the shortener)
+ must be encoded
+
+
+
+ Migrated to git
+
+
[Bug #4941] Removed jumps of scope
-
+
-
+
Removed maven-portal-bom as dependency
-
+
Updated to support several Access Point for each Resolver
Introduced Entry Names in Uri-Resolver-Map
-
+
First Release
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 2989391..628f39f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
4.0.0
org.gcube.portlets.user
uri-resolver-manager
- 1.4.0
+ 1.4.1-SNAPSHOT
jar
uri-resolver-manager
The URI Resolver Manager
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/UriResolverManager.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/UriResolverManager.java
index ada71c7..fb1902b 100644
--- a/src/main/java/org/gcube/portlets/user/uriresolvermanager/UriResolverManager.java
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/UriResolverManager.java
@@ -205,19 +205,43 @@ public class UriResolverManager {
}
String baseURI = serviceAccessPoint.getServiceUrl();
- //releaseReader();
- String params = UrlEncoderUtil.encodeQuery(parameters);
- link = baseURI+"?"+params;
+
+ //TO ENCODE THE WHOLE URL
+// String queryString = UrlEncoderUtil.toQueryString(parameters);
+// link = baseURI+"?"+queryString;
+// logger.info("Created HTTP URI request (link): "+link);
+// link = UrlEncoderUtil.encodeString(link);
+// logger.info("Encoded it, like: "+link);
+
+ //Enconding only the query string
+ String queryString = UrlEncoderUtil.toQueryString(parameters);
+ String linkDecoded = String.format("%s?%s", baseURI,queryString);
+ String queryStringEncoded = UrlEncoderUtil.encodeString(queryString);
+ link = String.format("%s?%s", baseURI,queryStringEncoded);
logger.info("Created HTTP URI request (link): "+link);
if(shortLink){
try{
logger.info("Shortner start..");
UrlShortener shortener = new UrlShortener();
- link = shortener.shorten(link);
- logger.info("Shorted link is: "+link);
+ String shortedLink = shortener.shorten(link);
+ logger.info("Shorted link is: "+shortedLink);
+ if(shortedLink!=null && shortedLink.equals(link)) {
+ //here the short link and the input link are identical
+ //so the shortening did not work
+ //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);
+ link = linkDecoded;
+ }else {
+ //here the link is really shorted
+ logger.debug("The link is really shorted, returning it");
+ link = shortedLink;
+ }
+
}catch(Exception e){
logger.warn("An error occurred during link shortening: ",e);
+ //here I'm returning the decoded link in case of error on shortening it
+ link = linkDecoded;
}
}
} catch (IllegalArgumentException e){
diff --git a/src/main/java/org/gcube/portlets/user/uriresolvermanager/util/UrlEncoderUtil.java b/src/main/java/org/gcube/portlets/user/uriresolvermanager/util/UrlEncoderUtil.java
index 7bd4741..2330752 100644
--- a/src/main/java/org/gcube/portlets/user/uriresolvermanager/util/UrlEncoderUtil.java
+++ b/src/main/java/org/gcube/portlets/user/uriresolvermanager/util/UrlEncoderUtil.java
@@ -11,105 +11,165 @@ import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+// TODO: Auto-generated Javadoc
/**
- *
+ * The Class UrlEncoderUtil.
+ *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Oct 13, 2014
- *
*/
public class UrlEncoderUtil {
-
+
public static String charset = "UTF-8";
-
+
protected static Logger logger = LoggerFactory.getLogger(UrlEncoderUtil.class);
+
/**
- *
- * @param url
- * @param parameters
- * @return
+ * Encode query.
+ *
+ * @param parameters the parameters
+ * @return the string
*/
- public static String encodeQuery(String... parameters){
-
+ public static String encodeQuery(String... parameters) {
+
String query = "";
for (String string : parameters) {
-
+
try {
- query+=URLEncoder.encode(string, charset)+"&";
+ query += URLEncoder.encode(string, charset) + "&";
} catch (UnsupportedEncodingException e) {
-
+
logger.error("encodeQuery error: ", e);
return query;
} catch (Exception e) {
-
+
logger.error("encodeQuery error: ", e);
return query;
}
-
}
return removeLastChar(query);
}
-
-
-
+
+ /**
+ * Encode the input String using {@link URLEncoder#encode(String, String)}.
+ *
+ * @param theString the the query string
+ * @return the string encoded
+ */
+ public static String encodeString(String theString) {
+
+ String encodedQuery = "";
+
+ if (theString == null || theString.isEmpty())
+ return theString;
+
+ try {
+ encodedQuery = URLEncoder.encode(theString, charset);
+ } catch (UnsupportedEncodingException e) {
+ logger.error("encodeQuery error: ", e);
+ return theString;
+ }
+ return encodedQuery;
+ }
+
/**
- *
- * @param url
- * @param parameters
- * @return
+ * To query string not encoded
+ *
+ * @param parameters the parameters
+ * @return the query string not encoded key1=value1&key2=value2&...
*/
- public static String encodeQuery(Map parameters){
-
+ public static String toQueryString(Map parameters) {
+
String query = "";
-
- if(parameters==null)
+
+ if (parameters == null)
return query;
-
+
for (String key : parameters.keySet()) {
-
+
try {
- query+=String.format(key+"=%s", URLEncoder.encode(parameters.get(key), charset))+"&";
+ query += String.format("%s=%s", key, parameters.get(key)) + "&";
+
+ } catch (Exception e) {
+
+ logger.error("getQueryString error: ", e);
+ return query;
+ }
+ }
+
+ return removeLastChar(query);
+
+ }
+
+ /**
+ * Encode query.
+ *
+ * @param parameters the parameters
+ * @return the string
+ */
+ public static String encodeQuery(Map parameters) {
+
+ String query = "";
+
+ if (parameters == null)
+ return query;
+
+ for (String key : parameters.keySet()) {
+
+ try {
+
+ query += String.format(key + "=%s", URLEncoder.encode(parameters.get(key), charset)) + "&";
} catch (UnsupportedEncodingException e) {
-
+
logger.error("encodeQuery error: ", e);
return query;
} catch (Exception e) {
-
+
logger.error("encodeQuery error: ", e);
return query;
}
}
return removeLastChar(query);
-
+
}
-
- public static String removeLastChar(String string){
-
- if(string == null)
+
+ /**
+ * Removes the last char.
+ *
+ * @param string the string
+ * @return the string
+ */
+ public static String removeLastChar(String string) {
+
+ if (string == null)
return null;
-
- if(string.length()>0)
- return string.substring(0, string.length()-1);
-
+
+ if (string.length() > 0)
+ return string.substring(0, string.length() - 1);
+
return string;
}
-
+
+ /**
+ * The main method.
+ *
+ * @param args the arguments
+ */
public static void main(String[] args) {
-
+
// System.out.println(UrlEncoderUtil.encodeQuery("request=GetStyles", "layers=test Name", "service=WMS", "version=1.1.1"));
-
+
HashMap parameters = new HashMap();
-
+
parameters.put("request", "GetStyles");
parameters.put("layers", "test Name");
parameters.put("version", "1.1.1");
-
+
System.out.println(UrlEncoderUtil.encodeQuery(parameters));
-
-
- }
+ }
}
diff --git a/src/test/java/UriResolverManagerTest.java b/src/test/java/UriResolverManagerTest.java
index f232140..f53c3f8 100644
--- a/src/test/java/UriResolverManagerTest.java
+++ b/src/test/java/UriResolverManagerTest.java
@@ -18,7 +18,7 @@ import org.junit.Test;
*/
public class UriResolverManagerTest {
-// @Test
+ //@Test
public void testUriResolverManger(){
UriResolverManager manager;
try {
@@ -36,15 +36,15 @@ public class UriResolverManagerTest {
}
-// @Test
+ //@Test
public void testGIS() {
try {
- ScopeProvider.instance.set("/gcube/devsec/devVRE");
+ ScopeProvider.instance.set("/pred4s/preprod/preVRE");
UriResolverManager resolver = new UriResolverManager("GIS");
Map params = new HashMap();
- params.put("gis-UUID", "5ac49f44-999f-4efe-a32b-af71da2b39ac");
- params.put("scope", "/gcube/devsec/devVRE");
+ params.put("gis-UUID", "1a657005-29c6-4528-a115-69640c4c2900");
+ params.put("scope", "/pred4s/preprod/preVRE");
String shortLink = resolver.getLink(params, true);
System.out.println(shortLink); //true, link is shorted otherwise none
} catch (UriResolverMapException e) {
diff --git a/src/test/resources/.gitignore b/src/test/resources/.gitignore
new file mode 100644
index 0000000..aaf50a2
--- /dev/null
+++ b/src/test/resources/.gitignore
@@ -0,0 +1,15 @@
+/D4OS.gcubekey
+/D4Research.gcubekey
+/FARM.gcubekey
+/OpenAIRE.gcubekey
+/ParthenosVO.gcubekey
+/SmartArea.gcubekey
+/SoBigData.gcubekey
+/d4science.research-infrastructures.eu.gcubekey
+/devNext.gcubekey
+/devsec.gcubekey
+/gCubeApps.gcubekey
+/gcube.gcubekey
+/log4j.properties
+/pred4s.gcubekey
+/preprod.gcubekey