1298: Workspace: Update public link generation
Task-Url: https://support.d4science.org/issues/1298 Updated as following: In case of error on decrypt or get input stream a 404 error is sent In case of error on get Metadata (from storage), file is download with default value for name and mime type git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@122326 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9e2f1f0798
commit
ef4bc1948c
|
@ -20,11 +20,12 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Class StorageIDResolver.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Sep 21, 2015
|
||||
* Jan 19, 2016
|
||||
*/
|
||||
public class StorageIDResolver extends HttpServlet {
|
||||
|
||||
|
@ -90,17 +91,38 @@ public class StorageIDResolver extends HttpServlet {
|
|||
|
||||
logger.info(SMP_ID+" = "+ smpID);
|
||||
InputStream in = null;
|
||||
try {
|
||||
String toSEID = null;
|
||||
|
||||
try {
|
||||
OutputStream out = response.getOutputStream();
|
||||
StorageClient client = new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), StorageIDResolver.class.getName(), AccessType.PUBLIC);
|
||||
|
||||
try{
|
||||
StorageClient client = new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), StorageIDResolver.class.getName(), AccessType.PUBLIC);
|
||||
IClient icClient = client.getClient();
|
||||
String toSEID = icClient.getId(smpID); //to Storage Encrypted ID
|
||||
toSEID = icClient.getId(smpID); //to Storage Encrypted ID
|
||||
logger.debug("Decoded ID"+" = "+ toSEID);
|
||||
|
||||
if(toSEID==null){
|
||||
String error = "Decrypted id is null, thrown exception!";
|
||||
throw new Exception(error);
|
||||
}
|
||||
|
||||
in=icClient.get().RFileAsInputStream(toSEID); //input stream
|
||||
|
||||
}catch (Exception e) {
|
||||
response.sendError(404);
|
||||
logger.error("Storage Client Exception when getting file from storage: ", e);
|
||||
return;
|
||||
}
|
||||
|
||||
//CASE InputStream NULL
|
||||
if(in==null){
|
||||
logger.error("Input stream returned from storage is null, sending status error 404");
|
||||
sendErrorQuietly(response, 404);
|
||||
return;
|
||||
}
|
||||
|
||||
try{
|
||||
MyFile file = client.getClient().getMetaFile().RFile(toSEID);
|
||||
logger.debug("MetaFile retrieved from storage? "+ (file!=null));
|
||||
|
||||
|
@ -115,16 +137,7 @@ public class StorageIDResolver extends HttpServlet {
|
|||
}
|
||||
|
||||
}catch (Exception e) {
|
||||
response.sendError(404);
|
||||
logger.error("Storage Client Exception:", e);
|
||||
return;
|
||||
}
|
||||
|
||||
//CASE InputStream NULL
|
||||
if(in==null){
|
||||
logger.warn("Input stream is null, sending status error 404");
|
||||
sendErrorQuietly(response, 404);
|
||||
return;
|
||||
logger.warn("Error when getting file metadata from storage, printing this warning and trying to continue..", e);
|
||||
}
|
||||
|
||||
//VALIDATING PARAMETERS: FILENAME AND CONTENT TYPE
|
||||
|
|
Loading…
Reference in New Issue