removed authz path /shub/metadata
added same fill metadata to the shub' resolvers git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@176240 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
75d57b3c77
commit
627f3b0efd
|
@ -5,6 +5,7 @@ import static org.gcube.common.storagehub.model.Constants.versionPrefix;
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
|
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.WebApplicationException;
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
@ -16,6 +17,7 @@ import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||||
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
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.services.error.ExceptionManager;
|
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||||
|
import org.gcube.datatransfer.resolver.util.StorageHubMetadataResponseBuilder;
|
||||||
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;
|
||||||
|
@ -43,6 +45,55 @@ public class StorageHubResolver {
|
||||||
String id;
|
String id;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the metadata.
|
||||||
|
*
|
||||||
|
* @param req the req
|
||||||
|
* @return the metadata
|
||||||
|
*/
|
||||||
|
@HEAD
|
||||||
|
@Path("")
|
||||||
|
public Response getMetadata(@Context HttpServletRequest req) {
|
||||||
|
logger.info(this.getClass().getSimpleName()+" HEAD getMetadata called");
|
||||||
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
//TODO Do we need to check the token?
|
||||||
|
|
||||||
|
//Checking mandatory parameter id
|
||||||
|
if(id==null || id.isEmpty()){
|
||||||
|
logger.error("Path Parameter "+STORAGE_HUB_ID+" not found");
|
||||||
|
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter "+STORAGE_HUB_ID, this.getClass(), help);
|
||||||
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
ItemManagerClient client = AbstractPlugin.item().build();
|
||||||
|
StreamDescriptor descriptor = client.resolvePublicLink(id);
|
||||||
|
ResponseBuilder response = Response.noContent();
|
||||||
|
response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id);
|
||||||
|
return response.build();
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Error on getting metadata for file with "+id, e);
|
||||||
|
String errorMsg = "Error on getting metadata for file with hub id '"+id+"'. "+e.getMessage();
|
||||||
|
throw ExceptionManager.internalErrorException(req, errorMsg, this.getClass(), help);
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch (Exception e) {
|
||||||
|
|
||||||
|
if(!(e instanceof WebApplicationException)){
|
||||||
|
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||||
|
String error = "Error occurred on resolving the StorageHub URL with id: "+id+". Please, contact the support!";
|
||||||
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), help);
|
||||||
|
}
|
||||||
|
//ALREADY MANAGED as WebApplicationException
|
||||||
|
logger.error("Exception:", e);
|
||||||
|
throw (WebApplicationException) e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download.
|
* Download.
|
||||||
*
|
*
|
||||||
|
@ -57,7 +108,7 @@ public class StorageHubResolver {
|
||||||
try{
|
try{
|
||||||
InnerMethodName.instance.set("resolveStorageHubPublicLink");
|
InnerMethodName.instance.set("resolveStorageHubPublicLink");
|
||||||
|
|
||||||
ItemManagerClient client = AbstractPlugin.item().build();
|
|
||||||
|
|
||||||
//Checking mandatory parameter id
|
//Checking mandatory parameter id
|
||||||
if(id==null || id.isEmpty()){
|
if(id==null || id.isEmpty()){
|
||||||
|
@ -66,14 +117,11 @@ public class StorageHubResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
ItemManagerClient client = AbstractPlugin.item().build();
|
||||||
StreamDescriptor descriptor = client.resolvePublicLink(id);
|
StreamDescriptor descriptor = client.resolvePublicLink(id);
|
||||||
ResponseBuilder response = Response
|
ResponseBuilder response = Response.ok(descriptor.getStream());
|
||||||
.ok(descriptor.getStream())
|
|
||||||
.header("content-disposition","attachment; filename = \""+descriptor.getFileName()+"\"");
|
|
||||||
|
|
||||||
if (descriptor.getContentType() != null && !descriptor.getContentType().isEmpty())
|
|
||||||
response.header("Content-Type", descriptor.getContentType());
|
|
||||||
|
|
||||||
|
response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id);
|
||||||
return response.build();
|
return response.build();
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
@ -125,13 +173,11 @@ public class StorageHubResolver {
|
||||||
try{
|
try{
|
||||||
String identifier = String.format("%s%s%s",id, versionPrefix, version);
|
String identifier = String.format("%s%s%s",id, versionPrefix, version);
|
||||||
StreamDescriptor descriptor = client.resolvePublicLink(identifier);
|
StreamDescriptor descriptor = client.resolvePublicLink(identifier);
|
||||||
ResponseBuilder response = Response
|
ResponseBuilder response = Response.ok(descriptor.getStream());
|
||||||
.ok(descriptor.getStream())
|
|
||||||
.header("content-disposition","attachment; filename = \""+descriptor.getFileName()+"\"");
|
|
||||||
|
|
||||||
if (descriptor.getContentType() != null && !descriptor.getContentType().isEmpty())
|
|
||||||
response.header("Content-Type", descriptor.getContentType()+"; charset=utf-8");
|
|
||||||
|
|
||||||
|
response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id);
|
||||||
|
//Adding ETag to version requested
|
||||||
|
response.header("ETag", version);
|
||||||
return response.build();
|
return response.build();
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
|
|
@ -1,139 +1,88 @@
|
||||||
package org.gcube.datatransfer.resolver.services;
|
//package org.gcube.datatransfer.resolver.services;
|
||||||
|
//
|
||||||
import static org.gcube.common.storagehub.model.Constants.versionPrefix;
|
//import javax.enterprise.context.RequestScoped;
|
||||||
|
//import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.enterprise.context.RequestScoped;
|
//import javax.ws.rs.HEAD;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
//import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.GET;
|
//import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.HEAD;
|
//import javax.ws.rs.WebApplicationException;
|
||||||
import javax.ws.rs.Path;
|
//import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.PathParam;
|
//import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.WebApplicationException;
|
//import javax.ws.rs.core.Response.ResponseBuilder;
|
||||||
import javax.ws.rs.core.Context;
|
//
|
||||||
import javax.ws.rs.core.Response;
|
//import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||||
import javax.ws.rs.core.Response.ResponseBuilder;
|
//import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
||||||
|
//import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||||
import org.gcube.common.storagehub.client.StreamDescriptor;
|
//import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||||
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
//import org.gcube.datatransfer.resolver.util.StorageHubMetadataResponseBuilder;
|
||||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
//import org.slf4j.Logger;
|
||||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
//import org.slf4j.LoggerFactory;
|
||||||
import org.gcube.datatransfer.resolver.util.StorageHubMetadataResponseBuilder;
|
//
|
||||||
import org.slf4j.Logger;
|
///**
|
||||||
import org.slf4j.LoggerFactory;
|
// * The Class StorageHubResolver.
|
||||||
|
// *
|
||||||
/**
|
// * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||||
* The Class StorageHubResolver.
|
// * Dec 14, 2018
|
||||||
*
|
// */
|
||||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
//@Path("shub/metadata/{id}")
|
||||||
* Dec 14, 2018
|
//public class StorageHubResolverGetMetadata {
|
||||||
*/
|
//
|
||||||
@Path("shub/metadata/{id}")
|
// private ItemManagerClient client = AbstractPlugin.item().build();
|
||||||
public class StorageHubResolverGetMetadata {
|
//
|
||||||
|
// public static final String STORAGE_HUB_ID = "id";
|
||||||
private ItemManagerClient client = AbstractPlugin.item().build();
|
//
|
||||||
|
// private static Logger logger = LoggerFactory.getLogger(StorageHubResolverGetMetadata.class);
|
||||||
public static final String STORAGE_HUB_ID = "id";
|
//
|
||||||
|
// private String help = "https://wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-HUB_Resolver";
|
||||||
private static Logger logger = LoggerFactory.getLogger(StorageHubResolverGetMetadata.class);
|
//
|
||||||
|
// @RequestScoped
|
||||||
private String help = "https://wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-HUB_Resolver";
|
// @PathParam(STORAGE_HUB_ID)
|
||||||
|
// String id;
|
||||||
@RequestScoped
|
//
|
||||||
@PathParam(STORAGE_HUB_ID)
|
//
|
||||||
String id;
|
// /**
|
||||||
|
// * Gets the metadata.
|
||||||
|
// *
|
||||||
/**
|
// * @param req the req
|
||||||
* Gets the metadata.
|
// * @return the metadata
|
||||||
*
|
// */
|
||||||
* @param req the req
|
// @HEAD
|
||||||
* @return the metadata
|
// @Path("")
|
||||||
*/
|
// public Response getMetadata(@Context HttpServletRequest req) {
|
||||||
@HEAD
|
// logger.info(this.getClass().getSimpleName()+" HEAD getMetadata called");
|
||||||
@Path("")
|
//
|
||||||
public Response getMetadata(@Context HttpServletRequest req) {
|
// try{
|
||||||
logger.info(this.getClass().getSimpleName()+" HEAD getMetadata called");
|
//
|
||||||
|
// //Checking mandatory parameter id
|
||||||
try{
|
// if(id==null || id.isEmpty()){
|
||||||
|
// logger.error("Path Parameter "+STORAGE_HUB_ID+" not found");
|
||||||
//Checking mandatory parameter id
|
// throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter "+STORAGE_HUB_ID, StorageHubResolverGetMetadata.class, help);
|
||||||
if(id==null || id.isEmpty()){
|
// }
|
||||||
logger.error("Path Parameter "+STORAGE_HUB_ID+" not found");
|
//
|
||||||
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter "+STORAGE_HUB_ID, StorageHubResolverGetMetadata.class, help);
|
// try{
|
||||||
}
|
// StreamDescriptor descriptor = client.resolvePublicLink(id);
|
||||||
|
// ResponseBuilder response = Response
|
||||||
try{
|
// .noContent();
|
||||||
StreamDescriptor descriptor = client.resolvePublicLink(id);
|
//
|
||||||
ResponseBuilder response = Response
|
// response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id);
|
||||||
.noContent();
|
// return response.build();
|
||||||
|
//
|
||||||
response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id);
|
// }catch(Exception e){
|
||||||
return response.build();
|
// logger.error("Error on getting file with "+id, e);
|
||||||
|
// String errorMsg = "Error on getting file with hub id '"+id+"'. "+e.getMessage();
|
||||||
}catch(Exception e){
|
// throw ExceptionManager.internalErrorException(req, errorMsg, StorageHubResolverGetMetadata.class, help);
|
||||||
logger.error("Error on getting file with "+id, e);
|
// }
|
||||||
String errorMsg = "Error on getting file with hub id '"+id+"'. "+e.getMessage();
|
//
|
||||||
throw ExceptionManager.internalErrorException(req, errorMsg, StorageHubResolverGetMetadata.class, help);
|
// }catch (Exception e) {
|
||||||
}
|
//
|
||||||
|
// if(!(e instanceof WebApplicationException)){
|
||||||
}catch (Exception e) {
|
// //UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||||
|
// String error = "Error occurred on resolving the StorageHub URL with id: "+id+". Please, contact the support!";
|
||||||
if(!(e instanceof WebApplicationException)){
|
// throw ExceptionManager.internalErrorException(req, error, this.getClass(), help);
|
||||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
// }
|
||||||
String error = "Error occurred on resolving the StorageHub URL with id: "+id+". Please, contact the support!";
|
// //ALREADY MANAGED as WebApplicationException
|
||||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), help);
|
// logger.error("Exception:", e);
|
||||||
}
|
// throw (WebApplicationException) e;
|
||||||
//ALREADY MANAGED as WebApplicationException
|
// }
|
||||||
logger.error("Exception:", e);
|
// }
|
||||||
throw (WebApplicationException) e;
|
//}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("{version}")
|
|
||||||
public Response getMetadataVersion(@Context HttpServletRequest req, @PathParam("version") String version) {
|
|
||||||
|
|
||||||
logger.info(this.getClass().getSimpleName() +" HEAD getMetadataVersion called");
|
|
||||||
|
|
||||||
try{
|
|
||||||
ItemManagerClient client = AbstractPlugin.item().build();
|
|
||||||
|
|
||||||
//Checking mandatory parameter id
|
|
||||||
if(id==null || id.isEmpty()){
|
|
||||||
logger.error("Path Parameter "+STORAGE_HUB_ID+" not found");
|
|
||||||
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter "+STORAGE_HUB_ID, StorageHubResolver.class, help);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Checking mandatory parameter id
|
|
||||||
if(version==null || version.isEmpty()){
|
|
||||||
logger.error("Parameter 'version' not found");
|
|
||||||
throw ExceptionManager.badRequestException(req, "Missing mandatory parameter 'version'", StorageHubResolver.class, help);
|
|
||||||
}
|
|
||||||
try{
|
|
||||||
String identifier = String.format("%s%s%s",id, versionPrefix, version);
|
|
||||||
StreamDescriptor descriptor = client.resolvePublicLink(identifier);
|
|
||||||
ResponseBuilder response = Response
|
|
||||||
.ok(descriptor.getStream());
|
|
||||||
|
|
||||||
response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id);
|
|
||||||
return response.build();
|
|
||||||
|
|
||||||
}catch(Exception e){
|
|
||||||
String errorMsg = "Error on getting versioned file with hub id '"+id+ "' and version '"+version+"'";
|
|
||||||
logger.error(errorMsg, e);
|
|
||||||
throw ExceptionManager.internalErrorException(req, errorMsg, StorageHubResolver.class, help);
|
|
||||||
}
|
|
||||||
}catch (Exception e) {
|
|
||||||
|
|
||||||
if(!(e instanceof WebApplicationException)){
|
|
||||||
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
|
||||||
String error = "Error occurred on resolving the StorageHub URL with id: "+id+" and version: "+version+". Please, contact the support!";
|
|
||||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), help);
|
|
||||||
}
|
|
||||||
//ALREADY MANAGED as WebApplicationException
|
|
||||||
logger.error("Exception:", e);
|
|
||||||
throw (WebApplicationException) e;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,15 +3,12 @@
|
||||||
*/
|
*/
|
||||||
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.Response.ResponseBuilder;
|
import javax.ws.rs.core.Response.ResponseBuilder;
|
||||||
|
|
||||||
import org.gcube.common.storagehub.client.StreamDescriptor;
|
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||||
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
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.common.storagehub.model.service.Version;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,7 +38,7 @@ public class StorageHubMetadataResponseBuilder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fill metadata.
|
* Fill metadata.
|
||||||
*
|
* By default it adds the ETag (see at https://tools.ietf.org/html/rfc7232#section-2.3) to last version of entity
|
||||||
* @param streamDescriptor the stream descriptor
|
* @param streamDescriptor the stream descriptor
|
||||||
* @param entityId the entity id
|
* @param entityId the entity id
|
||||||
* @return the response builder
|
* @return the response builder
|
||||||
|
@ -59,11 +56,11 @@ public class StorageHubMetadataResponseBuilder {
|
||||||
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()+"; charset=utf-8");
|
||||||
|
|
||||||
//Managing "Content-Version"
|
//Managing "ETag"
|
||||||
List<Version> versions = client.getFileVersions(entityId);
|
// List<Version> versions = client.getFileVersions(entityId);
|
||||||
if(versions!=null && !versions.isEmpty()){
|
// if(versions!=null && !versions.isEmpty()){
|
||||||
responseBuilder.header("Content-Version", versions.get(versions.size()));
|
// responseBuilder.header("ETag", versions.get(versions.size()));
|
||||||
}
|
// }
|
||||||
|
|
||||||
return responseBuilder;
|
return responseBuilder;
|
||||||
|
|
||||||
|
|
|
@ -5,5 +5,5 @@
|
||||||
<description>URIResolver RESTful</description>
|
<description>URIResolver RESTful</description>
|
||||||
<include>/analytics/create/*</include>
|
<include>/analytics/create/*</include>
|
||||||
<include>/knime/create/*</include>
|
<include>/knime/create/*</include>
|
||||||
<include>/shub/metadata/*</include>
|
<!-- <include>/shub/metadata/*</include> -->
|
||||||
</application>
|
</application>
|
Loading…
Reference in New Issue