git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/Common/storagehub-client@179272 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3c459a8ffc
commit
1871710e38
4
.project
4
.project
|
@ -16,12 +16,12 @@
|
||||||
</arguments>
|
</arguments>
|
||||||
</buildCommand>
|
</buildCommand>
|
||||||
<buildCommand>
|
<buildCommand>
|
||||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||||
<arguments>
|
<arguments>
|
||||||
</arguments>
|
</arguments>
|
||||||
</buildCommand>
|
</buildCommand>
|
||||||
<buildCommand>
|
<buildCommand>
|
||||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||||
<arguments>
|
<arguments>
|
||||||
</arguments>
|
</arguments>
|
||||||
</buildCommand>
|
</buildCommand>
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
package org.gcube.common.storagehub.client;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.MultivaluedMap;
|
||||||
|
|
||||||
|
import org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider;
|
||||||
|
import org.glassfish.jersey.message.internal.ReaderInterceptorExecutor;
|
||||||
|
|
||||||
|
@Produces({"application/octet-stream", "*/*"})
|
||||||
|
@Consumes({"application/octet-stream", "*/*"})
|
||||||
|
@Singleton
|
||||||
|
public final class MyInputStreamProvider extends AbstractMessageReaderWriterProvider<InputStream> {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
|
||||||
|
return InputStream.class == type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream readFrom(
|
||||||
|
Class<InputStream> type,
|
||||||
|
Type genericType,
|
||||||
|
Annotation annotations[],
|
||||||
|
MediaType mediaType,
|
||||||
|
MultivaluedMap<String, String> httpHeaders,
|
||||||
|
InputStream entityStream) throws IOException {
|
||||||
|
return ReaderInterceptorExecutor.closeableInputStream(entityStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWriteable(Class<?> type, Type genericType, Annotation annotations[], MediaType mediaType) {
|
||||||
|
return InputStream.class.isAssignableFrom(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getSize(InputStream t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
|
||||||
|
if (t instanceof ByteArrayInputStream) {
|
||||||
|
return ((ByteArrayInputStream) t).available();
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(
|
||||||
|
InputStream t,
|
||||||
|
Class<?> type,
|
||||||
|
Type genericType,
|
||||||
|
Annotation annotations[],
|
||||||
|
MediaType mediaType,
|
||||||
|
MultivaluedMap<String, Object> httpHeaders,
|
||||||
|
OutputStream entityStream) throws IOException {
|
||||||
|
try {
|
||||||
|
writeTo(t, entityStream);
|
||||||
|
}catch (IOException e) {
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
t.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||||
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
||||||
import org.gcube.common.gxrest.response.entity.SerializableErrorEntityTextReader;
|
import org.gcube.common.gxrest.response.entity.SerializableErrorEntityTextReader;
|
||||||
import org.gcube.common.storagehub.client.Constants;
|
import org.gcube.common.storagehub.client.Constants;
|
||||||
|
import org.gcube.common.storagehub.client.MyInputStreamProvider;
|
||||||
import org.gcube.common.storagehub.client.proxies.DefaultItemManager;
|
import org.gcube.common.storagehub.client.proxies.DefaultItemManager;
|
||||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
@ -42,6 +43,7 @@ public class ItemManagerPlugin extends AbstractPlugin<GXWebTargetAdapterRequest,
|
||||||
GcubeService service = GcubeService.service().withName(Constants.MANAGER_QNAME).andPath("items");
|
GcubeService service = GcubeService.service().withName(Constants.MANAGER_QNAME).andPath("items");
|
||||||
GXWebTargetAdapterRequest requestAdapter = TargetFactory.stubFor(service).getAsGxRest(address);
|
GXWebTargetAdapterRequest requestAdapter = TargetFactory.stubFor(service).getAsGxRest(address);
|
||||||
requestAdapter.register(SerializableErrorEntityTextReader.class);
|
requestAdapter.register(SerializableErrorEntityTextReader.class);
|
||||||
|
requestAdapter.register(MyInputStreamProvider.class);
|
||||||
return requestAdapter;
|
return requestAdapter;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package org.gcube.common.storagehub.client.proxies;
|
package org.gcube.common.storagehub.client.proxies;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.StreamCorruptedException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -8,6 +10,7 @@ import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.ws.rs.ProcessingException;
|
||||||
import javax.ws.rs.client.Entity;
|
import javax.ws.rs.client.Entity;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.MultivaluedHashMap;
|
import javax.ws.rs.core.MultivaluedHashMap;
|
||||||
|
@ -548,18 +551,22 @@ public class DefaultItemManager implements ItemManagerClient {
|
||||||
GXWebTargetAdapterRequest myManager = manager.register(MultiPartFeature.class).path(parentId)
|
GXWebTargetAdapterRequest myManager = manager.register(MultiPartFeature.class).path(parentId)
|
||||||
.path("create").path("FILE");
|
.path("create").path("FILE");
|
||||||
|
|
||||||
|
GXInboundResponse response =null;
|
||||||
FormDataMultiPart multipart = new FormDataMultiPart();
|
FormDataMultiPart multipart = new FormDataMultiPart();
|
||||||
|
|
||||||
multipart.field("name", fileName);
|
multipart.field("name", fileName);
|
||||||
multipart.field("description", description);
|
multipart.field("description", description);
|
||||||
multipart.field("file", stream, MediaType.APPLICATION_OCTET_STREAM_TYPE);
|
multipart.field("file", stream, MediaType.APPLICATION_OCTET_STREAM_TYPE);
|
||||||
|
|
||||||
GXInboundResponse response = myManager.post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA));
|
Entity<FormDataMultiPart> entity = Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA);
|
||||||
|
|
||||||
|
response = myManager.post(entity);
|
||||||
|
|
||||||
if (response.isErrorResponse()) {
|
if (response.isErrorResponse()) {
|
||||||
if (response.hasException())
|
if (response.hasException()) {
|
||||||
|
System.out.println(response.getException().getStackTrace());
|
||||||
throw response.getException();
|
throw response.getException();
|
||||||
else
|
}else
|
||||||
throw new BackendGenericError();
|
throw new BackendGenericError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue