# WARNING: head commit changed in the meantime
removed unused test classes
This commit is contained in:
parent
46fec84b55
commit
dac6be27ce
|
@ -164,5 +164,8 @@
|
||||||
date="${buildDate}">
|
date="${buildDate}">
|
||||||
<Change>[Feature #17630] Support parametric Content-Disposition
|
<Change>[Feature #17630] Support parametric Content-Disposition
|
||||||
</Change>
|
</Change>
|
||||||
|
<Change>[Bug #17650] Bug #17650: URI-Resolver: HEAD request to
|
||||||
|
StorageID link does not return the "content-disposition
|
||||||
|
</Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
</ReleaseNotes>
|
</ReleaseNotes>
|
|
@ -2,6 +2,7 @@ package org.gcube.datatransfer.resolver.requesthandler;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
@ -14,6 +15,8 @@ import javax.ws.rs.container.PreMatching;
|
||||||
import javax.ws.rs.container.ResourceContext;
|
import javax.ws.rs.container.ResourceContext;
|
||||||
import javax.ws.rs.core.Application;
|
import javax.ws.rs.core.Application;
|
||||||
import javax.ws.rs.core.Context;
|
import javax.ws.rs.core.Context;
|
||||||
|
import javax.ws.rs.core.MultivaluedMap;
|
||||||
|
import javax.ws.rs.core.UriBuilder;
|
||||||
import javax.ws.rs.ext.Provider;
|
import javax.ws.rs.ext.Provider;
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
@ -71,7 +74,21 @@ 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();
|
||||||
|
|
||||||
|
//HOW TO READ THE QUERY STRING
|
||||||
|
/*MultivaluedMap<String, String> queryParameters = reqContext.getUriInfo().getQueryParameters();
|
||||||
|
String queryString = "";
|
||||||
|
try {
|
||||||
|
queryString = Util.toQueryString(queryParameters);
|
||||||
|
}catch (Exception e) {
|
||||||
|
//silent
|
||||||
|
log.warn("Error on reading the query string, trying to continue...");
|
||||||
|
}
|
||||||
|
log.debug("The query string is: {}", queryString);
|
||||||
|
*/
|
||||||
|
|
||||||
log.debug("The path is: {}", path);
|
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");
|
||||||
|
@ -103,7 +120,7 @@ public class RequestHandler implements ContainerRequestFilter, ContainerResponse
|
||||||
|
|
||||||
//Try to manage as Catalogue Request ctlg, ctlg-p, etc.
|
//Try to manage as Catalogue Request ctlg, ctlg-p, etc.
|
||||||
if(!resourceToRedirectFound) {
|
if(!resourceToRedirectFound) {
|
||||||
log.info("Trying to manage as hard-coded case: {}", ConstantsResolver.resourcesHardCoded.toString());
|
log.info("Trying to manage as hard-coded case among cases: {}", Arrays.asList(ConstantsResolver.resourcesHardCoded).toString());
|
||||||
String[] hardCode = ConstantsResolver.resourcesHardCoded;
|
String[] hardCode = ConstantsResolver.resourcesHardCoded;
|
||||||
|
|
||||||
for (String resource : hardCode) {
|
for (String resource : hardCode) {
|
||||||
|
@ -134,7 +151,17 @@ public class RequestHandler implements ContainerRequestFilter, ContainerResponse
|
||||||
log.info("No resource/service found to manage the input request '{}'", path);
|
log.info("No resource/service found to manage the input request '{}'", path);
|
||||||
String newPath = String.format("/%s/%s", ConstantsResolver.defaultServiceToRedirect,path);
|
String newPath = String.format("/%s/%s", ConstantsResolver.defaultServiceToRedirect,path);
|
||||||
//log.debug("The path to redirect is '{}'", newPath);
|
//log.debug("The path to redirect is '{}'", newPath);
|
||||||
URI newRequestURI = reqContext.getUriInfo().getBaseUriBuilder().path(newPath).build();
|
//URI newRequestURI = reqContext.getUriInfo().getBaseUriBuilder().path(newPath).build();
|
||||||
|
UriBuilder uriBuilder = reqContext.getUriInfo().getBaseUriBuilder();
|
||||||
|
//ADDING THE INPUT QUERY STRING
|
||||||
|
MultivaluedMap<String, String> queryParameters = reqContext.getUriInfo().getQueryParameters();
|
||||||
|
for (String param : queryParameters.keySet()) {
|
||||||
|
List<String> values = queryParameters.get(param);
|
||||||
|
if(values!=null && !values.isEmpty())
|
||||||
|
uriBuilder.queryParam(param,values.toArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
URI newRequestURI = uriBuilder.path(newPath).build();
|
||||||
log.info("Redirect to URI path '{}'", newRequestURI.toString());
|
log.info("Redirect to URI path '{}'", newRequestURI.toString());
|
||||||
reqContext.setRequestUri(newRequestURI);
|
reqContext.setRequestUri(newRequestURI);
|
||||||
}
|
}
|
||||||
|
@ -152,4 +179,5 @@ public class RequestHandler implements ContainerRequestFilter, ContainerResponse
|
||||||
log.info("Token and Scope Provider reset called");
|
log.info("Token and Scope Provider reset called");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -24,6 +24,7 @@ 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.services.error.ExceptionManager;
|
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||||
|
import org.gcube.datatransfer.resolver.services.tobackward.StorageMetadataFile;
|
||||||
import org.gcube.datatransfer.resolver.storage.StorageClientInstance;
|
import org.gcube.datatransfer.resolver.storage.StorageClientInstance;
|
||||||
import org.gcube.datatransfer.resolver.util.SingleFileStreamingOutput;
|
import org.gcube.datatransfer.resolver.util.SingleFileStreamingOutput;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -46,8 +47,8 @@ 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 Logger logger = LoggerFactory.getLogger(StorageIDResolver.class);
|
private static final Logger logger = 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";
|
||||||
|
|
||||||
|
|
||||||
|
@ -134,31 +135,27 @@ public class StorageIDResolver {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
long size = iClient.getSize().RFileById(toSEID);
|
//long size = iClient.getSize().RFileById(toSEID);
|
||||||
|
long size = 0;
|
||||||
try{
|
|
||||||
|
//READING THE METADATA OF FILE FROM STORAGE
|
||||||
MyFile file = iClient.getMetaFile().RFile(toSEID);
|
StorageMetadataFile metaFile = getStorageMetadataFile(iClient,toSEID);
|
||||||
logger.debug("MetaFile retrieved from storage? "+ (file!=null));
|
logger.debug("MetaFile retrieved from storage? "+ (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= file.getName();
|
fileName= metaFile.getName();
|
||||||
|
|
||||||
//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 = file.getMimeType()
|
contentType = metaFile.getMimeType();
|
||||||
/**
|
|
||||||
* Gets the storage client instance.
|
//Reading the content size
|
||||||
*
|
size = metaFile.getSize();
|
||||||
* @param storageId the storage id
|
|
||||||
* @return the storage client instance
|
|
||||||
* @throws Exception the exception
|
|
||||||
*/;
|
|
||||||
|
|
||||||
}catch (Exception e) {
|
|
||||||
logger.warn("Error when getting file metadata from storage, printing this warning and trying to continue..", e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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);
|
logger.info("filename retrieved is {}",fileName);
|
||||||
|
|
||||||
|
@ -172,15 +169,16 @@ public class StorageIDResolver {
|
||||||
ResponseBuilder response = Response
|
ResponseBuilder response = Response
|
||||||
.ok(so)
|
.ok(so)
|
||||||
.header(ConstantsResolver.CONTENT_DISPOSITION,"attachment; filename=\""+fileName+"\"")
|
.header(ConstantsResolver.CONTENT_DISPOSITION,"attachment; filename=\""+fileName+"\"")
|
||||||
.header(ConstantsResolver.CONTENT_LENGTH, size);
|
.header(ConstantsResolver.CONTENT_LENGTH, size)
|
||||||
|
.header("Content-Type",contentType);
|
||||||
|
|
||||||
if (contentType!= null)
|
// if (contentType!= null)
|
||||||
response.header("Content-Type",contentType);
|
// response.header("Content-Type",contentType);
|
||||||
|
|
||||||
return response.build();
|
return response.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Http do head.
|
* Http do head.
|
||||||
|
@ -195,13 +193,15 @@ public class StorageIDResolver {
|
||||||
@Path("/{storage-id}")
|
@Path("/{storage-id}")
|
||||||
public Response httpDoHead(@Context HttpServletRequest req,
|
public Response httpDoHead(@Context HttpServletRequest req,
|
||||||
@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...");
|
logger.info(this.getClass().getSimpleName()+" HEAD starts...");
|
||||||
|
logger.info("The query string is: {}", req.getQueryString());
|
||||||
|
logger.info("Query parameter {} is {}", ConstantsResolver.HPC, hproxycheck);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
//THIS IS FOR HPROXY CHECK
|
//THIS IS FOR HPROXY CHECK
|
||||||
if(hproxycheck==null || hproxycheck){
|
if(hproxycheck){
|
||||||
logger.trace("returning status 200 for Hproxy check");
|
logger.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();
|
||||||
|
@ -234,6 +234,7 @@ 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");
|
||||||
|
|
||||||
//Checking mandatory parameter storageId
|
//Checking mandatory parameter storageId
|
||||||
if (storageId == null || storageId.isEmpty()) {
|
if (storageId == null || storageId.isEmpty()) {
|
||||||
|
@ -245,6 +246,7 @@ public class StorageIDResolver {
|
||||||
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);
|
logger.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
|
||||||
|
@ -259,6 +261,26 @@ public class StorageIDResolver {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SETTING DEFAULT METADATA
|
||||||
|
String fileName = ConstantsResolver.DEFAULT_FILENAME_FROM_STORAGE_MANAGER;
|
||||||
|
String contentType = ConstantsResolver.DEFAULT_CONTENTTYPE_UNKNOWN_UNKNOWN;
|
||||||
|
//READING THE METADATA OF FILE FROM STORAGE
|
||||||
|
StorageMetadataFile metadataFile = getStorageMetadataFile(iClient,toSEID);
|
||||||
|
logger.debug("MetaFile retrieved from storage? "+ (metadataFile!=null));
|
||||||
|
long size = 0;
|
||||||
|
|
||||||
|
if (metadataFile != null) {
|
||||||
|
|
||||||
|
// Reading the fileName from Storage Metadata only if it is not null
|
||||||
|
if (metadataFile.getName() != null)
|
||||||
|
fileName = metadataFile.getName();
|
||||||
|
|
||||||
|
// Reading the contentType from Storage Metadata only if it is not null
|
||||||
|
if (metadataFile.getMimeType() != null)
|
||||||
|
contentType = metadataFile.getMimeType();
|
||||||
|
|
||||||
|
size = metadataFile.getSize();
|
||||||
|
}
|
||||||
|
|
||||||
//Building the response
|
//Building the response
|
||||||
InputStream streamToWrite=iClient.get().RFileAsInputStream(toSEID); //input stream
|
InputStream streamToWrite=iClient.get().RFileAsInputStream(toSEID); //input stream
|
||||||
|
@ -283,7 +305,12 @@ public class StorageIDResolver {
|
||||||
|
|
||||||
if(response==null)
|
if(response==null)
|
||||||
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);
|
||||||
|
|
||||||
|
response = response
|
||||||
|
.header("Content-Type", contentType)
|
||||||
|
.header(ConstantsResolver.CONTENT_LENGTH, size)
|
||||||
|
.header(ConstantsResolver.CONTENT_DISPOSITION,"attachment; filename=\""+fileName+"\"");
|
||||||
|
|
||||||
return response.build();
|
return response.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -312,8 +339,35 @@ public class StorageIDResolver {
|
||||||
|
|
||||||
return new StorageClientInstance(client, memory, storageId);
|
return new StorageClientInstance(client, memory, storageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the storage metadata file.
|
||||||
|
*
|
||||||
|
* @param iClient the i client
|
||||||
|
* @param toSEID the to SEID
|
||||||
|
* @return the storage metadata file
|
||||||
|
*/
|
||||||
|
public static StorageMetadataFile getStorageMetadataFile(IClient iClient, String toSEID) {
|
||||||
|
|
||||||
|
try{
|
||||||
|
if(iClient==null)
|
||||||
|
throw new Exception("The "+IClient.class.getName()+" is not instancied correclty. It is null!");
|
||||||
|
|
||||||
|
if(toSEID==null || toSEID.isEmpty())
|
||||||
|
throw new Exception("Invalid input identifier. The input Storage Encrypted ID is null or empty!");
|
||||||
|
|
||||||
|
long size = iClient.getSize().RFileById(toSEID);
|
||||||
|
MyFile myFile = iClient.getMetaFile().RFile(toSEID);
|
||||||
|
|
||||||
|
return new StorageMetadataFile(myFile, size);
|
||||||
|
|
||||||
|
}catch (Exception e) {
|
||||||
|
logger.warn("Error on getting file metadata from storage, printing this warning and trying to continue..", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.datatransfer.resolver.util;
|
package org.gcube.datatransfer.resolver.util;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.ws.rs.core.MultivaluedMap;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -94,5 +97,32 @@ public class Util {
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To query string.
|
||||||
|
*
|
||||||
|
* @param queryParameters the query parameters
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
public static String toQueryString(MultivaluedMap<String, String> queryParameters) {
|
||||||
|
|
||||||
|
if(queryParameters==null || queryParameters.isEmpty())
|
||||||
|
return "";
|
||||||
|
|
||||||
|
StringBuilder queryStringBuilder = new StringBuilder();
|
||||||
|
for (String key : queryParameters.keySet()) {
|
||||||
|
List<String> values = queryParameters.get(key);
|
||||||
|
for (String value : values) {
|
||||||
|
queryStringBuilder.append(String.format("%s=%s",key,value));
|
||||||
|
queryStringBuilder.append("&"); //The series of pairs is separated by the ampersand, '&'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String queryString = queryStringBuilder.toString();
|
||||||
|
queryString = queryString.endsWith("&")?queryString.substring(0,queryString.length()-1):queryString;
|
||||||
|
log.debug("Query string built: {}",queryString);
|
||||||
|
return queryString;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue