DefaultManager update
This commit is contained in:
parent
433e075326
commit
ceb01cf16f
5
pom.xml
5
pom.xml
|
@ -35,10 +35,7 @@
|
|||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>gxJRS</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
|
|
@ -34,8 +34,11 @@ import org.gcube.common.storagehub.model.service.ItemWrapper;
|
|||
import org.gcube.common.storagehub.model.service.Version;
|
||||
import org.gcube.common.storagehub.model.service.VersionList;
|
||||
import org.gcube.common.storagehub.model.types.ACLList;
|
||||
import org.glassfish.jersey.client.ClientProperties;
|
||||
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
|
||||
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||
import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart;
|
||||
|
||||
public class DefaultItemManager implements ItemManagerClient {
|
||||
|
||||
|
@ -619,7 +622,6 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public String uploadFile(InputStream stream, String parentId, String fileName, String description) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||
|
@ -638,7 +640,11 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
|
||||
multipart.field("name", fileName);
|
||||
multipart.field("description", description);
|
||||
multipart.field("file", stream, MediaType.APPLICATION_OCTET_STREAM_TYPE);
|
||||
|
||||
|
||||
StreamDataBodyPart fdp = new StreamDataBodyPart("file", stream);
|
||||
multipart.bodyPart(fdp);
|
||||
|
||||
|
||||
Entity<FormDataMultiPart> entity = Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA);
|
||||
|
||||
|
@ -662,7 +668,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
@Override
|
||||
public String uploadFile(InputStream stream, String parentId, String fileName, String description) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||
|
@ -705,7 +711,7 @@ public class DefaultItemManager implements ItemManagerClient {
|
|||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public String uploadFile(URI uri, String parentId, String fileName, String description) throws StorageHubException {
|
||||
|
|
|
@ -44,7 +44,7 @@ public class Items {
|
|||
|
||||
private static final String propFile = "C:\\Users\\tilli\\Documents\\eclipse\\tokens.properties";
|
||||
|
||||
private static final String tokens = "prod-root";
|
||||
private static final String tokens = "dev-root";
|
||||
//private static final String tokens = "prod-root";
|
||||
|
||||
@BeforeClass
|
||||
|
@ -167,16 +167,19 @@ public class Items {
|
|||
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
|
||||
|
||||
FolderContainer myRoot = shc.getWSRoot();
|
||||
|
||||
|
||||
try(InputStream is = new FileInputStream(new File("C:\\\\Users\\\\tilli\\\\Downloads\\\\Blue-Cloud_order_2021_10_15_1.zip"))){
|
||||
myRoot.uploadFile(is, "testUpload.zip", "file");
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
File inFile = new File("C:\\Users\\tilli\\Downloads\\testup.zip");
|
||||
try(InputStream is = new FileInputStream(inFile)){
|
||||
myRoot.uploadFile(is, "testUp.zip", "file");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("Response in "+(System.currentTimeMillis()-start));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,10 @@ import java.io.BufferedInputStream;
|
|||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
@ -16,11 +17,14 @@ import java.util.Properties;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.client.Client;
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.client.WebTarget;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.StreamingOutput;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
|
@ -42,13 +46,9 @@ import org.gcube.common.storagehub.model.expressions.logical.ISDescendant;
|
|||
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
||||
import org.gcube.common.storagehub.model.items.GCubeItem;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.gcube.common.storagehub.model.messages.Message;
|
||||
import org.gcube.common.storagehub.model.query.Queries;
|
||||
import org.gcube.common.storagehub.model.query.Query;
|
||||
import org.glassfish.jersey.client.ClientProperties;
|
||||
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||
import org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -183,6 +183,34 @@ public class TestCall {
|
|||
client.createGcubeItem(ws.getId(), item);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void uploadDirectJersey() throws Exception {
|
||||
long start = System.currentTimeMillis();
|
||||
Client client = ClientBuilder.newClient();
|
||||
client.property(ClientProperties.REQUEST_ENTITY_PROCESSING, "CHUNKED").property(ClientProperties.CHUNKED_ENCODING_SIZE, 1024).property(ClientProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, -1);
|
||||
WebTarget target = client.target("https://workspace-repository.dev.d4science.org/storagehub/workspace/items/cc7513e7-fd93-4bfb-8e1b-bc9b32938c77/create/"
|
||||
+ "FILE?gcube-token=b7c80297-e4ed-42ab-ab42-fdc0b8b0eabf-98187548");
|
||||
|
||||
target = target.queryParam("name", "test2Gb.zip").queryParam("description", "description");
|
||||
|
||||
|
||||
File inFile = new File("C:\\Users\\tilli\\Downloads\\testup.zip");
|
||||
InputStream fileInStream = new FileInputStream(inFile);
|
||||
|
||||
|
||||
//String contentDisposition = "attachment; filename=\"" + inFile.getName() + "\"";
|
||||
System.out.println("sending: " + inFile.length() + " bytes...");
|
||||
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
|
||||
Response response = target
|
||||
.request(MediaType.APPLICATION_OCTET_STREAM_TYPE)
|
||||
//.header("Content-Disposition", contentDisposition)
|
||||
//.header("Content-Length", inFile.length())
|
||||
.post(Entity.entity(fileInStream, MediaType.APPLICATION_OCTET_STREAM_TYPE));
|
||||
System.out.println("Response status: " + response.getStatus()+ " in "+(System.currentTimeMillis()-start));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void upload() throws Exception{
|
||||
final ItemManagerClient client = AbstractPlugin.item().build();
|
||||
|
|
Loading…
Reference in New Issue