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:
parent
a4b5a67c5d
commit
8f808293fd
11
pom.xml
11
pom.xml
|
@ -42,7 +42,6 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>common-smartgears</artifactId>
|
<artifactId>common-smartgears</artifactId>
|
||||||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -114,11 +113,11 @@
|
||||||
<!-- <artifactId>jersey-mvc-jsp</artifactId> -->
|
<!-- <artifactId>jersey-mvc-jsp</artifactId> -->
|
||||||
<!-- <version>2.13</version> -->
|
<!-- <version>2.13</version> -->
|
||||||
<!-- </dependency> -->
|
<!-- </dependency> -->
|
||||||
<dependency>
|
<!-- <dependency> -->
|
||||||
<groupId>javax.ws.rs</groupId>
|
<!-- <groupId>javax.ws.rs</groupId> -->
|
||||||
<artifactId>javax.ws.rs-api</artifactId>
|
<!-- <artifactId>javax.ws.rs-api</artifactId> -->
|
||||||
<version>2.0</version>
|
<!-- <version>2.0</version> -->
|
||||||
</dependency>
|
<!-- </dependency> -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.glassfish.jersey.containers</groupId>
|
<groupId>org.glassfish.jersey.containers</groupId>
|
||||||
<artifactId>jersey-container-servlet</artifactId>
|
<artifactId>jersey-container-servlet</artifactId>
|
||||||
|
|
|
@ -152,20 +152,24 @@ public class AnalyticsCreateResolver {
|
||||||
tempInvocationFile = createTempFile(uniqueName, ".xml", xmlByteArray.toByteArray());
|
tempInvocationFile = createTempFile(uniqueName, ".xml", xmlByteArray.toByteArray());
|
||||||
logger.info("Created StorageHubClient Instance, uploading file: "+tempInvocationFile.getName());
|
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 infra = ScopeUtil.getInfrastructureNameFromScope(ScopeProvider.instance.get());
|
||||||
String theAppToken = readApplicationTokenFromSE(req, infra);
|
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 applicationMode = new ApplicationMode(theAppToken);
|
||||||
applicationMode.start();
|
applicationMode.start();
|
||||||
|
|
||||||
StorageHubManagement storageHubManagement = new StorageHubManagement();
|
StorageHubManagement storageHubManagement = new StorageHubManagement();
|
||||||
Metadata metadata = new Metadata();
|
Metadata metadata = new Metadata();
|
||||||
Map<String, String> theMap = new HashMap<String, String>();
|
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);
|
theMap.put("owner", owner);
|
||||||
|
|
||||||
logger.info("Saving dataminer-invocation file for the user: "+owner);
|
logger.info("Saving dataminer-invocation file for the user: "+owner);
|
||||||
URL thePublicLink = storageHubManagement.persistFile(new FileInputStream(tempInvocationFile), tempInvocationFile.getName(), "application/xml", metadata);
|
URL thePublicLink = storageHubManagement.persistFile(new FileInputStream(tempInvocationFile), tempInvocationFile.getName(), "application/xml", metadata);
|
||||||
logger.info("Saved dataminer-invocation file at: "+thePublicLink);
|
logger.info("Saved dataminer-invocation file at: "+thePublicLink);
|
||||||
|
@ -179,13 +183,14 @@ public class AnalyticsCreateResolver {
|
||||||
logger.error("Error on creating 'dataminer-invocation:", e);
|
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);
|
throw ExceptionManager.badRequestException(req, "Error on creating your 'dataminer-invocation' request with "+jsonRequest+". \nPlease contact the support", this.getClass(), helpURI);
|
||||||
}finally{
|
}finally{
|
||||||
try{
|
//No needed to reset the scope, it is provided by TokenSetter
|
||||||
//DELETING THE TEMP FILE
|
// try{
|
||||||
if(tempInvocationFile!=null && tempInvocationFile.exists())
|
// //DELETING THE TEMP FILE
|
||||||
tempInvocationFile.delete();
|
// if(tempInvocationFile!=null && tempInvocationFile.exists())
|
||||||
}catch(Exception e){
|
// tempInvocationFile.delete();
|
||||||
//silent
|
// }catch(Exception e){
|
||||||
}
|
// //silent
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
if(publicLinkToDMInvFile==null){
|
if(publicLinkToDMInvFile==null){
|
||||||
|
|
|
@ -10,6 +10,7 @@ import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.WebApplicationException;
|
import javax.ws.rs.WebApplicationException;
|
||||||
import javax.ws.rs.core.Context;
|
import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.Response;
|
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.StreamDescriptor;
|
||||||
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
||||||
|
@ -66,9 +67,14 @@ public class StorageHubResolver {
|
||||||
|
|
||||||
try{
|
try{
|
||||||
StreamDescriptor descriptor = client.resolvePublicLink(id);
|
StreamDescriptor descriptor = client.resolvePublicLink(id);
|
||||||
return Response
|
ResponseBuilder response = Response
|
||||||
.ok(descriptor.getStream())
|
.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){
|
}catch(Exception e){
|
||||||
logger.error("Error on getting file with "+id, e);
|
logger.error("Error on getting file with "+id, e);
|
||||||
|
@ -119,9 +125,14 @@ 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);
|
||||||
return Response
|
ResponseBuilder response = Response
|
||||||
.ok(descriptor.getStream())
|
.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){
|
}catch(Exception e){
|
||||||
String errorMsg = "Error on getting versioned file with hub id '"+id+ "' and version '"+version+"'";
|
String errorMsg = "Error on getting versioned file with hub id '"+id+ "' and version '"+version+"'";
|
||||||
|
|
Loading…
Reference in New Issue