bug fixing #19215
This commit is contained in:
parent
6b43539d66
commit
1882f62588
|
@ -8,11 +8,12 @@
|
||||||
</classpathentry>
|
</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="optional" value="true"/>
|
<attribute name="optional" value="true"/>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
<attribute name="test" value="true"/>
|
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" path="src/test/resources"/>
|
||||||
<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"/>
|
||||||
|
|
|
@ -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.codegen.targetPlatform=1.8
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
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.enumIdentifier=error
|
||||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
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.release=disabled
|
||||||
org.eclipse.jdt.core.compiler.source=1.8
|
org.eclipse.jdt.core.compiler.source=1.8
|
||||||
|
|
|
@ -1,20 +1,42 @@
|
||||||
<ReleaseNotes>
|
<ReleaseNotes>
|
||||||
<Changeset component="org.gcube.portlets.user.uri-resolver-manager.1-3-0" date="2016-09-27">
|
<Changeset
|
||||||
|
component="org.gcube.portlets.user.uri-resolver-manager.1-4-1"
|
||||||
|
date="2020-05-06">
|
||||||
|
<Change>[Bug #19215] UriResolverManager: request to DL (the shortener)
|
||||||
|
must be encoded
|
||||||
|
</Change>
|
||||||
|
</Changeset>
|
||||||
|
<Changeset
|
||||||
|
component="org.gcube.portlets.user.uri-resolver-manager.1-4-0"
|
||||||
|
date="2019-11-26">
|
||||||
|
<Change>Migrated to git</Change>
|
||||||
|
</Changeset>
|
||||||
|
<Changeset
|
||||||
|
component="org.gcube.portlets.user.uri-resolver-manager.1-3-0"
|
||||||
|
date="2016-09-27">
|
||||||
<Change>[Bug #4941] Removed jumps of scope</Change>
|
<Change>[Bug #4941] Removed jumps of scope</Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
<Changeset component="org.gcube.portlets.user.uri-resolver-manager.1-2-0" date="2016-06-28">
|
<Changeset
|
||||||
|
component="org.gcube.portlets.user.uri-resolver-manager.1-2-0"
|
||||||
|
date="2016-06-28">
|
||||||
<Change></Change>
|
<Change></Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
<Changeset component="org.gcube.portlets.user.uri-resolver-manager.1-1-0" date="2016-06-24">
|
<Changeset
|
||||||
|
component="org.gcube.portlets.user.uri-resolver-manager.1-1-0"
|
||||||
|
date="2016-06-24">
|
||||||
<Change>Removed maven-portal-bom as dependency
|
<Change>Removed maven-portal-bom as dependency
|
||||||
</Change>
|
</Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
<Changeset component="org.gcube.portlets.user.uri-resolver-manager.1-1-0" date="2015-05-04">
|
<Changeset
|
||||||
|
component="org.gcube.portlets.user.uri-resolver-manager.1-1-0"
|
||||||
|
date="2015-05-04">
|
||||||
<Change>Updated to support several Access Point for each Resolver
|
<Change>Updated to support several Access Point for each Resolver
|
||||||
</Change>
|
</Change>
|
||||||
<Change>Introduced Entry Names in Uri-Resolver-Map</Change>
|
<Change>Introduced Entry Names in Uri-Resolver-Map</Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
<Changeset component="org.gcube.portlets.user.uri-resolver-manager.1-0-0" date="2014-10-13">
|
<Changeset
|
||||||
|
component="org.gcube.portlets.user.uri-resolver-manager.1-0-0"
|
||||||
|
date="2014-10-13">
|
||||||
<Change>First Release</Change>
|
<Change>First Release</Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
</ReleaseNotes>
|
</ReleaseNotes>
|
2
pom.xml
2
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.0</version>
|
<version>1.4.1-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>
|
||||||
|
|
|
@ -205,19 +205,43 @@ public class UriResolverManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
String baseURI = serviceAccessPoint.getServiceUrl();
|
String baseURI = serviceAccessPoint.getServiceUrl();
|
||||||
//releaseReader();
|
|
||||||
String params = UrlEncoderUtil.encodeQuery(parameters);
|
//TO ENCODE THE WHOLE URL
|
||||||
link = baseURI+"?"+params;
|
// 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);
|
logger.info("Created HTTP URI request (link): "+link);
|
||||||
|
|
||||||
if(shortLink){
|
if(shortLink){
|
||||||
try{
|
try{
|
||||||
logger.info("Shortner start..");
|
logger.info("Shortner start..");
|
||||||
UrlShortener shortener = new UrlShortener();
|
UrlShortener shortener = new UrlShortener();
|
||||||
link = shortener.shorten(link);
|
String shortedLink = shortener.shorten(link);
|
||||||
logger.info("Shorted link is: "+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){
|
}catch(Exception e){
|
||||||
logger.warn("An error occurred during link shortening: ",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){
|
} catch (IllegalArgumentException e){
|
||||||
|
|
|
@ -11,30 +11,32 @@ import java.util.Map;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
// TODO: Auto-generated Javadoc
|
||||||
/**
|
/**
|
||||||
|
* The Class UrlEncoderUtil.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
* @Oct 13, 2014
|
* @Oct 13, 2014
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class UrlEncoderUtil {
|
public class UrlEncoderUtil {
|
||||||
|
|
||||||
public static String charset = "UTF-8";
|
public static String charset = "UTF-8";
|
||||||
|
|
||||||
protected static Logger logger = LoggerFactory.getLogger(UrlEncoderUtil.class);
|
protected static Logger logger = LoggerFactory.getLogger(UrlEncoderUtil.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Encode query.
|
||||||
*
|
*
|
||||||
* @param url
|
* @param parameters the parameters
|
||||||
* @param parameters
|
* @return the string
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static String encodeQuery(String... parameters){
|
public static String encodeQuery(String... parameters) {
|
||||||
|
|
||||||
String query = "";
|
String query = "";
|
||||||
for (String string : parameters) {
|
for (String string : parameters) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
query+=URLEncoder.encode(string, charset)+"&";
|
query += URLEncoder.encode(string, charset) + "&";
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
|
||||||
logger.error("encodeQuery error: ", e);
|
logger.error("encodeQuery error: ", e);
|
||||||
|
@ -45,31 +47,80 @@ public class UrlEncoderUtil {
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return removeLastChar(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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* To query string not encoded
|
||||||
*
|
*
|
||||||
* @param url
|
* @param parameters the parameters
|
||||||
* @param parameters
|
* @return the query string not encoded key1=value1&key2=value2&...
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static String encodeQuery(Map<String, String> parameters){
|
public static String toQueryString(Map<String, String> parameters) {
|
||||||
|
|
||||||
String query = "";
|
String query = "";
|
||||||
|
|
||||||
if(parameters==null)
|
if (parameters == null)
|
||||||
return query;
|
return query;
|
||||||
|
|
||||||
for (String key : parameters.keySet()) {
|
for (String key : parameters.keySet()) {
|
||||||
|
|
||||||
try {
|
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<String, String> 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) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
|
||||||
logger.error("encodeQuery error: ", e);
|
logger.error("encodeQuery error: ", e);
|
||||||
|
@ -85,17 +136,28 @@ public class UrlEncoderUtil {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String removeLastChar(String string){
|
/**
|
||||||
|
* Removes the last char.
|
||||||
|
*
|
||||||
|
* @param string the string
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
public static String removeLastChar(String string) {
|
||||||
|
|
||||||
if(string == null)
|
if (string == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if(string.length()>0)
|
if (string.length() > 0)
|
||||||
return string.substring(0, string.length()-1);
|
return string.substring(0, string.length() - 1);
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main method.
|
||||||
|
*
|
||||||
|
* @param args the arguments
|
||||||
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
// System.out.println(UrlEncoderUtil.encodeQuery("request=GetStyles", "layers=test Name", "service=WMS", "version=1.1.1"));
|
// System.out.println(UrlEncoderUtil.encodeQuery("request=GetStyles", "layers=test Name", "service=WMS", "version=1.1.1"));
|
||||||
|
@ -108,8 +170,6 @@ public class UrlEncoderUtil {
|
||||||
|
|
||||||
System.out.println(UrlEncoderUtil.encodeQuery(parameters));
|
System.out.println(UrlEncoderUtil.encodeQuery(parameters));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import org.junit.Test;
|
||||||
*/
|
*/
|
||||||
public class UriResolverManagerTest {
|
public class UriResolverManagerTest {
|
||||||
|
|
||||||
// @Test
|
//@Test
|
||||||
public void testUriResolverManger(){
|
public void testUriResolverManger(){
|
||||||
UriResolverManager manager;
|
UriResolverManager manager;
|
||||||
try {
|
try {
|
||||||
|
@ -36,15 +36,15 @@ public class UriResolverManagerTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
//@Test
|
||||||
public void testGIS() {
|
public void testGIS() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
ScopeProvider.instance.set("/pred4s/preprod/preVRE");
|
||||||
UriResolverManager resolver = new UriResolverManager("GIS");
|
UriResolverManager resolver = new UriResolverManager("GIS");
|
||||||
Map<String, String> params = new HashMap<String, String>();
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
params.put("gis-UUID", "5ac49f44-999f-4efe-a32b-af71da2b39ac");
|
params.put("gis-UUID", "1a657005-29c6-4528-a115-69640c4c2900");
|
||||||
params.put("scope", "/gcube/devsec/devVRE");
|
params.put("scope", "/pred4s/preprod/preVRE");
|
||||||
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
|
||||||
} catch (UriResolverMapException e) {
|
} catch (UriResolverMapException e) {
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue