diff --git a/pom.xml b/pom.xml index e9f814b..0b26827 100644 --- a/pom.xml +++ b/pom.xml @@ -71,12 +71,7 @@ jersey-media-multipart 2.13 - - javax.ws.rs - javax.ws.rs-api - 2.0 - - + org.gcube.core common-gcube-calls diff --git a/src/main/java/org/gcube/common/storagehub/client/StreamDescriptor.java b/src/main/java/org/gcube/common/storagehub/client/StreamDescriptor.java index 46ffbd8..fa103c4 100644 --- a/src/main/java/org/gcube/common/storagehub/client/StreamDescriptor.java +++ b/src/main/java/org/gcube/common/storagehub/client/StreamDescriptor.java @@ -6,11 +6,13 @@ public class StreamDescriptor { private InputStream stream; private String fileName; + private String contentType; - public StreamDescriptor(InputStream stream, String fileName) { + public StreamDescriptor(InputStream stream, String fileName, String contentType) { super(); this.stream = stream; this.fileName = fileName; + this.contentType= contentType; } public InputStream getStream() { @@ -20,5 +22,9 @@ public class StreamDescriptor { public String getFileName() { return fileName; } + + public String getContentType() { + return contentType; + } } diff --git a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultItemManager.java b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultItemManager.java index ca4f6fc..107bbd7 100644 --- a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultItemManager.java +++ b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultItemManager.java @@ -36,7 +36,9 @@ import org.glassfish.jersey.media.multipart.MultiPartFeature; public class DefaultItemManager implements ItemManagerClient { private final ProxyDelegate delegate; - + + private static final String CONTENT_DISPOSITION= "Content-Disposition"; + private static final String CONTENT_TYPE= "Content-Type"; public DefaultItemManager(ProxyDelegate config){ this.delegate = config; @@ -62,11 +64,9 @@ public class DefaultItemManager implements ItemManagerClient { Response resp = response.getSource(); - InputStream stream = resp.readEntity(InputStream.class); - String disposition = resp.getHeaderString("Content-Disposition"); - String fileName = disposition.replaceFirst("attachment; filename = ([^/s]+)?", "$1"); - return new StreamDescriptor(stream, fileName); + return createStreamDescriptor(resp); } + }; try { StreamDescriptor result = delegate.make(call); @@ -230,10 +230,7 @@ public class DefaultItemManager implements ItemManagerClient { Response resp = response.getSource(); - InputStream stream = resp.readEntity(InputStream.class); - String disposition = resp.getHeaderString("Content-Disposition"); - String fileName = disposition.replaceFirst("attachment; filename = ([^/s]+)?", "$1"); - return new StreamDescriptor(stream, fileName); + return createStreamDescriptor(resp); } }; try { @@ -262,10 +259,7 @@ public class DefaultItemManager implements ItemManagerClient { Response resp = response.getSource(); - InputStream stream = resp.readEntity(InputStream.class); - String disposition = resp.getHeaderString("Content-Disposition"); - String fileName = disposition.replaceFirst("attachment; filename = ([^/s]+)?", "$1"); - return new StreamDescriptor(stream, fileName); + return createStreamDescriptor(resp); } }; try { @@ -829,4 +823,12 @@ public class DefaultItemManager implements ItemManagerClient { } } + + private StreamDescriptor createStreamDescriptor(Response resp) { + InputStream stream = resp.readEntity(InputStream.class); + String disposition = resp.getHeaderString(CONTENT_DISPOSITION); + String fileName = disposition.replaceFirst("attachment; filename = ([^/s]+)?", "$1"); + String contentType = resp.getHeaderString(CONTENT_TYPE); + return new StreamDescriptor(stream, fileName, contentType); + } } diff --git a/src/test/java/org/gcube/data/access/fs/Items.java b/src/test/java/org/gcube/data/access/fs/Items.java index 71fc67f..8930f09 100644 --- a/src/test/java/org/gcube/data/access/fs/Items.java +++ b/src/test/java/org/gcube/data/access/fs/Items.java @@ -29,10 +29,10 @@ public class Items { @BeforeClass public static void setUp(){ - SecurityTokenProvider.instance.set("18fed2d9-030b-4c77-93af-af2015d945f7-843339462"); + SecurityTokenProvider.instance.set("b7c80297-e4ed-42ab-ab42-fdc0b8b0eabf-98187548"); //SecurityTokenProvider.instance.set("a5b623b6-6577-4271-aba6-7ada687d29cf-98187548"); - ScopeProvider.instance.set("/d4science.research-infrastructures.eu"); + ScopeProvider.instance.set("/gcube"); } diff --git a/src/test/java/org/gcube/data/access/fs/TestCall.java b/src/test/java/org/gcube/data/access/fs/TestCall.java index 64f429e..967cd61 100644 --- a/src/test/java/org/gcube/data/access/fs/TestCall.java +++ b/src/test/java/org/gcube/data/access/fs/TestCall.java @@ -51,8 +51,8 @@ public class TestCall { //SecurityTokenProvider.instance.set("0e2c7963-8d3e-4ea6-a56d-ffda530dd0fa-98187548"); //token costantino 9ca79556-54b0-4bbf-ab0f-151ae326f4cf-98187548 - SecurityTokenProvider.instance.set("04269c7d-dab7-498a-841d-8d38ae2d482b-98187548"); - ScopeProvider.instance.set("/gcube/preprod"); + SecurityTokenProvider.instance.set("e03bfbc4-a144-48e3-aa37-b07bafdf8822-98187548"); + ScopeProvider.instance.set("/gcube/devsec"); } @Test @@ -64,7 +64,7 @@ public class TestCall { }catch (Exception e) { e.printStackTrace(); } - /*System.out.println("ws id is "+ws.getId()); + /* List items = itemclient.getChildren(ws.getId(),10, 5, "hl:accounting", "jcr:content"); List Vreitems = client.getVreFolders("hl:accounting"); List VreitemsPaged = client.getVreFolders(5,5, "hl:accounting");