diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index d726289..cfa6374 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -4,9 +4,6 @@ - - uses - diff --git a/distro/changelog.xml b/distro/changelog.xml index 94d5d79..adbadd4 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -159,4 +159,10 @@ [Incident #17180] Bug fixes + + [Feature #17630] Support parametric Content-Disposition + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 91578c1..d4ae9bd 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.gcube.data.transfer uri-resolver - 2.1.1-SNAPSHOT + 2.2.0-SNAPSHOT war The URI Resolver is an HTTP URI resolver implemented as an REST service which gives access trough HTTP to different gcube Resolvers and gCube Applications. diff --git a/src/main/java/org/gcube/datatransfer/resolver/ConstantsResolver.java b/src/main/java/org/gcube/datatransfer/resolver/ConstantsResolver.java index 026ae85..13af130 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/ConstantsResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/ConstantsResolver.java @@ -12,10 +12,13 @@ package org.gcube.datatransfer.resolver; public class ConstantsResolver { public static final String CONTENT_DISPOSITION = "Content-Disposition"; - public static final String DEFAULT_CONTENTTYPE_UNKNOWN_UNKNOWN = "unknown/unknown"; - public static final String DEFAULT_FILENAME_FROM_STORAGE_MANAGER = "fromStorageManager"; + public static enum CONTENT_DISPOSITION_VALUE {inline, attachment}; public static final String CONTENT_LENGTH = "Content-Length"; public static final String CONTENT_TYPE= "Content-Type"; + + public static final String QUERY_PARAM_CONTENTDISPOSITION = "content-disposition"; + public static final String DEFAULT_CONTENTTYPE_UNKNOWN_UNKNOWN = "unknown/unknown"; + public static final String DEFAULT_FILENAME_FROM_STORAGE_MANAGER = "fromStorageManager"; public static final String HPC = "hproxycheck"; //for hproxycheck diff --git a/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/UpdateApplicationProfileCatalogueResolver.java b/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/UpdateApplicationProfileCatalogueResolver.java index 36332eb..3cb05b9 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/UpdateApplicationProfileCatalogueResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/UpdateApplicationProfileCatalogueResolver.java @@ -147,16 +147,4 @@ public class UpdateApplicationProfileCatalogueResolver { return document; } - -// public static void main(String[] args) { -// -// String scope = "/gcube"; -// try { -// UpdateApplicationProfileCatalogueResolver.validateEndPoint( -// scope, "gcube", "/gcube/devsec"); -// } -// catch (Exception e) { -// e.printStackTrace(); -// } -// } } diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/StorageHubResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/StorageHubResolver.java index ca0453d..3abfbce 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/StorageHubResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/StorageHubResolver.java @@ -14,6 +14,8 @@ import javax.ws.rs.core.Response.ResponseBuilder; 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.ConstantsResolver; +import org.gcube.datatransfer.resolver.ConstantsResolver.CONTENT_DISPOSITION_VALUE; import org.gcube.datatransfer.resolver.services.error.ExceptionManager; import org.gcube.datatransfer.resolver.util.StorageHubMetadataResponseBuilder; import org.gcube.smartgears.utils.InnerMethodName; @@ -68,7 +70,7 @@ public class StorageHubResolver { ItemManagerClient client = AbstractPlugin.item().build(); StreamDescriptor descriptor = client.resolvePublicLink(id); ResponseBuilder response = Response.noContent(); - response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id); + response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id, CONTENT_DISPOSITION_VALUE.attachment); return response.build(); }catch(Exception e){ @@ -105,11 +107,27 @@ public class StorageHubResolver { try{ InnerMethodName.instance.set("resolveStorageHubPublicLink"); - //Checking mandatory parameter id + //Checking mandatory parameter "id" if(id==null || id.isEmpty()){ logger.error("Path Parameter "+STORAGE_HUB_ID+" not found"); throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter "+STORAGE_HUB_ID, StorageHubResolver.class, help); } + + //Checking the optional parameter "Content-Disposition" + String contDisp = req.getParameter(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION); + CONTENT_DISPOSITION_VALUE dispValue = CONTENT_DISPOSITION_VALUE.attachment; + //Validating the Content-Disposition value + if(contDisp!=null && !contDisp.isEmpty()) { + try { + //It must have a value of: "inline" or "attachement" + dispValue = ConstantsResolver.CONTENT_DISPOSITION_VALUE.valueOf(contDisp); + }catch (Exception e) { + String allowedValues = String.format("{%s,%s}", CONTENT_DISPOSITION_VALUE.inline,CONTENT_DISPOSITION_VALUE.attachment); + String errorMsg = "The parameter "+ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION+" passed in the query string is not a value of "+allowedValues; + logger.error(errorMsg); + throw ExceptionManager.badRequestException(req, errorMsg, StorageHubResolver.class, help); + } + } try{ @@ -117,7 +135,7 @@ public class StorageHubResolver { StreamDescriptor descriptor = client.resolvePublicLink(id); ResponseBuilder response = Response.ok(descriptor.getStream()); - response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id); + response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id, dispValue); return response.build(); }catch(Exception e){ diff --git a/src/main/java/org/gcube/datatransfer/resolver/util/GetResponseRecordFilter.java b/src/main/java/org/gcube/datatransfer/resolver/util/GetResponseRecordFilter.java index 56294ed..344066b 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/util/GetResponseRecordFilter.java +++ b/src/main/java/org/gcube/datatransfer/resolver/util/GetResponseRecordFilter.java @@ -282,7 +282,7 @@ public class GetResponseRecordFilter { Map overridingRecordsMap = new HashMap(); int overrideCount = 0; //FOR EACH PUBLIC IDS - for (String identifier : idsToRemove) { + for (String publicIdentifier : idsToRemove) { //FOR EACH gmd:fileIdentifier RETURNED IN THE GET_RECORDS RESPONSE //CHECKING IF IT IS A PUBLIC ID @@ -292,15 +292,19 @@ public class GetResponseRecordFilter { // NodeList fileIdentifierLst = mdMetadata.getElementsByTagName("gmd:fileIdentifier"); if(fileIdentifierLst==null || fileIdentifierLst.getLength()==0 || fileIdentifierLst.item(0)==null){ - logger.info("skipping identifier: " + identifier +" it has not fileidentifier"); - break; + logger.info("tagName gmd:fileIdentifier not found, trying to search 'fileIdentifier"); + fileIdentifierLst = mdMetadata.getElementsByTagName("fileIdentifier"); + if(fileIdentifierLst==null || fileIdentifierLst.getLength()==0 || fileIdentifierLst.item(0)==null){ + logger.info("also tagName fileIdentifier not found, skipping matching of public identifier " + publicIdentifier +" current gmd:MD_Metadata has not tagName 'gmd:fileIdentifier' or 'fileIdentifier'"); + break; + } } Element id = (Element) fileIdentifierLst.item(0); NodeList gcoLst = id.getElementsByTagName("gco:CharacterString"); if(gcoLst==null || gcoLst.getLength()==0 || gcoLst.item(0)==null){ - logger.debug("skipping identifier: " + identifier +" it has not gco:CharacterString"); + logger.debug("skipping matching of public identifier: " + publicIdentifier +"current gmd:MD_Metadata has not 'gco:CharacterString'"); break; } @@ -312,7 +316,7 @@ public class GetResponseRecordFilter { } logger.trace("Summary gmd:fileIdentifier is: " + idValue); - if (idValue!=null && idValue.compareTo(identifier)==0) { + if (idValue!=null && idValue.compareTo(publicIdentifier)==0) { gco.setTextContent(messageToWrite); logger.debug("Overrided child " + idValue); overridingRecordsMap.put(idValue, true); diff --git a/src/main/java/org/gcube/datatransfer/resolver/util/StorageHubMetadataResponseBuilder.java b/src/main/java/org/gcube/datatransfer/resolver/util/StorageHubMetadataResponseBuilder.java index cee3408..c4384e1 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/util/StorageHubMetadataResponseBuilder.java +++ b/src/main/java/org/gcube/datatransfer/resolver/util/StorageHubMetadataResponseBuilder.java @@ -10,6 +10,7 @@ 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.ConstantsResolver; +import org.gcube.datatransfer.resolver.ConstantsResolver.CONTENT_DISPOSITION_VALUE; /** @@ -35,18 +36,21 @@ public class StorageHubMetadataResponseBuilder { this.request = req; this.responseBuilder = responseBuilder; } - - + + /** * Fill metadata. + * * @param streamDescriptor the stream descriptor * @param entityId the entity id + * @param contentDispValue the content disp value * @return the response builder */ - public ResponseBuilder fillMetadata(StreamDescriptor streamDescriptor, String entityId){ - + public ResponseBuilder fillMetadata(StreamDescriptor streamDescriptor, String entityId, CONTENT_DISPOSITION_VALUE contentDispValue){ + //Adding "Content-Disposition" - responseBuilder.header(ConstantsResolver.CONTENT_DISPOSITION,"attachment; filename=\""+streamDescriptor.getFileName()+"\""); + String headerCD = String.format("%s; filename=\"%s\"", contentDispValue,streamDescriptor.getFileName()); + responseBuilder.header(ConstantsResolver.CONTENT_DISPOSITION, headerCD); //Adding "Content-Location" String contentLocation = String.format("%s/%s/%s", Util.getServerURL(request), "shub", entityId);