1990: GeoExplorer enhancements: WPS integration

Task-Url: https://support.d4science.org/issues/1990

Updated Storage ID Resolver according to #1959

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@122317 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-01-19 14:23:29 +00:00
parent 56ab11b3ec
commit 79ba6fa01e
2 changed files with 38 additions and 32 deletions

View File

@ -19,6 +19,12 @@
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.1-4-0"
date="2015-09-21">
<Change>[Feature #416] Added code to read fileName and content-type (mime type) from Storage </Change>
<Change>[Feature #416] Added code to read fileName and content-type
(mime type) from Storage </Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.1-5-0"
date="2016-01-19">
<Change>[Feature #1925] Updated the method to resolve gCube Storage ID</Change>
<Change>[Feature #1925] Added class UriResolverRewriteFilter to filter the different public link types</Change>
</Changeset>
</ReleaseNotes>

View File

@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory;
public class StorageIDResolver extends HttpServlet {
private static final long serialVersionUID = -5208562956923156697L;
protected static final String SMP_ID = "smp-id";
protected static final String VALIDATION = "validation";
protected static final String CONTENT_TYPE = "contentType";
@ -51,7 +51,7 @@ public class StorageIDResolver extends HttpServlet {
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
String smpID =null;
String fileName =null;
String contentType =null;
@ -66,73 +66,73 @@ public class StorageIDResolver extends HttpServlet {
response.sendError(404);
return;
}
fileName = request.getParameter(FILE_NAME);
if (fileName == null || fileName.equals("")) {
logger.warn(FILE_NAME+" not found");
fileName = null;
}
contentType = request.getParameter(CONTENT_TYPE);
if (contentType == null || contentType.equals("")) {
logger.warn(CONTENT_TYPE+" not found");
contentType = null;
}
String validation = request.getParameter(VALIDATION);
validatingURI = Boolean.parseBoolean(validation);
logger.info("validation? "+validatingURI);
//we should not unescape the filename with spaces
logger.debug(SMP_ID+" = "+ smpID);
InputStream in = null;
try {
OutputStream out = response.getOutputStream();
try{
StorageClient client = new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), StorageIDResolver.class.getName(), AccessType.PUBLIC);
IClient icClient = client.getClient();
in=icClient.get().RFileAsInputStream(smpID); //input stream
String toSEID = icClient.getId(smpID); //to Storage Encrypted ID
in=icClient.get().RFileAsInputStream(toSEID); //input stream
MyFile file = client.getClient().getMetaFile().RFile(smpID);
logger.debug("MetaFile retrieved from storage? "+ (file!=null));
if(fileName==null || fileName.isEmpty()){ //filename
fileName = file.getName();
logger.debug("filename read from MetaFile: "+ fileName);
}
if(contentType==null || contentType.isEmpty()){ //mime type
contentType = file.getMimeType();
logger.debug("contentType read from MetaFile: "+ contentType);
}
}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;
}
//VALIDATING PARAMETERS: FILENAME AND CONTENT TYPE
if(fileName==null || fileName.isEmpty())
fileName = ConstantsHttpResolver.DEFAULT_FILENAME_FROM_STORAGE_MANAGER;
if(contentType==null || contentType.isEmpty())
contentType = ConstantsHttpResolver.DEFAULT_CONTENTTYPE_UNKNOWN_UNKNOWN;
response.addHeader(ConstantsHttpResolver.CONTENT_DISPOSITION, "attachment; filename=" +fileName);
response.setContentType(contentType);
@ -146,29 +146,29 @@ public class StorageIDResolver extends HttpServlet {
IOUtils.closeQuietly(in);
response.setStatus(200);
return;
}
}
}
try {
IOUtils.copy(in, out);
} catch (IOException e){
logger.warn("IOException class name: "+e.getClass().getSimpleName());
if (e.getClass().getSimpleName().equals("ClientAbortException"))
logger.warn("Skipping ClientAbortException: "+e.getMessage());
else
throw e; //Sending Exceptions
} catch (NullPointerException e) {
logger.warn("NullPointerException during copy, skipping printStrackTrace");
sendErrorQuietly(response, 404);
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
}
} catch (Exception e) {
logger.error("Exception:", e);
IOUtils.closeQuietly(in);
@ -177,7 +177,7 @@ public class StorageIDResolver extends HttpServlet {
}
}
/**
* Send error quietly.
*
@ -185,7 +185,7 @@ public class StorageIDResolver extends HttpServlet {
* @param code the code
*/
protected void sendErrorQuietly(HttpServletResponse response, int code){
if(response!=null){
try {
response.sendError(code);
@ -195,7 +195,7 @@ public class StorageIDResolver extends HttpServlet {
}
}
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@ -203,6 +203,6 @@ public class StorageIDResolver extends HttpServlet {
HttpServletResponse response) throws IOException {
doGet(request,response);
}
}