This commit is contained in:
Lucio Lelii 2018-07-05 14:24:49 +00:00
parent a181528978
commit d71c507924
2 changed files with 47 additions and 64 deletions

View File

@ -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;
@ -43,33 +42,17 @@ public class Items {
@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();
}*/
}
}
@ -110,17 +93,17 @@ public class Items {
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;
}
}
@ -156,7 +139,7 @@ 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());
@ -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;
}
*/
*/
}
}

View File

@ -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();
}