git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/Common/storagehub-client@169678 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
a181528978
commit
d71c507924
|
@ -15,7 +15,6 @@ import javax.ws.rs.client.WebTarget;
|
|||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.calls.jaxrs.JaxRSRequestFilter;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||
import org.gcube.common.storagehub.client.dsl.ContainerType;
|
||||
|
@ -39,49 +38,33 @@ public class Items {
|
|||
SecurityTokenProvider.instance.set("b7c80297-e4ed-42ab-ab42-fdc0b8b0eabf-98187548");
|
||||
ScopeProvider.instance.set("/gcube");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void uploadFile() throws Exception {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
/*
|
||||
Client client = ClientBuilder.newClient().property(ClientProperties.FOLLOW_REDIRECTS, Boolean.FALSE).property(ClientProperties.CHUNKED_ENCODING_SIZE, 1024*1024);
|
||||
|
||||
WebTarget webTarget = client.target("http://workspace-repository1-d.d4science.org/storagehub/workspace/items/bc1c9525-43f7-4565-b5ea-0a0f9d7853a0/create/FILE?gcube-token=595ca591-9921-423c-bfca-f8be19f05882-98187548");
|
||||
|
||||
Invocation.Builder builder = webTarget.register(MultiPartFeature.class).request();
|
||||
|
||||
try (FormDataMultiPart multipart = new FormDataMultiPart();InputStream is = new FileInputStream(new File("/home/lucio/Downloads/1GB.zip"))){
|
||||
|
||||
multipart.field("name", "5Giga");
|
||||
multipart.field("description", "");
|
||||
|
||||
StreamDataBodyPart fileDataBodyPart = new StreamDataBodyPart("file",is);
|
||||
multipart.bodyPart(fileDataBodyPart);
|
||||
|
||||
String response = builder.post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE),String.class);
|
||||
System.out.println(response);
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
String afi = null;
|
||||
InputStream is = new FileInputStream(new File("/home/lucio/Downloads/test5Gb.zip"));
|
||||
shc.getWSRoot().uploadFile(is, "5g.zip", "descr");
|
||||
|
||||
System.out.println(afi);
|
||||
/*} catch (Exception e) {
|
||||
|
||||
try(InputStream is = new FileInputStream(new File("/home/lucio/Downloads/test5Gb.zip"))){
|
||||
shc.getWSRoot().uploadFile(is, "5g.zip", "descr");
|
||||
|
||||
System.out.println(afi);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void getPublicLink() {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
System.out.println(shc.open("c2573eec-3942-47ec-94a7-04869e97bb69").asFile().getPublicLink());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void findByName() throws Exception{
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
|
@ -90,49 +73,49 @@ public class Items {
|
|||
System.out.println("name is :"+container.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void delete() throws Exception{
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
shc.open("8dc6fca2-f0f5-4813-b854-f12e414e3a28").asFile().delete();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void downloadFile() {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
|
||||
|
||||
List<ItemContainer<? extends Item>> containers = shc.getWSRoot().list().getContainers();
|
||||
|
||||
|
||||
for (ItemContainer<? extends Item> container : containers) {
|
||||
if (container.getType()==ContainerType.FILE) {
|
||||
FileContainer file = (FileContainer) container;
|
||||
StreamDescriptor descr = file.download();
|
||||
File targetFile = new File("/tmp/"+descr.getFileName());
|
||||
|
||||
try {
|
||||
|
||||
try {
|
||||
java.nio.file.Files.copy(
|
||||
descr.getStream(),
|
||||
targetFile.toPath(),
|
||||
StandardCopyOption.REPLACE_EXISTING);
|
||||
targetFile.toPath(),
|
||||
StandardCopyOption.REPLACE_EXISTING);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("file created "+targetFile.getAbsolutePath());
|
||||
break;
|
||||
System.out.println("file created "+targetFile.getAbsolutePath());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
|
||||
static String baseUrl="http://workspace-repository1-d.d4science.org/storagehub";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static List<? extends Item> list(OrderBy order, Path path, ItemFilter<?> ... filters){
|
||||
Client client = ClientBuilder.newClient();
|
||||
WebTarget webTarget = client.target(baseUrl+"/list/byPath?gcube-token=595ca591-9921-423c-bfca-f8be19f05882-98187548");
|
||||
|
@ -156,30 +139,30 @@ public class Items {
|
|||
/* .field("characterProfile", jsonToSend, MediaType.APPLICATION_JSON_TYPE)
|
||||
.field("filename", fileToUpload.getName(), MediaType.TEXT_PLAIN_TYPE)
|
||||
.bodyPart(fileDataBodyPart)*/;
|
||||
/*
|
||||
/*
|
||||
Response res = webTarget.request().post(Entity.entity(multiPart, multiPart.getMediaType()));
|
||||
System.out.println("status is "+res.getStatus());
|
||||
|
||||
}
|
||||
|
||||
public static void create() throws Exception{
|
||||
|
||||
|
||||
|
||||
|
||||
ClientConfig clientConfig = new ClientConfig();
|
||||
clientConfig.property("DEFAULT_CHUNK_SIZE", 2048);
|
||||
|
||||
|
||||
Clie
|
||||
|
||||
|
||||
//Client client = ClientBuilder.newClient();
|
||||
Client client = ClientBuilder.newClient(clientConfig)
|
||||
.register(MultiPartFeature.class);
|
||||
|
||||
|
||||
WebTarget webTarget = client.target(baseUrl+"/item/create?gcube-token=595ca591-9921-423c-bfca-f8be19f05882-98187548");
|
||||
|
||||
GenericFileItem folder= new GenericFileItem();
|
||||
folder.setName("testUpload.tar.gz");
|
||||
folder.setTitle("testUpload.tar.gz");
|
||||
|
||||
|
||||
FileDataBodyPart fileDataBodyPart = new FileDataBodyPart("file", new File("/home/lucio/Downloads/testUpload.tar.gz"));
|
||||
final MultiPart multiPart = new FormDataMultiPart().field("item", new ItemWrapper<GenericFileItem>(folder), MediaType.APPLICATION_JSON_TYPE)
|
||||
.bodyPart(fileDataBodyPart, MediaType.APPLICATION_OCTET_STREAM_TYPE);
|
||||
|
@ -200,9 +183,9 @@ public class Items {
|
|||
byte[] buf = new byte[1024];
|
||||
/*while (is.read(buf)!=-1)
|
||||
System.out.println("reading the buffer");
|
||||
*/
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
}
|
||||
|
||||
|
||||
|
@ -217,6 +200,6 @@ public class Items {
|
|||
public static <T extends Item> T unshareAll(T item){
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,8 +104,9 @@ public class TestCall {
|
|||
//final ItemManagerClient client = AbstractPlugin.item().at(new URI("http://workspace-repository1-d.d4science.org:8080/storagehub")).build();
|
||||
|
||||
Client client = ClientBuilder.newClient();
|
||||
client.register(MultiPartFeature.class).property(ClientProperties.CHUNKED_ENCODING_SIZE, 0);
|
||||
WebTarget target = client.target("http://workspace-repository1-d.d4science.org/storagehub/workspace/items/bc1c9525-43f7-4565-b5ea-0a0f9d7853a0/create/FILE?gcube-token=595ca591-9921-423c-bfca-f8be19f05882-98187548");
|
||||
client.register(MultiPartFeature.class).property(ClientProperties.CHUNKED_ENCODING_SIZE, 1024).property(ClientProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, -1)
|
||||
.property(ClientProperties.REQUEST_ENTITY_PROCESSING, "CHUNKED");
|
||||
WebTarget target = client.target("http://workspace-repository1-d.d4science.org:8080/storagehub/workspace/items/bc1c9525-43f7-4565-b5ea-0a0f9d7853a0/create/FILE?gcube-token=595ca591-9921-423c-bfca-f8be19f05882-98187548");
|
||||
|
||||
FormDataMultiPart multipart = new FormDataMultiPart();
|
||||
|
||||
|
@ -117,7 +118,6 @@ public class TestCall {
|
|||
|
||||
//client.uploadFile(new FileInputStream("/home/lucio/Downloads/test5Gb.zip"), "bc1c9525-43f7-4565-b5ea-0a0f9d7853a0", "5gb.zip", "description");
|
||||
|
||||
System.in.read();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue