Support to Content-Disposition as query parameter
Added to Storage Resolvers link support to content-disposition as input query parameter.
This commit is contained in:
parent
ac85f3dd92
commit
d1d093cdd4
|
@ -12,23 +12,28 @@ package org.gcube.datatransfer.resolver;
|
||||||
public class ConstantsResolver {
|
public class ConstantsResolver {
|
||||||
|
|
||||||
public static final String CONTENT_DISPOSITION = "Content-Disposition";
|
public static final String CONTENT_DISPOSITION = "Content-Disposition";
|
||||||
public static enum CONTENT_DISPOSITION_VALUE {inline, attachment};
|
|
||||||
|
public static enum CONTENT_DISPOSITION_VALUE {
|
||||||
|
inline, attachment
|
||||||
|
};
|
||||||
|
|
||||||
public static final String CONTENT_LENGTH = "Content-Length";
|
public static final String CONTENT_LENGTH = "Content-Length";
|
||||||
public static final String CONTENT_TYPE = "Content-Type";
|
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_CONTENTTYPE_UNKNOWN_UNKNOWN = "unknown/unknown";
|
||||||
public static final String DEFAULT_FILENAME_FROM_STORAGE_MANAGER = "fromStorageManager";
|
public static final String DEFAULT_FILENAME_FROM_STORAGE_MANAGER = "fromStorageManager";
|
||||||
|
|
||||||
public static final String HPC = "hproxycheck"; // for hproxycheck
|
public static final String HPC = "hproxycheck"; // for hproxycheck
|
||||||
|
|
||||||
|
public static final String QUERY_PARAM_CONTENTDISPOSITION = "content-disposition";
|
||||||
public static final String QUERY_PARAM_VALIDATION = "validation";
|
public static final String QUERY_PARAM_VALIDATION = "validation";
|
||||||
public static final String QUERY_PARAM_CONTENT_TYPE = "contentType";
|
public static final String QUERY_PARAM_CONTENT_TYPE = "contentType";
|
||||||
public static final String QUERY_PARAM_FILE_NAME = "fileName";
|
public static final String QUERY_PARAM_FILE_NAME = "fileName";
|
||||||
|
|
||||||
public static final String[] resourcesHardCoded = { "ctlg" };
|
public static final String[] resourcesHardCoded = { "ctlg" };
|
||||||
|
|
||||||
//The default resource candidate to manage the input requests not matching any resolver services
|
// The default resource candidate to manage the input requests not matching any
|
||||||
|
// resolver services
|
||||||
public static final String defaultServiceToRedirect = "storage";
|
public static final String defaultServiceToRedirect = "storage";
|
||||||
|
|
||||||
public static final String SCOPE_SEPARATOR = "/";
|
public static final String SCOPE_SEPARATOR = "/";
|
||||||
|
|
|
@ -74,6 +74,7 @@ public class RequestHandler implements ContainerRequestFilter, ContainerResponse
|
||||||
log.debug("The resources are: {}", listOfPath);
|
log.debug("The resources are: {}", listOfPath);
|
||||||
|
|
||||||
String path = reqContext.getUriInfo().getPath();
|
String path = reqContext.getUriInfo().getPath();
|
||||||
|
log.debug("The path is: {}", path);
|
||||||
|
|
||||||
//HOW TO READ THE QUERY STRING
|
//HOW TO READ THE QUERY STRING
|
||||||
/*MultivaluedMap<String, String> queryParameters = reqContext.getUriInfo().getQueryParameters();
|
/*MultivaluedMap<String, String> queryParameters = reqContext.getUriInfo().getQueryParameters();
|
||||||
|
@ -87,9 +88,6 @@ public class RequestHandler implements ContainerRequestFilter, ContainerResponse
|
||||||
log.debug("The query string is: {}", queryString);
|
log.debug("The query string is: {}", queryString);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
log.debug("The path is: {}", path);
|
|
||||||
|
|
||||||
|
|
||||||
if(path==null || path.isEmpty()) {
|
if(path==null || path.isEmpty()) {
|
||||||
log.debug("The path is null or empty, redirecting to /index");
|
log.debug("The path is null or empty, redirecting to /index");
|
||||||
URI newRequestURI = reqContext.getUriInfo().getBaseUriBuilder().path("/index").build();
|
URI newRequestURI = reqContext.getUriInfo().getBaseUriBuilder().path("/index").build();
|
||||||
|
|
|
@ -13,7 +13,9 @@ import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
import org.gcube.datatransfer.resolver.ConstantsResolver;
|
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.services.error.ExceptionManager;
|
||||||
|
import org.gcube.datatransfer.resolver.util.ValidateContentDisposition;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -53,7 +55,9 @@ public class SMPIDResolver {
|
||||||
@QueryParam(SMP_ID) @Nullable String smpId,
|
@QueryParam(SMP_ID) @Nullable String smpId,
|
||||||
@QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName,
|
@QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName,
|
||||||
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENT_TYPE) String contentType,
|
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENT_TYPE) String contentType,
|
||||||
@QueryParam(ConstantsResolver.QUERY_PARAM_VALIDATION) Boolean validation) throws WebApplicationException{
|
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition,
|
||||||
|
@QueryParam(ConstantsResolver.QUERY_PARAM_VALIDATION) boolean validation) throws WebApplicationException{
|
||||||
|
|
||||||
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
@ -63,7 +67,13 @@ public class SMPIDResolver {
|
||||||
throw ExceptionManager.badRequestException(req, "Missing mandatory parameter "+SMP_ID, SMPIDResolver.class, helpURI);
|
throw ExceptionManager.badRequestException(req, "Missing mandatory parameter "+SMP_ID, SMPIDResolver.class, helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
return StorageIDResolver.resolveStorageId(req, smpId, fileName, contentType, validation);
|
|
||||||
|
//Checking the optional parameter "Content-Disposition"
|
||||||
|
CONTENT_DISPOSITION_VALUE dispositionValue = CONTENT_DISPOSITION_VALUE.attachment;
|
||||||
|
//Validating the Content-Disposition value
|
||||||
|
dispositionValue = ValidateContentDisposition.validValue(req, this.getClass(), helpURI, contentDisposition);
|
||||||
|
|
||||||
|
return StorageIDResolver.resolveStorageId(req, smpId, fileName, contentType, dispositionValue, validation);
|
||||||
|
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,9 @@ import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
import org.gcube.datatransfer.resolver.ConstantsResolver;
|
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.services.error.ExceptionManager;
|
||||||
|
import org.gcube.datatransfer.resolver.util.ValidateContentDisposition;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -54,7 +56,8 @@ public class SMPResolver {
|
||||||
String smpURI,
|
String smpURI,
|
||||||
@QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName,
|
@QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName,
|
||||||
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENT_TYPE) String contentType,
|
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENT_TYPE) String contentType,
|
||||||
@QueryParam(ConstantsResolver.QUERY_PARAM_VALIDATION) Boolean validation) throws WebApplicationException{
|
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition,
|
||||||
|
@QueryParam(ConstantsResolver.QUERY_PARAM_VALIDATION) boolean validation) throws WebApplicationException{
|
||||||
|
|
||||||
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
||||||
|
|
||||||
|
@ -65,7 +68,12 @@ public class SMPResolver {
|
||||||
throw ExceptionManager.badRequestException(req, "Missing mandatory parameter "+SMP_URI, SMPResolver.class, helpURI);
|
throw ExceptionManager.badRequestException(req, "Missing mandatory parameter "+SMP_URI, SMPResolver.class, helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
return StorageIDResolver.resolveStorageId(req, smpURI, fileName, contentType, validation);
|
//Checking the optional parameter "Content-Disposition"
|
||||||
|
CONTENT_DISPOSITION_VALUE dispositionValue = CONTENT_DISPOSITION_VALUE.attachment;
|
||||||
|
//Validating the Content-Disposition value
|
||||||
|
dispositionValue = ValidateContentDisposition.validValue(req, this.getClass(), helpURI, contentDisposition);
|
||||||
|
|
||||||
|
return StorageIDResolver.resolveStorageId(req, smpURI, fileName, contentType, dispositionValue, validation);
|
||||||
|
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.HEAD;
|
import javax.ws.rs.HEAD;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.WebApplicationException;
|
import javax.ws.rs.WebApplicationException;
|
||||||
import javax.ws.rs.core.Context;
|
import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
@ -17,7 +18,8 @@ import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||||
import org.gcube.datatransfer.resolver.ConstantsResolver;
|
import org.gcube.datatransfer.resolver.ConstantsResolver;
|
||||||
import org.gcube.datatransfer.resolver.ConstantsResolver.CONTENT_DISPOSITION_VALUE;
|
import org.gcube.datatransfer.resolver.ConstantsResolver.CONTENT_DISPOSITION_VALUE;
|
||||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||||
import org.gcube.datatransfer.resolver.util.StorageHubMetadataResponseBuilder;
|
import org.gcube.datatransfer.resolver.shub.StorageHubMetadataResponseBuilder;
|
||||||
|
import org.gcube.datatransfer.resolver.util.ValidateContentDisposition;
|
||||||
import org.gcube.smartgears.utils.InnerMethodName;
|
import org.gcube.smartgears.utils.InnerMethodName;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -101,7 +103,7 @@ public class StorageHubResolver {
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("/{id}")
|
@Path("/{id}")
|
||||||
public Response download(@Context HttpServletRequest req) {
|
public Response download(@Context HttpServletRequest req, @QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition) {
|
||||||
logger.info(this.getClass().getSimpleName()+" GET download called");
|
logger.info(this.getClass().getSimpleName()+" GET download called");
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
@ -114,20 +116,9 @@ public class StorageHubResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Checking the optional parameter "Content-Disposition"
|
//Checking the optional parameter "Content-Disposition"
|
||||||
String contDisp = req.getParameter(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION);
|
CONTENT_DISPOSITION_VALUE dispositionValue = CONTENT_DISPOSITION_VALUE.attachment;
|
||||||
CONTENT_DISPOSITION_VALUE dispValue = CONTENT_DISPOSITION_VALUE.attachment;
|
|
||||||
//Validating the Content-Disposition value
|
//Validating the Content-Disposition value
|
||||||
if(contDisp!=null && !contDisp.isEmpty()) {
|
dispositionValue = ValidateContentDisposition.validValue(req, this.getClass(), help, contentDisposition);
|
||||||
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 msg = String.format("Wrong parameter: '%s=%s'. Valid '%s' values are: %s",ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION,contDisp,ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION,allowedValues);
|
|
||||||
logger.error(msg);
|
|
||||||
throw ExceptionManager.wrongParameterException(req, msg, StorageHubResolver.class, help);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
|
@ -135,7 +126,7 @@ public class StorageHubResolver {
|
||||||
StreamDescriptor descriptor = client.resolvePublicLink(id);
|
StreamDescriptor descriptor = client.resolvePublicLink(id);
|
||||||
ResponseBuilder response = Response.ok(descriptor.getStream());
|
ResponseBuilder response = Response.ok(descriptor.getStream());
|
||||||
|
|
||||||
response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id, dispValue);
|
response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id, dispositionValue);
|
||||||
return response.build();
|
return response.build();
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
|
|
@ -23,10 +23,12 @@ import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
|
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
|
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
|
||||||
import org.gcube.datatransfer.resolver.ConstantsResolver;
|
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.services.error.ExceptionManager;
|
||||||
import org.gcube.datatransfer.resolver.storage.StorageClientInstance;
|
import org.gcube.datatransfer.resolver.storage.StorageClientInstance;
|
||||||
import org.gcube.datatransfer.resolver.storage.StorageMetadataFile;
|
import org.gcube.datatransfer.resolver.storage.StorageMetadataFile;
|
||||||
import org.gcube.datatransfer.resolver.util.SingleFileStreamingOutput;
|
import org.gcube.datatransfer.resolver.util.SingleFileStreamingOutput;
|
||||||
|
import org.gcube.datatransfer.resolver.util.ValidateContentDisposition;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -47,7 +49,7 @@ public class StorageIDResolver {
|
||||||
protected static final String STORAGEID_RESOLVER = "storageid-resolver";
|
protected static final String STORAGEID_RESOLVER = "storageid-resolver";
|
||||||
private static final String STORAGE_ID = "storage-id";
|
private static final String STORAGE_ID = "storage-id";
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(StorageIDResolver.class);
|
private static final Logger LOG = LoggerFactory.getLogger(StorageIDResolver.class);
|
||||||
|
|
||||||
private static String help = "https://wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-ID_Resolver";
|
private static String help = "https://wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-ID_Resolver";
|
||||||
|
|
||||||
|
@ -69,16 +71,22 @@ public class StorageIDResolver {
|
||||||
@PathParam(STORAGE_ID) String storageId,
|
@PathParam(STORAGE_ID) String storageId,
|
||||||
@QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName,
|
@QueryParam(ConstantsResolver.QUERY_PARAM_FILE_NAME) String fileName,
|
||||||
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENT_TYPE) String contentType,
|
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENT_TYPE) String contentType,
|
||||||
@QueryParam(ConstantsResolver.QUERY_PARAM_VALIDATION) Boolean validation) throws WebApplicationException {
|
@QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition,
|
||||||
|
@QueryParam(ConstantsResolver.QUERY_PARAM_VALIDATION) boolean validation) throws WebApplicationException {
|
||||||
|
|
||||||
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
LOG.info(this.getClass().getSimpleName()+" GET starts...");
|
||||||
|
|
||||||
|
//Checking the optional parameter "Content-Disposition"
|
||||||
|
CONTENT_DISPOSITION_VALUE dispositionValue = CONTENT_DISPOSITION_VALUE.attachment;
|
||||||
|
//Validating the Content-Disposition value
|
||||||
|
dispositionValue = ValidateContentDisposition.validValue(req, this.getClass(), help, contentDisposition);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
if(storageId==null || storageId.isEmpty()){
|
if(storageId==null || storageId.isEmpty()){
|
||||||
logger.error(STORAGE_ID+" not found");
|
LOG.error(STORAGE_ID+" not found");
|
||||||
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter "+STORAGE_ID, StorageIDResolver.class, help);
|
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter "+STORAGE_ID, StorageIDResolver.class, help);
|
||||||
}
|
}
|
||||||
return resolveStorageId(req, storageId, fileName, contentType, validation);
|
return resolveStorageId(req, storageId, fileName, contentType, dispositionValue, validation);
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
|
|
||||||
if(!(e instanceof WebApplicationException)){
|
if(!(e instanceof WebApplicationException)){
|
||||||
|
@ -89,7 +97,7 @@ public class StorageIDResolver {
|
||||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), help);
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), help);
|
||||||
}
|
}
|
||||||
//ALREADY MANAGED AS WebApplicationException
|
//ALREADY MANAGED AS WebApplicationException
|
||||||
logger.error("Exception:", e);
|
LOG.error("Exception:", e);
|
||||||
throw (WebApplicationException) e;
|
throw (WebApplicationException) e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,13 +114,13 @@ public class StorageIDResolver {
|
||||||
* @return the response
|
* @return the response
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
protected static Response resolveStorageId(HttpServletRequest httpRequest, String storageId, String fileName, String contentType, Boolean validation) throws Exception{
|
protected static Response resolveStorageId(HttpServletRequest httpRequest, String storageId, String fileName, String contentType, CONTENT_DISPOSITION_VALUE contentDisposition, boolean validation) throws Exception{
|
||||||
|
|
||||||
logger.info("storage-id: "+storageId+", fileName: "+fileName+", contentType: "+contentType+", validation: "+validation);
|
LOG.info("storage-id: "+storageId+", fileName: "+fileName+", contentType: "+contentType+", validation: "+validation);
|
||||||
|
|
||||||
//Checking mandatory parameter storageId
|
//Checking mandatory parameter storageId
|
||||||
if (storageId == null || storageId.isEmpty()) {
|
if (storageId == null || storageId.isEmpty()) {
|
||||||
logger.error("storageId not found");
|
LOG.error("storageId not found");
|
||||||
throw ExceptionManager.badRequestException(httpRequest, "Missing mandatory path parameter "+STORAGE_ID, StorageIDResolver.class, help);
|
throw ExceptionManager.badRequestException(httpRequest, "Missing mandatory path parameter "+STORAGE_ID, StorageIDResolver.class, help);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,18 +128,18 @@ public class StorageIDResolver {
|
||||||
String toSEID = null;
|
String toSEID = null;
|
||||||
IClient iClient = null;
|
IClient iClient = null;
|
||||||
storageId = scInstance.getStorageId(); //IT SHOULD BE CHANGED es. removing the suffix '-VLT'
|
storageId = scInstance.getStorageId(); //IT SHOULD BE CHANGED es. removing the suffix '-VLT'
|
||||||
logger.info("I'm using the storageId {}",storageId);
|
LOG.info("I'm using the storageId {}",storageId);
|
||||||
try{
|
try{
|
||||||
iClient = scInstance.getStorageClient().getClient();
|
iClient = scInstance.getStorageClient().getClient();
|
||||||
toSEID = iClient.getId(storageId); //to Storage Encrypted ID
|
toSEID = iClient.getId(storageId); //to Storage Encrypted ID
|
||||||
logger.info("Decoded ID"+" = "+ toSEID);
|
LOG.info("Decoded ID"+" = "+ toSEID);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Storage Client Exception when getting file from storage: ", e);
|
LOG.error("Storage Client Exception when getting file from storage: ", e);
|
||||||
throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help);
|
throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(toSEID==null || toSEID.isEmpty()){
|
if(toSEID==null || toSEID.isEmpty()){
|
||||||
logger.error("Decrypted id for storageId: "+storageId +" is null or empty!");
|
LOG.error("Decrypted id for storageId: "+storageId +" is null or empty!");
|
||||||
throw ExceptionManager.notFoundException(httpRequest, "Error on decrypting the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageIDResolver.class, help);
|
throw ExceptionManager.notFoundException(httpRequest, "Error on decrypting the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageIDResolver.class, help);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,27 +148,32 @@ public class StorageIDResolver {
|
||||||
|
|
||||||
//READING THE METADATA OF FILE FROM STORAGE
|
//READING THE METADATA OF FILE FROM STORAGE
|
||||||
StorageMetadataFile metaFile = getStorageMetadataFile(iClient,toSEID);
|
StorageMetadataFile metaFile = getStorageMetadataFile(iClient,toSEID);
|
||||||
logger.debug("MetaFile retrieved from storage? "+ (metaFile!=null));
|
LOG.debug("MetaFile retrieved from storage? "+ (metaFile!=null));
|
||||||
|
|
||||||
if(metaFile!=null) {
|
if(metaFile!=null) {
|
||||||
//Reading the fileName from Storage Metadata only if the passed fileName is null
|
//Reading the fileName from Storage Metadata only if the passed fileName is null
|
||||||
if(fileName==null || fileName.isEmpty())
|
if(fileName==null || fileName.isEmpty()) {
|
||||||
fileName= metaFile.getName();
|
fileName= metaFile.getName();
|
||||||
|
LOG.debug("Read filename {} from {}", fileName, StorageMetadataFile.class.getSimpleName());
|
||||||
|
}
|
||||||
|
|
||||||
//Reading the contentType from Storage Metadata only if the passed contentType is null
|
//Reading the contentType from Storage Metadata only if the passed contentType is null
|
||||||
if(contentType==null || contentType.isEmpty())
|
if(contentType==null || contentType.isEmpty()) {
|
||||||
contentType = metaFile.getMimeType();
|
contentType = metaFile.getMimeType();
|
||||||
|
LOG.debug("Read contentType {} from {}", contentType, StorageMetadataFile.class.getSimpleName());
|
||||||
|
}
|
||||||
|
|
||||||
//Reading the content size
|
//Reading the content size
|
||||||
size = metaFile.getSize();
|
size = metaFile.getSize();
|
||||||
|
LOG.debug("Read size {} from {}", size, StorageMetadataFile.class.getSimpleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
//CHECKING TO DEFAULT METADATA
|
//CHECKING TO DEFAULT METADATA
|
||||||
fileName = fileName==null || fileName.isEmpty()?ConstantsResolver.DEFAULT_FILENAME_FROM_STORAGE_MANAGER:fileName;
|
fileName = fileName==null || fileName.isEmpty()?ConstantsResolver.DEFAULT_FILENAME_FROM_STORAGE_MANAGER:fileName;
|
||||||
logger.info("filename retrieved is {}",fileName);
|
LOG.info("filename retrieved is {}",fileName);
|
||||||
|
|
||||||
contentType = contentType==null || contentType.isEmpty()?ConstantsResolver.DEFAULT_CONTENTTYPE_UNKNOWN_UNKNOWN:contentType;
|
contentType = contentType==null || contentType.isEmpty()?ConstantsResolver.DEFAULT_CONTENTTYPE_UNKNOWN_UNKNOWN:contentType;
|
||||||
logger.info("contentType used is {}",contentType);
|
LOG.info("contentType used is {}",contentType);
|
||||||
|
|
||||||
//Building the response
|
//Building the response
|
||||||
InputStream streamToWrite=iClient.get().RFileAsInputStream(toSEID); //input stream
|
InputStream streamToWrite=iClient.get().RFileAsInputStream(toSEID); //input stream
|
||||||
|
@ -168,7 +181,7 @@ public class StorageIDResolver {
|
||||||
|
|
||||||
ResponseBuilder response = Response
|
ResponseBuilder response = Response
|
||||||
.ok(so)
|
.ok(so)
|
||||||
.header(ConstantsResolver.CONTENT_DISPOSITION,"attachment; filename=\""+fileName+"\"")
|
.header(ConstantsResolver.CONTENT_DISPOSITION, contentDisposition.name()+"; filename=\""+fileName+"\"")
|
||||||
.header(ConstantsResolver.CONTENT_LENGTH, size)
|
.header(ConstantsResolver.CONTENT_LENGTH, size)
|
||||||
.header("Content-Type",contentType);
|
.header("Content-Type",contentType);
|
||||||
|
|
||||||
|
@ -195,14 +208,14 @@ public class StorageIDResolver {
|
||||||
@PathParam(STORAGE_ID) String storageId,
|
@PathParam(STORAGE_ID) String storageId,
|
||||||
@QueryParam(ConstantsResolver.HPC) boolean hproxycheck) throws WebApplicationException {
|
@QueryParam(ConstantsResolver.HPC) boolean hproxycheck) throws WebApplicationException {
|
||||||
|
|
||||||
logger.info(this.getClass().getSimpleName()+" HEAD starts...");
|
LOG.info(this.getClass().getSimpleName()+" HEAD starts...");
|
||||||
logger.info("The query string is: {}", req.getQueryString());
|
LOG.info("The query string is: {}", req.getQueryString());
|
||||||
logger.info("Query parameter {} is {}", ConstantsResolver.HPC, hproxycheck);
|
LOG.info("Query parameter {} is {}", ConstantsResolver.HPC, hproxycheck);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
//THIS IS FOR HPROXY CHECK
|
//THIS IS FOR HPROXY CHECK
|
||||||
if(hproxycheck){
|
if(hproxycheck){
|
||||||
logger.trace("returning status 200 for Hproxy check");
|
LOG.trace("returning status 200 for Hproxy check");
|
||||||
ResponseBuilder response = Response.status(HttpStatus.SC_OK);
|
ResponseBuilder response = Response.status(HttpStatus.SC_OK);
|
||||||
return response.build();
|
return response.build();
|
||||||
}
|
}
|
||||||
|
@ -219,7 +232,7 @@ public class StorageIDResolver {
|
||||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), help);
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), help);
|
||||||
}
|
}
|
||||||
//ALREADY MANAGED AS WebApplicationException
|
//ALREADY MANAGED AS WebApplicationException
|
||||||
logger.error("Exception:", e);
|
LOG.error("Exception:", e);
|
||||||
throw (WebApplicationException) e;
|
throw (WebApplicationException) e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,30 +247,30 @@ public class StorageIDResolver {
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
protected Response validationPayload(HttpServletRequest httpRequest, String storageId) throws Exception{
|
protected Response validationPayload(HttpServletRequest httpRequest, String storageId) throws Exception{
|
||||||
logger.info("validationPayload called");
|
LOG.info("validationPayload called");
|
||||||
|
|
||||||
//Checking mandatory parameter storageId
|
//Checking mandatory parameter storageId
|
||||||
if (storageId == null || storageId.isEmpty()) {
|
if (storageId == null || storageId.isEmpty()) {
|
||||||
logger.warn("storageId not found");
|
LOG.warn("storageId not found");
|
||||||
throw ExceptionManager.badRequestException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, this.getClass(), help);
|
throw ExceptionManager.badRequestException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, this.getClass(), help);
|
||||||
}
|
}
|
||||||
StorageClientInstance client = buildStorageClientInstance(storageId);
|
StorageClientInstance client = buildStorageClientInstance(storageId);
|
||||||
String toSEID = null;
|
String toSEID = null;
|
||||||
IClient iClient = null;
|
IClient iClient = null;
|
||||||
storageId = client.getStorageId(); //IT SHOULD BE CHANGED es. removing the suffix '-VLT'
|
storageId = client.getStorageId(); //IT SHOULD BE CHANGED es. removing the suffix '-VLT'
|
||||||
logger.info("I'm using the storageId {}",storageId);
|
LOG.info("I'm using the storageId {}",storageId);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
iClient = client.getStorageClient().getClient();
|
iClient = client.getStorageClient().getClient();
|
||||||
toSEID = iClient.getId(storageId); //to Storage Encrypted ID
|
toSEID = iClient.getId(storageId); //to Storage Encrypted ID
|
||||||
logger.debug("Decoded ID"+" = "+ toSEID);
|
LOG.debug("Decoded ID"+" = "+ toSEID);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Storage Client Exception when getting file from storage: ", e);
|
LOG.error("Storage Client Exception when getting file from storage: ", e);
|
||||||
throw ExceptionManager.internalErrorException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help);
|
throw ExceptionManager.internalErrorException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(toSEID==null || toSEID.isEmpty()){
|
if(toSEID==null || toSEID.isEmpty()){
|
||||||
logger.error("Decrypted id for storageId: "+storageId +" is null or empty!");
|
LOG.error("Decrypted id for storageId: "+storageId +" is null or empty!");
|
||||||
throw ExceptionManager.notFoundException(httpRequest, "Error on decrypting the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageIDResolver.class, help);
|
throw ExceptionManager.notFoundException(httpRequest, "Error on decrypting the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageIDResolver.class, help);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,20 +279,25 @@ public class StorageIDResolver {
|
||||||
String contentType = ConstantsResolver.DEFAULT_CONTENTTYPE_UNKNOWN_UNKNOWN;
|
String contentType = ConstantsResolver.DEFAULT_CONTENTTYPE_UNKNOWN_UNKNOWN;
|
||||||
//READING THE METADATA OF FILE FROM STORAGE
|
//READING THE METADATA OF FILE FROM STORAGE
|
||||||
StorageMetadataFile metadataFile = getStorageMetadataFile(iClient,toSEID);
|
StorageMetadataFile metadataFile = getStorageMetadataFile(iClient,toSEID);
|
||||||
logger.debug("MetaFile retrieved from storage? "+ (metadataFile!=null));
|
LOG.debug("MetaFile retrieved from storage? "+ (metadataFile!=null));
|
||||||
long size = 0;
|
long size = 0;
|
||||||
|
|
||||||
if (metadataFile != null) {
|
if (metadataFile != null) {
|
||||||
|
|
||||||
// Reading the fileName from Storage Metadata only if it is not null
|
// Reading the fileName from Storage Metadata only if it is not null
|
||||||
if (metadataFile.getName() != null)
|
if (metadataFile.getName() != null) {
|
||||||
fileName = metadataFile.getName();
|
fileName = metadataFile.getName();
|
||||||
|
LOG.debug("Read filename {} from {}", fileName, StorageMetadataFile.class.getSimpleName());
|
||||||
|
}
|
||||||
|
|
||||||
// Reading the contentType from Storage Metadata only if it is not null
|
// Reading the contentType from Storage Metadata only if it is not null
|
||||||
if (metadataFile.getMimeType() != null)
|
if (metadataFile.getMimeType() != null) {
|
||||||
contentType = metadataFile.getMimeType();
|
contentType = metadataFile.getMimeType();
|
||||||
|
LOG.debug("Read contentType {} from {}", contentType, StorageMetadataFile.class.getSimpleName());
|
||||||
|
}
|
||||||
|
|
||||||
size = metadataFile.getSize();
|
size = metadataFile.getSize();
|
||||||
|
LOG.debug("Read size {} from {}", size, StorageMetadataFile.class.getSimpleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Building the response
|
//Building the response
|
||||||
|
@ -290,16 +308,16 @@ public class StorageIDResolver {
|
||||||
ResponseBuilder response = null;
|
ResponseBuilder response = null;
|
||||||
try {
|
try {
|
||||||
c = streamToWrite.read(bytes);
|
c = streamToWrite.read(bytes);
|
||||||
logger.info(c+" byte read from InputStream");
|
LOG.info(c+" byte read from InputStream");
|
||||||
if(c>0){
|
if(c>0){
|
||||||
logger.info("at least 1 byte read, returning status 200");
|
LOG.info("at least 1 byte read, returning status 200");
|
||||||
IOUtils.closeQuietly(streamToWrite);
|
IOUtils.closeQuietly(streamToWrite);
|
||||||
response = Response.status(HttpStatus.SC_OK);
|
response = Response.status(HttpStatus.SC_OK);
|
||||||
}else
|
}else
|
||||||
throw ExceptionManager.notFoundException(httpRequest, "The file with id: "+storageId+" is missing in the storage", StorageIDResolver.class, help);
|
throw ExceptionManager.notFoundException(httpRequest, "The file with id: "+storageId+" is missing in the storage", StorageIDResolver.class, help);
|
||||||
}
|
}
|
||||||
catch (IOException e2) {
|
catch (IOException e2) {
|
||||||
logger.error("Error on validating the file: ",e2);
|
LOG.error("Error on validating the file: ",e2);
|
||||||
throw ExceptionManager.internalErrorException(httpRequest, "Error on validating the file with id: "+storageId, StorageIDResolver.class, help);
|
throw ExceptionManager.internalErrorException(httpRequest, "Error on validating the file with id: "+storageId, StorageIDResolver.class, help);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,7 +382,7 @@ public class StorageIDResolver {
|
||||||
return new StorageMetadataFile(myFile, size);
|
return new StorageMetadataFile(myFile, size);
|
||||||
|
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
logger.warn("Error on getting file metadata from storage, printing this warning and trying to continue..", e);
|
LOG.warn("Error on getting file metadata from storage, printing this warning and trying to continue..", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.gcube.datatransfer.resolver.util;
|
package org.gcube.datatransfer.resolver.shub;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.ws.rs.core.Response.ResponseBuilder;
|
import javax.ws.rs.core.Response.ResponseBuilder;
|
||||||
|
@ -11,6 +11,7 @@ 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.ConstantsResolver;
|
import org.gcube.datatransfer.resolver.ConstantsResolver;
|
||||||
import org.gcube.datatransfer.resolver.ConstantsResolver.CONTENT_DISPOSITION_VALUE;
|
import org.gcube.datatransfer.resolver.ConstantsResolver.CONTENT_DISPOSITION_VALUE;
|
||||||
|
import org.gcube.datatransfer.resolver.util.Util;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,7 +59,12 @@ public class StorageHubMetadataResponseBuilder {
|
||||||
|
|
||||||
//Managing "Content-Type"
|
//Managing "Content-Type"
|
||||||
if (streamDescriptor.getContentType()!= null && !streamDescriptor.getContentType().isEmpty())
|
if (streamDescriptor.getContentType()!= null && !streamDescriptor.getContentType().isEmpty())
|
||||||
responseBuilder.header("Content-Type", streamDescriptor.getContentType()+"; charset=utf-8");
|
responseBuilder.header("Content-Type", streamDescriptor.getContentType());
|
||||||
|
|
||||||
|
//Managing "Content-Lenght"
|
||||||
|
if(streamDescriptor.getContentLenght()>0) {
|
||||||
|
responseBuilder.header("Content-Length", streamDescriptor.getContentLenght());
|
||||||
|
}
|
||||||
|
|
||||||
//Managing "ETag"
|
//Managing "ETag"
|
||||||
//Here is not feasible because the entityId is cripted
|
//Here is not feasible because the entityId is cripted
|
|
@ -0,0 +1,53 @@
|
||||||
|
package org.gcube.datatransfer.resolver.util;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
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.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class ValidateContentDisposition.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||||
|
*
|
||||||
|
* Oct 2, 2019
|
||||||
|
*/
|
||||||
|
public class ValidateContentDisposition {
|
||||||
|
|
||||||
|
public static Logger LOG = LoggerFactory.getLogger(GetResponseRecordFilter.class);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Valid value.
|
||||||
|
*
|
||||||
|
* @param req the req
|
||||||
|
* @param resolverClass the resolver class
|
||||||
|
* @param helpURI the help URI
|
||||||
|
* @param contentDispositionValue the content disposition value
|
||||||
|
* @return the content disposition value
|
||||||
|
*/
|
||||||
|
public static CONTENT_DISPOSITION_VALUE validValue(HttpServletRequest req, Class resolverClass, String helpURI, String contentDispositionValue){
|
||||||
|
|
||||||
|
CONTENT_DISPOSITION_VALUE toDispositionValue = CONTENT_DISPOSITION_VALUE.attachment;
|
||||||
|
//Validating the Content-Disposition value
|
||||||
|
if(contentDispositionValue!=null && !contentDispositionValue.isEmpty()) {
|
||||||
|
try {
|
||||||
|
//It must have a value of: "inline" or "attachement"
|
||||||
|
toDispositionValue = ConstantsResolver.CONTENT_DISPOSITION_VALUE.valueOf(contentDispositionValue);
|
||||||
|
}catch (Exception e) {
|
||||||
|
String allowedValues = String.format("{%s,%s}", CONTENT_DISPOSITION_VALUE.inline,CONTENT_DISPOSITION_VALUE.attachment);
|
||||||
|
String msg = String.format("Wrong parameter: '%s=%s'. Valid '%s' values are: %s",ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION,contentDispositionValue,ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION,allowedValues);
|
||||||
|
LOG.error(msg);
|
||||||
|
throw ExceptionManager.wrongParameterException(req, msg, resolverClass, helpURI);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return toDispositionValue;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue