Uppdated CatalogueResolver by adding

query_string=BASE64[query_string_value]
This commit is contained in:
Francesco Mangiacrapa 2022-04-21 11:08:43 +02:00
parent cda5599d27
commit ca07d7ae0e
4 changed files with 14 additions and 33 deletions

View File

@ -94,12 +94,12 @@ public class CatalogueStaticConfigurations{
if(toPrivateCKANCatalogueURL.startsWith(prefix)) { if(toPrivateCKANCatalogueURL.startsWith(prefix)) {
toPrivateCKANCatalogueURL = toPrivateCKANCatalogueURL.replaceFirst(prefix, ""); //removing prefix toPrivateCKANCatalogueURL = toPrivateCKANCatalogueURL.replaceFirst(prefix, ""); //removing prefix
String catalogueName = toPrivateCKANCatalogueURL.substring(0,toPrivateCKANCatalogueURL.indexOf(".d4science")); String catalogueName = toPrivateCKANCatalogueURL.substring(0,toPrivateCKANCatalogueURL.indexOf(".d4science"));
LOG.info("Catalogue Name extration returning value: "+catalogueName); LOG.info("Catalogue Name extraction returning value: "+catalogueName);
return catalogueName; return catalogueName;
} }
} }
LOG.info("Catalogue Name extration returning null"); LOG.info("Catalogue Name extraction returning null");
return null; return null;
} }

View File

@ -19,6 +19,7 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import org.apache.commons.codec.binary.Base64;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.scope.impl.ScopeBean.Type; import org.gcube.common.scope.impl.ScopeBean.Type;
@ -34,7 +35,6 @@ import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigura
import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference; import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference;
import org.gcube.datatransfer.resolver.catalogue.resource.GetAllInfrastructureScopes; import org.gcube.datatransfer.resolver.catalogue.resource.GetAllInfrastructureScopes;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager; import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.gcube.datatransfer.resolver.util.UrlEncoderUtil;
import org.gcube.datatransfer.resolver.util.Util; import org.gcube.datatransfer.resolver.util.Util;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE; import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE;
import org.gcube.smartgears.utils.InnerMethodName; import org.gcube.smartgears.utils.InnerMethodName;
@ -94,6 +94,7 @@ public class CatalogueResolver {
try { try {
InnerMethodName.instance.set("resolveCataloguePublicLink"); InnerMethodName.instance.set("resolveCataloguePublicLink");
ItemCatalogueURLs itemCatalogueURLs = getItemCatalogueURLs(req, vreName, entityContext, entityName); ItemCatalogueURLs itemCatalogueURLs = getItemCatalogueURLs(req, vreName, entityContext, entityName);
String itemCatalogueURL; String itemCatalogueURL;
@ -113,17 +114,19 @@ public class CatalogueResolver {
} }
} else { } else {
itemCatalogueURL = itemCatalogueURLs.getPrivateVRECataloguePortletURL(); itemCatalogueURL = itemCatalogueURLs.getPrivateVRECataloguePortletURL();
logger.info("The dataset " + itemCatalogueURLs.getItemName() logger.info("Either the " + itemCatalogueURLs.getItemName()
+ " is a private item (to VRE) so using protected access to CKAN portlet: " + itemCatalogueURL); + " is not an item (alias dataset) or it is a private item (to VRE) so using protected access to CKAN portlet: "
+ itemCatalogueURL);
} }
String queryString = req.getQueryString(); String queryString = req.getQueryString();
if (queryString != null) { if (queryString != null) {
logger.debug("Query string found: " + queryString); logger.info("Query string found: " + queryString);
String qsEnc = URLEncoder.encode(queryString, "UTF-8"); byte[] stringEncBytes = Base64.encodeBase64(queryString.getBytes());
logger.info("Adding encoded query string " + qsEnc + " to Catalogue URL response"); String queryStringEnc = "query_string=" + new String(stringEncBytes);
logger.info("Adding Base64 encoded: " + queryString);
itemCatalogueURL += "?" + qsEnc; itemCatalogueURL += itemCatalogueURL.contains("?") ? "&" : "?";
itemCatalogueURL += queryStringEnc;
} }
return Response.seeOther(new URL(itemCatalogueURL).toURI()).build(); return Response.seeOther(new URL(itemCatalogueURL).toURI()).build();

View File

@ -1,23 +1,10 @@
package org.gcube.datatransfer.test; package org.gcube.datatransfer.test;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.storagehub.client.StreamDescriptor; import org.gcube.common.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.client.plugins.AbstractPlugin; import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
import org.gcube.common.storagehub.client.proxies.ItemManagerClient; import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigurationsReader;
import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference;
import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit; import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit;
import org.gcube.datatransfer.resolver.services.CatalogueResolver;
import org.gcube.datatransfer.resolver.services.StorageHubResolver;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.gcube.datatransfer.resolver.shub.StorageHubMetadataResponseBuilder;
import org.junit.Before;
import org.junit.Test;
import com.itextpdf.text.log.SysoCounter;
/** /**

View File

@ -15,19 +15,10 @@ import java.nio.file.StandardCopyOption;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.gcube.common.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader; import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader;
import org.gcube.datatransfer.resolver.services.StorageHubResolver;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.gcube.datatransfer.resolver.shub.StorageHubMetadataResponseBuilder;
import org.gcube.datatransfer.resolver.util.HTTPCallsUtils; import org.gcube.datatransfer.resolver.util.HTTPCallsUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -42,7 +33,7 @@ import org.slf4j.LoggerFactory;
public class TestResolvers { public class TestResolvers {
public static final String URI_RESOLVER_SERVICE_ENDPOINT = "https://data1-d.d4science.net"; public static final String URI_RESOLVER_SERVICE_ENDPOINT = "https://data.dev.d4science.org";
public static final Logger logger = LoggerFactory.getLogger(TestResolvers.class); public static final Logger logger = LoggerFactory.getLogger(TestResolvers.class);