bug fixing #19215
This commit is contained in:
parent
6b43539d66
commit
1882f62588
|
@ -8,11 +8,12 @@
|
|||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src/test/resources"/>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<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.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
|
||||
|
|
|
@ -1,20 +1,42 @@
|
|||
<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>
|
||||
</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>
|
||||
</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>
|
||||
</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>
|
||||
<Change>Introduced Entry Names in Uri-Resolver-Map</Change>
|
||||
</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>
|
||||
</Changeset>
|
||||
</ReleaseNotes>
|
2
pom.xml
2
pom.xml
|
@ -11,7 +11,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.gcube.portlets.user</groupId>
|
||||
<artifactId>uri-resolver-manager</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<version>1.4.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>uri-resolver-manager</name>
|
||||
<description>The URI Resolver Manager</description>
|
||||
|
|
|
@ -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){
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param url
|
||||
* @param parameters
|
||||
* @return
|
||||
* Encode the input String using {@link URLEncoder#encode(String, String)}.
|
||||
*
|
||||
* @param theString the the query string
|
||||
* @return the string encoded
|
||||
*/
|
||||
public static String encodeQuery(Map<String, String> parameters){
|
||||
|
||||
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 parameters the parameters
|
||||
* @return the query string not encoded key1=value1&key2=value2&...
|
||||
*/
|
||||
public static String toQueryString(Map<String, String> 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<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) {
|
||||
|
||||
|
||||
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<String, String> parameters = new HashMap<String, String>();
|
||||
|
||||
|
||||
parameters.put("request", "GetStyles");
|
||||
parameters.put("layers", "test Name");
|
||||
parameters.put("version", "1.1.1");
|
||||
|
||||
|
||||
System.out.println(UrlEncoderUtil.encodeQuery(parameters));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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<String, String> params = new HashMap<String, String>();
|
||||
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) {
|
||||
|
|
|
@ -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