added content-type to storagehubresolver

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@175986 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-12-18 14:13:57 +00:00
parent a4b5a67c5d
commit 8f808293fd
3 changed files with 39 additions and 24 deletions

11
pom.xml
View File

@ -42,7 +42,6 @@
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-smartgears</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
@ -114,11 +113,11 @@
<!-- <artifactId>jersey-mvc-jsp</artifactId> -->
<!-- <version>2.13</version> -->
<!-- </dependency> -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>javax.ws.rs</groupId> -->
<!-- <artifactId>javax.ws.rs-api</artifactId> -->
<!-- <version>2.0</version> -->
<!-- </dependency> -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>

View File

@ -152,20 +152,24 @@ public class AnalyticsCreateResolver {
tempInvocationFile = createTempFile(uniqueName, ".xml", xmlByteArray.toByteArray());
logger.info("Created StorageHubClient Instance, uploading file: "+tempInvocationFile.getName());
AuthorizationEntry entry = authorizationService().get(contextToken);
//retrieve the info of the token owner
ClientInfo clientInfo = entry.getClientInfo();
String owner = clientInfo.getId(); //IS THIS THE USERNAME?
String infra = ScopeUtil.getInfrastructureNameFromScope(ScopeProvider.instance.get());
String theAppToken = readApplicationTokenFromSE(req, infra);
logger.info("By using infra scope: "+infra +" and the Application Token: "+theAppToken.substring(0,theAppToken.length()/2)+"... of "+ANALYTICS_RESOLVER_SERVICE_ENDPOINT_NAME+" to instance the "+StorageHubManagement.class.getSimpleName());
ScopeProvider.instance.set(infra);
ApplicationMode applicationMode = new ApplicationMode(theAppToken);
applicationMode.start();
StorageHubManagement storageHubManagement = new StorageHubManagement();
Metadata metadata = new Metadata();
Map<String, String> theMap = new HashMap<String, String>();
AuthorizationEntry entry = authorizationService().get(contextToken);
//retrieve the info of the token owner
ClientInfo clientInfo = entry.getClientInfo();
String owner = clientInfo.getId(); //IS THIS THE USERNAME?
theMap.put("owner", owner);
logger.info("Saving dataminer-invocation file for the user: "+owner);
URL thePublicLink = storageHubManagement.persistFile(new FileInputStream(tempInvocationFile), tempInvocationFile.getName(), "application/xml", metadata);
logger.info("Saved dataminer-invocation file at: "+thePublicLink);
@ -179,13 +183,14 @@ public class AnalyticsCreateResolver {
logger.error("Error on creating 'dataminer-invocation:", e);
throw ExceptionManager.badRequestException(req, "Error on creating your 'dataminer-invocation' request with "+jsonRequest+". \nPlease contact the support", this.getClass(), helpURI);
}finally{
try{
//DELETING THE TEMP FILE
if(tempInvocationFile!=null && tempInvocationFile.exists())
tempInvocationFile.delete();
}catch(Exception e){
//silent
}
//No needed to reset the scope, it is provided by TokenSetter
// try{
// //DELETING THE TEMP FILE
// if(tempInvocationFile!=null && tempInvocationFile.exists())
// tempInvocationFile.delete();
// }catch(Exception e){
// //silent
// }
}
if(publicLinkToDMInvFile==null){

View File

@ -10,6 +10,7 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import org.gcube.common.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
@ -55,9 +56,9 @@ public class StorageHubResolver {
try{
InnerMethodName.instance.set("resolveStorageHubPublicLink");
ItemManagerClient client = AbstractPlugin.item().build();
//Checking mandatory parameter id
if(id==null || id.isEmpty()){
logger.error("Path Parameter "+STORAGE_HUB_ID+" not found");
@ -66,9 +67,14 @@ public class StorageHubResolver {
try{
StreamDescriptor descriptor = client.resolvePublicLink(id);
return Response
ResponseBuilder response = Response
.ok(descriptor.getStream())
.header("content-disposition","attachment; filename = \""+descriptor.getFileName()+"\"").build();
.header("content-disposition","attachment; filename = \""+descriptor.getFileName()+"\"");
if (descriptor.getContentType() != null && !descriptor.getContentType().isEmpty())
response.header("Content-Type", descriptor.getContentType());
return response.build();
}catch(Exception e){
logger.error("Error on getting file with "+id, e);
@ -119,9 +125,14 @@ public class StorageHubResolver {
try{
String identifier = String.format("%s%s%s",id, versionPrefix, version);
StreamDescriptor descriptor = client.resolvePublicLink(identifier);
return Response
ResponseBuilder response = Response
.ok(descriptor.getStream())
.header("content-disposition","attachment; filename = \""+descriptor.getFileName()+"\"").build();
.header("content-disposition","attachment; filename = \""+descriptor.getFileName()+"\"");
if (descriptor.getContentType() != null && !descriptor.getContentType().isEmpty())
response.header("Content-Type", descriptor.getContentType());
return response.build();
}catch(Exception e){
String errorMsg = "Error on getting versioned file with hub id '"+id+ "' and version '"+version+"'";