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