diff --git a/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/GSRESTClient.java b/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/GSRESTClient.java index ca6ee43..76af48c 100644 --- a/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/GSRESTClient.java +++ b/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/GSRESTClient.java @@ -1,14 +1,25 @@ package org.gcube.spatial.data.clients.geoserver; -import java.io.InputStream; import java.util.List; +//import org.apache.commons.httpclient.NameValuePair; +//import org.gcube.application.geoportal.service.engine.RESTFeatureType; +//import org.gcube.application.geoportal.service.engine.RESTLayer; import org.gcube.spatial.data.sdi.model.faults.RemoteException; import org.json.simple.JSONObject; +//import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.UploadMethod; +//import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy; + public interface GSRESTClient { + // Management + public boolean exist(); + + + + // ********** READ OPS // WS @@ -20,6 +31,9 @@ public interface GSRESTClient { // DS public JSONObject getDataStoresInWorkspace(String ws)throws RemoteException,Exception; public List getDataStoresNamesInWorkspace(String ws)throws RemoteException,Exception; + public JSONObject getDataStore(String workspace,String dsName)throws RemoteException,Exception; + + // SLD public JSONObject getStyles()throws RemoteException,Exception; @@ -28,6 +42,18 @@ public interface GSRESTClient { public List getStylesNamesinWorkspace(String ws)throws RemoteException,Exception; public JSONObject getStylesByLayer(String layer)throws RemoteException,Exception; public List getStylesNamesByLayer(String layer)throws RemoteException,Exception; + public String getSLD(String styleName)throws RemoteException,Exception; + + + // FeatureTypes +// public JSONObject getFeatureType(JSONObject layer) + /** + * RESTLayer l=reader.getLayer(workspace, toSetLayerName); + RESTFeatureType f= reader.getFeatureType(l); + * @param ws + * @throws RemoteException + * @throws Exception + */ // *********** CREATE OPS public void createWorkspace(String ws)throws RemoteException,Exception; @@ -39,10 +65,53 @@ public interface GSRESTClient { // publish local files // create store for postgis db + /** + * getDataStoreManager().create(workspace, encoder) + */ + + /** + * if(!gis.getCurrentGeoServer().getPublisher().publishStyle(sldFile, name) + * + */ + + + /** + * + * gis.getCurrentGeoServer().getPublisher().publishDBLayer(workspace, storeName, fte, layerEncoder)) + */ + + + /** + * public boolean publishShp(String workspace, String storeName, NameValuePair[] storeParams, + String datasetName, UploadMethod method, URI shapefile, String srs, String defaultStyle) + throws FileNotFoundException, IllegalArgumentException { + return publishShp(workspace, storeName, storeParams, datasetName, method, shapefile, srs, + null, ProjectionPolicy.FORCE_DECLARED, defaultStyle); + } + * @param ws + * @throws RemoteException + * @throws Exception + */ + // // +********** DELETE OPS + + /** + * publisher.removeWorkspace(toDelete.getWorkspace(), true); + * @param ws + * @throws RemoteException + * @throws Exception + */ public void deleteWorkspace(String ws)throws RemoteException,Exception; public void deleteStyle(String style)throws RemoteException,Exception; + + + /** + * publisher.removeDatastore(toDelete.getWorkspace(), toDelete.getStore(), true); + * @param ds + * @throws RemoteException + * @throws Exception + */ public void deleteDataStore(String ds)throws RemoteException,Exception; public void deleteLayer(String layer)throws RemoteException,Exception; } diff --git a/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/GSRESTClientImpl.java b/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/GSRESTClientImpl.java index 5eb8d77..8f576c1 100644 --- a/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/GSRESTClientImpl.java +++ b/gcube-geoserver-client/src/main/java/org/gcube/spatial/data/clients/geoserver/GSRESTClientImpl.java @@ -125,8 +125,6 @@ public class GSRESTClientImpl extends AbstractGenericRESTClient implements GSRES } - - @Override public List getStylesNamesByLayer(String layer) throws RemoteException, Exception { DocumentContext sourceCtx=JsonPath.using(JSON_PATH_ALWAYS_LIST_CONFIG).parse(getStylesByLayer(layer).toString()); @@ -134,6 +132,18 @@ public class GSRESTClientImpl extends AbstractGenericRESTClient implements GSRES } + @Override + public JSONObject getDataStore(String workspace, String dsName) throws RemoteException, Exception { + // TODO Auto-generated method stub + return null; + } + + + @Override + public String getSLD(String styleName) throws RemoteException, Exception { + // TODO Auto-generated method stub + return null; + } //************* DELETE OPS @Override @@ -169,4 +179,18 @@ public class GSRESTClientImpl extends AbstractGenericRESTClient implements GSRES public void createWorkspace(String ws) throws RemoteException, Exception { post(WS_BASE_PATH,Entity.entity(new JSONObject().put("name", ws),MediaType.APPLICATION_JSON)); } + + + + + @Override + public boolean exist() { + // TODO Auto-generated method stub + return false; + } + + + + + } diff --git a/sdi-generic-client/pom.xml b/sdi-generic-client/pom.xml index d8cbbb8..c49208f 100644 --- a/sdi-generic-client/pom.xml +++ b/sdi-generic-client/pom.xml @@ -1,4 +1,5 @@ - 4.0.0 @@ -10,57 +11,79 @@ 0.0.1-SNAPSHOT Generic SDI Client - - + + scm:git:${gitBaseUrl}/gcube-sdi-suite scm:git:${gitBaseUrl}/gcube-sdi-suite ${gitBaseUrl}/gcube-sdi-suite - - + + sdi-interface org.gcube.spatial.data - + - - org.gcube.common - authorization-client - - - org.gcube.core - common-gcube-calls + org.gcube.common + gxJRS + org.gcube.core - common-fw-clients - - - - + common-fw-clients + + + + org.gcube.core + common-generic-clients + + + + + org.glassfish.jersey.core + jersey-client + + + + + + + + + + + + + + + + + + - - org.glassfish.jersey.core - jersey-client - - - org.glassfish.jersey.media - jersey-media-json-jackson - + + + + - - org.glassfish.jersey.media - jersey-media-multipart - + + + + - - com.jayway.jsonpath - json-path - 2.4.0 - + + + + + + + + + + @@ -68,10 +91,10 @@ sdi-test-commons org.gcube.spatial.data test - + - + Java library used to implement SDI clients. \ No newline at end of file diff --git a/sdi-generic-client/src/main/java/org/gcube/spatial/data/clients/AbstractGenericRESTClient.java b/sdi-generic-client/src/main/java/org/gcube/spatial/data/clients/AbstractGenericRESTClient.java index 5d9363e..715c9c8 100644 --- a/sdi-generic-client/src/main/java/org/gcube/spatial/data/clients/AbstractGenericRESTClient.java +++ b/sdi-generic-client/src/main/java/org/gcube/spatial/data/clients/AbstractGenericRESTClient.java @@ -1,87 +1,57 @@ package org.gcube.spatial.data.clients; -import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.HashSet; +import java.util.Set; -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 org.gcube.common.clients.Call; +import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest; +import org.gcube.common.gxrest.response.inbound.GXInboundResponse; import org.gcube.spatial.data.clients.model.ConnectionDescriptor; import org.gcube.spatial.data.sdi.model.faults.RemoteException; -import org.glassfish.jersey.client.ClientConfig; -import org.glassfish.jersey.client.ClientProperties; -import org.json.simple.JSONObject; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; - -import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; @Slf4j public abstract class AbstractGenericRESTClient { - private static ObjectMapper mapper = new ObjectMapper(); - - static { - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false); - mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS,false); - mapper.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false); - mapper.setSerializationInclusion(Include.NON_NULL); - } - - @Getter - private ClientConfig config=new ClientConfig(); private ConnectionDescriptor conn; - private Client client; @Setter private String basePath=null; - + private Set> toRegisterClasses=new HashSet>(); + private Set toRegisterObjects=new HashSet<>(); protected AbstractGenericRESTClient(ConnectionDescriptor conn) { this.conn=conn; - config.register(AuthorizationFilter.class); } protected void register(Class providerClass) { - config.register(providerClass); - client=null; + toRegisterClasses.add(providerClass); } protected void register(Object provider) { - config.register(provider); - client=null; - } - - public Client getClient() { - if(client==null) { - client = ClientBuilder.newClient(config) - .property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); - } - return client; + toRegisterObjects.add(provider); } - protected WebTarget resolve() { - WebTarget toReturn =getClient().target(conn.getEndpoint()); + + protected GXWebTargetAdapterRequest resolve() throws UnsupportedEncodingException { + GXWebTargetAdapterRequest toReturn =GXWebTargetAdapterRequest.newHTTPSRequest(conn.getEndpoint()); if(basePath!=null) return toReturn.path(basePath); + else return toReturn; } - protected T makeCall(Call call) throws Exception{ + protected T makeCall(Call call) throws Exception{ try{ return call.call(resolve()); }catch(RemoteException e) { @@ -91,57 +61,67 @@ public abstract class AbstractGenericRESTClient { } } - protected JSONObject get(String path) throws Exception { - return get(path,JSONObject.class); - } protected void delete(String path) throws Exception { - check(resolve().path(path).request(MediaType.APPLICATION_JSON).delete(),null); + check(resolve().path(path).delete(),null); } protected void post(String path,Entity entity)throws Exception{ post(path,entity,null); } + + protected void post(String path,Object obj) { + + } + protected T post(String path,Entity entity,Class returnClazz) throws Exception { - return makeCall(new Call() { + return makeCall(new Call() { - public T call(WebTarget endpoint) throws Exception { - return check(endpoint.path(path).request(MediaType.APPLICATION_JSON). - post(entity),returnClazz); + public T call(GXWebTargetAdapterRequest endpoint) throws Exception { + return check(endpoint.path(path).post(entity),returnClazz); }; }); } + protected String get(String path) throws Exception { + return get(path,null); + } protected T get(String path, Class clazz) throws Exception{ - return makeCall(new Call() { + return makeCall(new Call() { - public T call(WebTarget endpoint) throws Exception { - return check(endpoint.path(path).request(MediaType.APPLICATION_JSON).get(),clazz); + public T call(GXWebTargetAdapterRequest endpoint) throws Exception { + return check(endpoint.path(path).get(),clazz); }; }); } - protected static T check(Response resp, Class clazz) throws RemoteException{ - if(resp.getStatus()<200||resp.getStatus()>=300) { - String remoteMessage=resp.readEntity(String.class); - Integer httpCode=resp.getStatus(); - RemoteException e=new RemoteException("RESP STATUS IS "+httpCode+". Message : "+remoteMessage); - e.setRemoteMessage(remoteMessage); - e.setResponseHTTPCode(httpCode); + + + + protected static T check(GXInboundResponse resp, Class clazz) throws RemoteException{ + try { + log.debug("Checking Response {}",resp); + if(resp.hasGXError()) { + RemoteException e=new RemoteException("Error received from server"); + e.setRemoteMessage(resp.getMessage()); + e.setResponseHTTPCode(resp.getHTTPCode()); + e.setContent(resp.getStreamedContentAsString()); throw e; }else { - if(clazz==null) return null; - String respString=resp.readEntity(String.class); - if(clazz==String.class) return (T) respString; - try { - return mapper.readValue(respString, clazz); - } catch (IOException e) { - throw new RemoteException("Unable to parse response from Zenodo. Content was : \n "+respString,e); - } + if(clazz==null) return null; + + if(clazz==String.class) return (T) resp.getStreamedContentAsString(); + + return resp.tryConvertStreamedContentFromJson(clazz); + } + }catch(RemoteException e) { + throw e; + }catch(Exception e) { + throw new RemoteException("Unable to read response from server.",e); } } diff --git a/sdi-generic-client/src/main/java/org/gcube/spatial/data/clients/AuthorizationFilter.java b/sdi-generic-client/src/main/java/org/gcube/spatial/data/clients/AuthorizationFilter.java index 5a93783..ec3b495 100644 --- a/sdi-generic-client/src/main/java/org/gcube/spatial/data/clients/AuthorizationFilter.java +++ b/sdi-generic-client/src/main/java/org/gcube/spatial/data/clients/AuthorizationFilter.java @@ -1,25 +1,18 @@ package org.gcube.spatial.data.clients; -import java.io.IOException; -import java.util.Collections; -import java.util.Map.Entry; - -import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientRequestFilter; -import org.gcube.common.calls.Call; -import org.gcube.common.calls.Interceptors; -import org.gcube.common.calls.Request; +public class AuthorizationFilter { +// implements ClientRequestFilter { -public class AuthorizationFilter implements ClientRequestFilter { - @Override - public void filter(final ClientRequestContext rc) throws IOException { - Request requestContext = Interceptors.executeRequestChain(new Call()); - - for (Entry entry: requestContext.getHeaders()){ - rc.getHeaders().put(entry.getKey(), Collections.singletonList((Object)entry.getValue())); - } - } +// @Override +// public void filter(final ClientRequestContext rc) throws IOException { +// Request requestContext = Interceptors.executeRequestChain(new Call()); +// +// for (Entry entry: requestContext.getHeaders()){ +// rc.getHeaders().put(entry.getKey(), Collections.singletonList((Object)entry.getValue())); +// } +// } } \ No newline at end of file diff --git a/sdi-generic-client/src/test/java/org/gcube/spatial/data/clients/TestClient.java b/sdi-generic-client/src/test/java/org/gcube/spatial/data/clients/TestClient.java index 004cb4b..3b9f5b9 100644 --- a/sdi-generic-client/src/test/java/org/gcube/spatial/data/clients/TestClient.java +++ b/sdi-generic-client/src/test/java/org/gcube/spatial/data/clients/TestClient.java @@ -1,7 +1,6 @@ package org.gcube.spatial.data.clients; import org.gcube.spatial.data.clients.model.ConnectionDescriptor; -import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; public class TestClient extends AbstractGenericRESTClient{ @@ -14,10 +13,10 @@ public class TestClient extends AbstractGenericRESTClient{ - - - - public void setHttpBasicAuth(String user,String pwd) { - super.register(HttpAuthenticationFeature.universal(user, pwd)); - } +// +// +// +// public void setHttpBasicAuth(String user,String pwd) { +// super.register(HttpAuthenticationFeature.universal(user, pwd)); +// } } diff --git a/sdi-generic-client/src/test/java/org/gcube/spatial/data/clients/Tests.java b/sdi-generic-client/src/test/java/org/gcube/spatial/data/clients/Tests.java index 5db9dba..c69ab92 100644 --- a/sdi-generic-client/src/test/java/org/gcube/spatial/data/clients/Tests.java +++ b/sdi-generic-client/src/test/java/org/gcube/spatial/data/clients/Tests.java @@ -1,14 +1,28 @@ package org.gcube.spatial.data.clients; +import static org.junit.Assume.assumeTrue; + +import org.gcube.sdi.test.GCubeSDITest; import org.gcube.spatial.data.clients.model.ConnectionDescriptor; +import org.gcube.spatial.data.clients.model.engine.Engine; import org.gcube.spatial.data.sdi.model.faults.RemoteException; import org.junit.BeforeClass; import org.junit.Test; -public class Tests { +public class Tests extends GCubeSDITest{ + @Test + public void testContextAuth() throws Exception { + assumeTrue(isTestInfrastructureEnabled()); + + + + String url=scopeConfiguration().getByEngine(Engine.GS_ENGINE).get(0).getBaseEndpoint(); + new TestClient(new ConnectionDescriptor(url)).get(""); + } + // static String sdiHostname="sdi-t.pre.d4science.org"; // static String scope ="/pred4s/preprod/preVRE"; diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/ServiceConstants.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/ServiceConstants.java index d4b5b1d..ebc3759 100644 --- a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/ServiceConstants.java +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/ServiceConstants.java @@ -3,7 +3,7 @@ package org.gcube.spatial.data.sdi.model; public class ServiceConstants { public static final String APPLICATION="SDI-Service"; - public static final String INTERFACE="SDI"; + public static final String SERVICE_CLASS="SDI"; public static final String SERVICE_NAME="sdi-service"; @@ -42,6 +42,7 @@ public class ServiceConstants { } public static final class SDI{ + public static final String INTERFACE="SDI"; public static final String STATUS_PATH="status"; public static final String PROFILES_PATH="profile"; public static final String SERVICE_CLASS_PARAM="service_class"; diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/faults/RemoteException.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/faults/RemoteException.java index ae9fd31..9ea0b45 100644 --- a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/faults/RemoteException.java +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/faults/RemoteException.java @@ -1,8 +1,8 @@ package org.gcube.spatial.data.sdi.model.faults; -import lombok.ToString; +import lombok.Data; -@ToString +@Data public class RemoteException extends Exception { /** @@ -34,24 +34,12 @@ public class RemoteException extends Exception { // TODO Auto-generated constructor stub } -private String remoteMessage=null; + private String remoteMessage=null; private Integer responseHTTPCode=0; - public void setResponseHTTPCode(Integer responseHTTPCode) { - this.responseHTTPCode = responseHTTPCode; - } + private String content=null; - public Integer getResponseHTTPCode() { - return responseHTTPCode; - } - public String getRemoteMessage() { - return remoteMessage; - } - - public void setRemoteMessage(String remoteMessage) { - this.remoteMessage = remoteMessage; - } } diff --git a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/service/GeoServerDescriptor.java b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/service/GeoServerDescriptor.java index ecc32ef..632070b 100644 --- a/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/service/GeoServerDescriptor.java +++ b/sdi-interface/src/main/java/org/gcube/spatial/data/sdi/model/service/GeoServerDescriptor.java @@ -34,15 +34,15 @@ public class GeoServerDescriptor extends GeoServiceDescriptor { this.sharedWorkspace = sharedWorkspace; this.publicWorkspace = publicWorkspace; } - @NonNull + private String confidentialWorkspace; - @NonNull + private String contextVisibilityWorkspace; - @NonNull + private String sharedWorkspace; - @NonNull + private String publicWorkspace; - @NonNull + private Long hostedLayersCount; private String engineId=Engine.GS_ENGINE; diff --git a/sdi-library/src/main/java/org/gcube/spatial/data/sdi/plugins/MetadataPlugin.java b/sdi-library/src/main/java/org/gcube/spatial/data/sdi/plugins/MetadataPlugin.java index b8a40ac..97b004e 100644 --- a/sdi-library/src/main/java/org/gcube/spatial/data/sdi/plugins/MetadataPlugin.java +++ b/sdi-library/src/main/java/org/gcube/spatial/data/sdi/plugins/MetadataPlugin.java @@ -1,20 +1,17 @@ package org.gcube.spatial.data.sdi.plugins; -import javax.ws.rs.client.WebTarget; -import javax.xml.namespace.QName; import javax.xml.transform.dom.DOMResult; import javax.xml.ws.EndpointReference; -import org.gcube.common.calls.jaxrs.GcubeService; -import org.gcube.common.calls.jaxrs.TargetFactory; import org.gcube.common.clients.config.ProxyConfig; import org.gcube.common.clients.delegates.ProxyDelegate; +import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest; import org.gcube.spatial.data.sdi.interfaces.Metadata; import org.gcube.spatial.data.sdi.model.ServiceConstants; import org.gcube.spatial.data.sdi.proxies.DefaultMetadata; import org.w3c.dom.Node; -public class MetadataPlugin extends SDIAbstractPlugin{ +public class MetadataPlugin extends SDIAbstractPlugin{ public MetadataPlugin() { super("sdi-service/gcube/service"); @@ -25,21 +22,21 @@ public class MetadataPlugin extends SDIAbstractPlugin{ return arg0; } @Override - public Metadata newProxy(ProxyDelegate arg0) { + public Metadata newProxy(ProxyDelegate arg0) { return new DefaultMetadata(arg0); } @Override - public WebTarget resolve(EndpointReference epr, ProxyConfig arg1) throws Exception { + public GXWebTargetAdapterRequest resolve(EndpointReference epr, ProxyConfig arg1) throws Exception { DOMResult result = new DOMResult(); epr.writeTo(result); Node node =result.getNode(); Node child=node.getFirstChild(); String address = child.getTextContent(); - GcubeService service = GcubeService.service(). - withName(new QName(ServiceConstants.NAMESPACE,ServiceConstants.Metadata.INTERFACE)). - andPath(ServiceConstants.Metadata.INTERFACE); - return TargetFactory.stubFor(service).at(address); + GXWebTargetAdapterRequest request = + GXWebTargetAdapterRequest.newRequest(address).path(ServiceConstants.Metadata.INTERFACE); + //set additional path parts or parameters here + return request; } } diff --git a/sdi-library/src/main/java/org/gcube/spatial/data/sdi/plugins/SDIAbstractPlugin.java b/sdi-library/src/main/java/org/gcube/spatial/data/sdi/plugins/SDIAbstractPlugin.java index 029fa73..f576d3d 100644 --- a/sdi-library/src/main/java/org/gcube/spatial/data/sdi/plugins/SDIAbstractPlugin.java +++ b/sdi-library/src/main/java/org/gcube/spatial/data/sdi/plugins/SDIAbstractPlugin.java @@ -1,10 +1,9 @@ package org.gcube.spatial.data.sdi.plugins; -import javax.ws.rs.client.WebTarget; - +import org.gcube.common.clients.Plugin; import org.gcube.common.clients.ProxyBuilder; import org.gcube.common.clients.ProxyBuilderImpl; -import org.gcube.common.clients.Plugin; +import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest; import org.gcube.spatial.data.sdi.interfaces.Metadata; import org.gcube.spatial.data.sdi.interfaces.SDIManagement; import org.gcube.spatial.data.sdi.model.ServiceConstants; @@ -18,12 +17,12 @@ public abstract class SDIAbstractPlugin implements Plugin{ public static ProxyBuilder metadata() { - return new ProxyBuilderImpl(metadata_plugin); + return new ProxyBuilderImpl(metadata_plugin); } public static ProxyBuilder management() { - return new ProxyBuilderImpl(sdi_plugin); + return new ProxyBuilderImpl(sdi_plugin); } diff --git a/sdi-library/src/main/java/org/gcube/spatial/data/sdi/plugins/SDIPlugin.java b/sdi-library/src/main/java/org/gcube/spatial/data/sdi/plugins/SDIPlugin.java index 5ba2df7..8101210 100644 --- a/sdi-library/src/main/java/org/gcube/spatial/data/sdi/plugins/SDIPlugin.java +++ b/sdi-library/src/main/java/org/gcube/spatial/data/sdi/plugins/SDIPlugin.java @@ -9,12 +9,13 @@ import org.gcube.common.calls.jaxrs.GcubeService; import org.gcube.common.calls.jaxrs.TargetFactory; import org.gcube.common.clients.config.ProxyConfig; import org.gcube.common.clients.delegates.ProxyDelegate; +import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest; import org.gcube.spatial.data.sdi.interfaces.SDIManagement; import org.gcube.spatial.data.sdi.model.ServiceConstants; import org.gcube.spatial.data.sdi.proxies.DefaultSDIManagement; import org.w3c.dom.Node; -public class SDIPlugin extends SDIAbstractPlugin{ +public class SDIPlugin extends SDIAbstractPlugin{ public SDIPlugin() { super("sdi-service/gcube/service"); @@ -25,21 +26,21 @@ public class SDIPlugin extends SDIAbstractPlugin{ return arg0; } @Override - public SDIManagement newProxy(ProxyDelegate arg0) { + public SDIManagement newProxy(ProxyDelegate arg0) { return new DefaultSDIManagement(arg0); } @Override - public WebTarget resolve(EndpointReference epr, ProxyConfig arg1) throws Exception { + public GXWebTargetAdapterRequest resolve(EndpointReference epr, ProxyConfig arg1) throws Exception { DOMResult result = new DOMResult(); epr.writeTo(result); Node node =result.getNode(); Node child=node.getFirstChild(); String address = child.getTextContent(); - GcubeService service = GcubeService.service(). - withName(new QName(ServiceConstants.NAMESPACE,ServiceConstants.INTERFACE)). - andPath(ServiceConstants.INTERFACE); - return TargetFactory.stubFor(service).at(address); + GXWebTargetAdapterRequest request = + GXWebTargetAdapterRequest.newRequest(address).path(ServiceConstants.SDI.INTERFACE); + //set additional path parts or parameters here + return request; } } diff --git a/sdi-library/src/main/java/org/gcube/spatial/data/sdi/proxies/AbstractProxy.java b/sdi-library/src/main/java/org/gcube/spatial/data/sdi/proxies/AbstractProxy.java new file mode 100644 index 0000000..89444c2 --- /dev/null +++ b/sdi-library/src/main/java/org/gcube/spatial/data/sdi/proxies/AbstractProxy.java @@ -0,0 +1,126 @@ +package org.gcube.spatial.data.sdi.proxies; + +import java.io.UnsupportedEncodingException; +import java.util.HashSet; +import java.util.Set; + +import javax.ws.rs.client.Entity; + +import org.gcube.common.clients.Call; +import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest; +import org.gcube.common.gxrest.response.inbound.GXInboundResponse; +import org.gcube.spatial.data.clients.model.ConnectionDescriptor; +import org.gcube.spatial.data.sdi.model.faults.RemoteException; + +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class AbstractProxy { + +private ConnectionDescriptor conn; + + + + @Setter + private String basePath=null; + + private Set> toRegisterClasses=new HashSet>(); + private Set toRegisterObjects=new HashSet<>(); + + protected AbstractProxy(ConnectionDescriptor conn) { + this.conn=conn; + } + + protected void register(Class providerClass) { + toRegisterClasses.add(providerClass); + } + + protected void register(Object provider) { + toRegisterObjects.add(provider); + } + + + + protected GXWebTargetAdapterRequest resolve() throws UnsupportedEncodingException { + GXWebTargetAdapterRequest toReturn =GXWebTargetAdapterRequest.newHTTPSRequest(conn.getEndpoint()); + if(basePath!=null) return toReturn.path(basePath); + + else return toReturn; + } + + + protected T makeCall(Call call) throws Exception{ + try{ + return call.call(resolve()); + }catch(RemoteException e) { + throw e; + }catch(Throwable t) { + throw new Exception(t); + } + } + + + protected void delete(String path) throws Exception { + check(resolve().path(path).delete(),null); + } + + protected void post(String path,Entity entity)throws Exception{ + post(path,entity,null); + } + + + protected void post(String path,Object obj) { + + } + + protected T post(String path,Entity entity,Class returnClazz) throws Exception { + return makeCall(new Call() { + + public T call(GXWebTargetAdapterRequest endpoint) throws Exception { + return check(endpoint.path(path).post(entity),returnClazz); + }; + + }); + } + + protected String get(String path) throws Exception { + return get(path,null); + } + + protected T get(String path, Class clazz) throws Exception{ + return makeCall(new Call() { + + public T call(GXWebTargetAdapterRequest endpoint) throws Exception { + return check(endpoint.path(path).get(),clazz); + }; + + }); + } + + + + + protected static T check(GXInboundResponse resp, Class clazz) throws RemoteException{ + try { + log.debug("Checking Response {}",resp); + if(resp.hasGXError()) { + RemoteException e=new RemoteException("Error received from server"); + e.setRemoteMessage(resp.getMessage()); + e.setResponseHTTPCode(resp.getHTTPCode()); + e.setContent(resp.getStreamedContentAsString()); + throw e; + }else { + if(clazz==null) return null; + + if(clazz==String.class) return (T) resp.getStreamedContentAsString(); + + return resp.tryConvertStreamedContentFromJson(clazz); + } + }catch(RemoteException e) { + throw e; + }catch(Exception e) { + throw new RemoteException("Unable to read response from server.",e); + } + } +} diff --git a/sdi-library/src/main/java/org/gcube/spatial/data/sdi/proxies/DefaultMetadata.java b/sdi-library/src/main/java/org/gcube/spatial/data/sdi/proxies/DefaultMetadata.java index 7360323..393a15c 100644 --- a/sdi-library/src/main/java/org/gcube/spatial/data/sdi/proxies/DefaultMetadata.java +++ b/sdi-library/src/main/java/org/gcube/spatial/data/sdi/proxies/DefaultMetadata.java @@ -2,16 +2,17 @@ package org.gcube.spatial.data.sdi.proxies; import java.io.File; import java.util.HashSet; +import java.util.Map; import java.util.Set; +import java.util.WeakHashMap; import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; import org.gcube.common.clients.Call; import org.gcube.common.clients.delegates.ProxyDelegate; +import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest; import org.gcube.spatial.data.sdi.interfaces.Metadata; import org.gcube.spatial.data.sdi.model.ServiceConstants; import org.gcube.spatial.data.sdi.model.metadata.MetadataPublishOptions; @@ -19,16 +20,17 @@ import org.gcube.spatial.data.sdi.model.metadata.MetadataReport; import org.gcube.spatial.data.sdi.model.metadata.TemplateCollection; import org.gcube.spatial.data.sdi.model.metadata.TemplateDescriptor; import org.gcube.spatial.data.sdi.model.metadata.TemplateInvocation; +import org.gcube.spatial.data.sdi.utils.ResponseUtils; import org.glassfish.jersey.media.multipart.FormDataMultiPart; import org.glassfish.jersey.media.multipart.MultiPartFeature; import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; -public class DefaultMetadata implements Metadata{ +public class DefaultMetadata implements Metadata { - private final ProxyDelegate delegate; + private final ProxyDelegate delegate; - public DefaultMetadata(ProxyDelegate config){ + public DefaultMetadata(ProxyDelegate config){ this.delegate = config; } @@ -36,12 +38,13 @@ public class DefaultMetadata implements Metadata{ @Override public TemplateCollection getAvailableTemplates() { - Call> call = new Call>() { + + Call> call = new Call>() { @Override - public Set call(WebTarget templates) throws Exception { + public Set call(GXWebTargetAdapterRequest templates) throws Exception { GenericType> generic=new GenericType>() { }; - return templates.path(ServiceConstants.Metadata.LIST_METHOD).request(MediaType.APPLICATION_JSON).get(generic); + return ResponseUtils.check(templates.path(ServiceConstants.Metadata.LIST_METHOD).get()).readEntity(generic); } }; try { @@ -60,52 +63,48 @@ public class DefaultMetadata implements Metadata{ public MetadataReport pushMetadata(final File toPublish, final MetadataPublishOptions options) { // upload Meta - Call applyTemplatesCall=null; //needs uploaded id - Call publishCall=null; //needs uploaded id + Call applyTemplatesCall=null; //needs uploaded id + Call publishCall=null; //needs uploaded id try{ - Call uploadCall=new Call() { + Call uploadCall=new Call() { @Override - public String call(WebTarget endpoint) throws Exception { + public String call(GXWebTargetAdapterRequest endpoint) throws Exception { endpoint.register(MultiPartFeature.class); FormDataMultiPart multi=new FormDataMultiPart(); // multi.field("file",toPublish,MediaType.APPLICATION_OCTET_STREAM_TYPE); FileDataBodyPart fileDataBodyPart = new FileDataBodyPart(ServiceConstants.Metadata.UPLOADED_FILE_PARAMETER, toPublish,MediaType.APPLICATION_OCTET_STREAM_TYPE); multi.bodyPart(fileDataBodyPart); - Response resp= endpoint.request().post(Entity.entity(multi, multi.getMediaType())); - checkResponse(resp); - return resp.readEntity(String.class); + return ResponseUtils.check(endpoint.post(Entity.entity(multi, multi.getMediaType())),String.class); } }; final String id=delegate.make(uploadCall); - applyTemplatesCall=new Call() { + applyTemplatesCall=new Call() { @Override - public MetadataReport call(WebTarget endpoint) throws Exception { + public MetadataReport call(GXWebTargetAdapterRequest endpoint) throws Exception { - - Response resp= endpoint.path(id). - request(MediaType.APPLICATION_JSON).put(Entity.entity( - new HashSet(options.getTemplateInvocations()),MediaType.APPLICATION_JSON)); - checkResponse(resp); - return resp.readEntity(MetadataReport.class); + return ResponseUtils.check(endpoint.path(id).put(Entity.entity( + new HashSet(options.getTemplateInvocations()),MediaType.APPLICATION_JSON)), MetadataReport.class); } }; - publishCall=new Call(){ + publishCall=new Call(){ @Override - public MetadataReport call(WebTarget endpoint) throws Exception { - Response resp= endpoint.path(ServiceConstants.Metadata.PUBLISH_METHOD).path(id).path(options.getGeonetworkCategory()). - queryParam(ServiceConstants.Metadata.VALIDATE_PARAMETER, options.isValidate()). - queryParam(ServiceConstants.Metadata.PUBLIC_PARAMETER, options.isMakePublic()). - queryParam(ServiceConstants.Metadata.STYLESHEET_PARAMETER, options.getGeonetworkStyleSheet()). - request(MediaType.APPLICATION_JSON).get(); - checkResponse(resp); - return resp.readEntity(MetadataReport.class); + public MetadataReport call(GXWebTargetAdapterRequest endpoint) throws Exception { + + Map queryParams = new WeakHashMap<>(); + queryParams.put(ServiceConstants.Metadata.VALIDATE_PARAMETER, options.isValidate()+""); + queryParams.put(ServiceConstants.Metadata.PUBLIC_PARAMETER, options.isMakePublic()+""); + queryParams.put(ServiceConstants.Metadata.STYLESHEET_PARAMETER, options.getGeonetworkStyleSheet()); + + return ResponseUtils.check(endpoint.path(ServiceConstants.Metadata.PUBLISH_METHOD).path(id).path(options.getGeonetworkCategory()). + get(), MetadataReport.class); + } }; }catch(Throwable t){ @@ -136,10 +135,4 @@ public class DefaultMetadata implements Metadata{ } - protected void checkResponse(Response toCheck) throws Exception{ - switch(toCheck.getStatusInfo().getFamily()){ - case SUCCESSFUL : break; - default : throw new Exception("Unexpected Response code : "+toCheck.getStatus(),new Exception(toCheck.readEntity(String.class))); - } - } } diff --git a/sdi-library/src/main/java/org/gcube/spatial/data/sdi/proxies/DefaultSDIManagement.java b/sdi-library/src/main/java/org/gcube/spatial/data/sdi/proxies/DefaultSDIManagement.java index c3ed464..afa1240 100644 --- a/sdi-library/src/main/java/org/gcube/spatial/data/sdi/proxies/DefaultSDIManagement.java +++ b/sdi-library/src/main/java/org/gcube/spatial/data/sdi/proxies/DefaultSDIManagement.java @@ -2,32 +2,32 @@ package org.gcube.spatial.data.sdi.proxies; import java.util.List; -import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MediaType; import org.gcube.common.clients.Call; import org.gcube.common.clients.delegates.ProxyDelegate; +import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest; import org.gcube.spatia.data.model.profiles.ApplicationProfile; import org.gcube.spatial.data.clients.SDIClientManager; import org.gcube.spatial.data.clients.SDIGenericClient; import org.gcube.spatial.data.clients.model.ClientInfo; -import org.gcube.spatial.data.clients.model.ConnectionDescriptor; import org.gcube.spatial.data.sdi.interfaces.SDIManagement; import org.gcube.spatial.data.sdi.model.ScopeConfiguration; import org.gcube.spatial.data.sdi.model.ServiceConstants; import org.gcube.spatial.data.sdi.model.faults.RemoteException; import org.gcube.spatial.data.sdi.model.health.HealthReport; import org.gcube.spatial.data.sdi.model.service.GeoServiceDescriptor; +import org.gcube.spatial.data.sdi.utils.ResponseUtils; import lombok.extern.slf4j.Slf4j; @Slf4j public class DefaultSDIManagement implements SDIManagement{ - private final ProxyDelegate delegate; + private final ProxyDelegate delegate; private SDIClientManager clientManager=null; - public DefaultSDIManagement(ProxyDelegate delegate) { + public DefaultSDIManagement(ProxyDelegate delegate) { this.delegate=delegate; clientManager=new SDIClientManager(); log.debug("Available clients are "); @@ -39,10 +39,11 @@ public class DefaultSDIManagement implements SDIManagement{ @Override public ScopeConfiguration getConfiguration() throws RemoteException { - Call call=new Call(){ + Call call= + new Call(){ @Override - public ScopeConfiguration call(WebTarget endpoint) throws Exception { - return endpoint.request().get(ScopeConfiguration.class); + public ScopeConfiguration call(GXWebTargetAdapterRequest endpoint) throws Exception { + return ResponseUtils.check(endpoint.get(),ScopeConfiguration.class); } }; try { @@ -54,10 +55,11 @@ public class DefaultSDIManagement implements SDIManagement{ @Override public HealthReport getReport() throws RemoteException { - Call call=new Call(){ + Call call=new Call(){ @Override - public HealthReport call(WebTarget endpoint) throws Exception { - return endpoint.path(ServiceConstants.SDI.STATUS_PATH).request(MediaType.APPLICATION_JSON).get(HealthReport.class); + public HealthReport call(GXWebTargetAdapterRequest endpoint) throws Exception { + return ResponseUtils.check(endpoint.setAcceptedResponseType(MediaType.APPLICATION_JSON_TYPE).path(ServiceConstants.SDI.STATUS_PATH). + get(),HealthReport.class); } }; try { @@ -70,11 +72,11 @@ public class DefaultSDIManagement implements SDIManagement{ @Override public ApplicationProfile getProfile(String serviceClass,String serviceName) throws RemoteException { - Call call=new Call(){ + Call call=new Call(){ @Override - public ApplicationProfile call(WebTarget endpoint) throws Exception { - return endpoint.path(ServiceConstants.SDI.PROFILES_PATH).path(serviceClass). - path(serviceName).request(MediaType.APPLICATION_JSON).get(ApplicationProfile.class); + public ApplicationProfile call(GXWebTargetAdapterRequest endpoint) throws Exception { + return ResponseUtils.check(endpoint.path(ServiceConstants.SDI.PROFILES_PATH).path(serviceClass). + path(serviceName).get(),ApplicationProfile.class); } }; try { diff --git a/sdi-library/src/main/java/org/gcube/spatial/data/sdi/utils/ResponseUtils.java b/sdi-library/src/main/java/org/gcube/spatial/data/sdi/utils/ResponseUtils.java new file mode 100644 index 0000000..ce87c15 --- /dev/null +++ b/sdi-library/src/main/java/org/gcube/spatial/data/sdi/utils/ResponseUtils.java @@ -0,0 +1,82 @@ +package org.gcube.spatial.data.sdi.utils; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status.Family; + +import org.gcube.common.gxrest.response.inbound.GXInboundResponse; +import org.gcube.spatial.data.sdi.model.faults.RemoteException; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class ResponseUtils { + + public static T check(GXInboundResponse resp, Class clazz) throws RemoteException{ + try { + log.debug("Checking Response {}",resp); + + if(resp.hasGXError()||!resp.getSource().getStatusInfo().getFamily().equals(Family.SUCCESSFUL)) { + RemoteException e=new RemoteException("Error received from server"); + e.setRemoteMessage(resp.getMessage()); + e.setResponseHTTPCode(resp.getHTTPCode()); + e.setContent(resp.getStreamedContentAsString()); + throw e; + }else { + if(clazz==null) return null; + + if(clazz==String.class) return (T) resp.getStreamedContentAsString(); + + return resp.tryConvertStreamedContentFromJson(clazz); + } + }catch(RemoteException e) { + throw e; + }catch(Exception e) { + throw new RemoteException("Unable to read response from server.",e); + } + } + + + public static Response check(GXInboundResponse resp) throws RemoteException{ + try { + log.debug("Checking Response {}",resp); + + if(resp.hasGXError()||!resp.getSource().getStatusInfo().getFamily().equals(Family.SUCCESSFUL)) { + RemoteException e=new RemoteException("Error received from server"); + e.setRemoteMessage(resp.getMessage()); + e.setResponseHTTPCode(resp.getHTTPCode()); + e.setContent(resp.getStreamedContentAsString()); + throw e; + }else { + return resp.getSource(); + } + }catch(RemoteException e) { + throw e; + }catch(Exception e) { + throw new RemoteException("Unable to read response from server.",e); + } + } + +// protected static T check(GXInboundResponse resp, Class clazz) throws RemoteException{ +// try { +// log.debug("Checking Response {}",resp); +// if(resp.hasGXError()) { +// RemoteException e=new RemoteException("Error received from server"); +// e.setRemoteMessage(resp.getMessage()); +// e.setResponseHTTPCode(resp.getHTTPCode()); +// e.setContent(resp.getStreamedContentAsString()); +// throw e; +// }else { +// if(clazz==null) return null; +// +// if(clazz==String.class) return (T) resp.getStreamedContentAsString(); +// +// return resp.tryConvertStreamedContentFromJson(clazz); +// } +// }catch(RemoteException e) { +// throw e; +// }catch(Exception e) { +// throw new RemoteException("Unable to read response from server.",e); +// } +// } + +} diff --git a/sdi-library/src/test/java/org/gcube/spatial/data/sdi/MetadataTests.java b/sdi-library/src/test/java/org/gcube/spatial/data/sdi/MetadataTests.java index 0c1b7e9..fc99527 100644 --- a/sdi-library/src/test/java/org/gcube/spatial/data/sdi/MetadataTests.java +++ b/sdi-library/src/test/java/org/gcube/spatial/data/sdi/MetadataTests.java @@ -1,5 +1,6 @@ package org.gcube.spatial.data.sdi; +import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; import java.io.File; @@ -41,11 +42,16 @@ public class MetadataTests extends GCubeSDITest{ } })) { + try { // System.out.println(meta.pushMetadata(f)); MetadataPublishOptions opts=new MetadataPublishOptions(new TemplateInvocationBuilder().threddsOnlineResources("my_hostname", "some_dataset.nc", "myPersonalCatalog").get()); opts.setGeonetworkCategory("service"); opts.setValidate(false); System.out.println(meta.pushMetadata(f, opts)); + }catch(Exception e) { + + throw new RuntimeException("Unable to push "+f.getName(),e); + } } } diff --git a/sdi-library/src/test/java/org/gcube/spatial/data/sdi/SDITests.java b/sdi-library/src/test/java/org/gcube/spatial/data/sdi/SDITests.java index 7df7ae7..b289f4a 100644 --- a/sdi-library/src/test/java/org/gcube/spatial/data/sdi/SDITests.java +++ b/sdi-library/src/test/java/org/gcube/spatial/data/sdi/SDITests.java @@ -36,8 +36,8 @@ public class SDITests extends GCubeSDITest{ System.out.println( SDIAbstractPlugin.management().build().getClientByEngineId(Engine.GS_ENGINE).getInfo()); - GSRESTClient gs=(GSRESTClient) SDIAbstractPlugin.management().build().getClientByEngineId(Engine.GS_ENGINE).getRESTClient(); - gs.getWorkspaces(); - +// GSRESTClient gs=(GSRESTClient) SDIAbstractPlugin.management().build().getClientByEngineId(Engine.GS_ENGINE).getRESTClient(); +// gs.getWorkspaces(); +// } } diff --git a/sdi-service/src/main/java/org/gcube/spatial/data/sdi/rest/SDI.java b/sdi-service/src/main/java/org/gcube/spatial/data/sdi/rest/SDI.java index a78ae4d..bd715c4 100644 --- a/sdi-service/src/main/java/org/gcube/spatial/data/sdi/rest/SDI.java +++ b/sdi-service/src/main/java/org/gcube/spatial/data/sdi/rest/SDI.java @@ -18,7 +18,7 @@ import org.gcube.spatial.data.sdi.model.health.HealthReport; import lombok.extern.slf4j.Slf4j; -@Path(ServiceConstants.INTERFACE) +@Path(ServiceConstants.SDI.INTERFACE) //@Api(value=ServiceConstants.INTERFACE) @ManagedBy(SDIServiceManager.class) @Slf4j diff --git a/sdi-service/src/test/java/org/gcube/spatial/data/sdi/test/MainTest.java b/sdi-service/src/test/java/org/gcube/spatial/data/sdi/test/MainTest.java index 227b5cf..dd4aea6 100644 --- a/sdi-service/src/test/java/org/gcube/spatial/data/sdi/test/MainTest.java +++ b/sdi-service/src/test/java/org/gcube/spatial/data/sdi/test/MainTest.java @@ -25,8 +25,8 @@ public class MainTest extends ServiceTest{ @Test public void getConfiguration(){ assumeTrue(isTestInfrastructureEnabled()); - System.out.println(target(ServiceConstants.INTERFACE).request(MediaType.APPLICATION_JSON_TYPE).get(String.class)); - ScopeConfiguration conf=target(ServiceConstants.INTERFACE).request(MediaType.APPLICATION_JSON_TYPE).get(ScopeConfiguration.class); + System.out.println(target(ServiceConstants.SDI.INTERFACE).request(MediaType.APPLICATION_JSON_TYPE).get(String.class)); + ScopeConfiguration conf=target(ServiceConstants.SDI.INTERFACE).request(MediaType.APPLICATION_JSON_TYPE).get(ScopeConfiguration.class); } // @@ -34,7 +34,7 @@ public class MainTest extends ServiceTest{ public void getGeoServer() throws MalformedURLException{ assumeTrue(isTestInfrastructureEnabled()); - ScopeConfiguration conf=target(ServiceConstants.INTERFACE).request(MediaType.APPLICATION_JSON_TYPE).get(ScopeConfiguration.class); + ScopeConfiguration conf=target(ServiceConstants.SDI.INTERFACE).request(MediaType.APPLICATION_JSON_TYPE).get(ScopeConfiguration.class); assumeTrue(!conf.getByEngine(Engine.GS_ENGINE).isEmpty()); @@ -49,8 +49,8 @@ public class MainTest extends ServiceTest{ @Test public void testHealthReport() { assumeTrue(isTestInfrastructureEnabled()); - System.out.println(target(ServiceConstants.INTERFACE).path("status").request(MediaType.APPLICATION_JSON_TYPE).get(String.class)); - System.out.println(target(ServiceConstants.INTERFACE).path("status").request(MediaType.APPLICATION_XML_TYPE).get(String.class)); + System.out.println(target(ServiceConstants.SDI.INTERFACE).path("status").request(MediaType.APPLICATION_JSON_TYPE).get(String.class)); + System.out.println(target(ServiceConstants.SDI.INTERFACE).path("status").request(MediaType.APPLICATION_XML_TYPE).get(String.class)); } diff --git a/sdi-test-commons/pom.xml b/sdi-test-commons/pom.xml index dac2a7b..bf87134 100644 --- a/sdi-test-commons/pom.xml +++ b/sdi-test-commons/pom.xml @@ -1,4 +1,5 @@ - 4.0.0 @@ -10,45 +11,49 @@ 0.0.2-SNAPSHOT SDI test commons - - + + scm:git:${gitBaseUrl}/gcube-sdi-suite scm:git:${gitBaseUrl}/gcube-sdi-suite ${gitBaseUrl}/gcube-sdi-suite - - + + sdi-interface org.gcube.spatial.data - - - - org.gcube.core - common-fw-clients - - - - org.gcube.core - common-generic-clients - - - + + org.gcube.common - common-jaxrs-client - [1.0.0,2.0.0) + gxJRS - - + + + + org.gcube.core + common-fw-clients + + + + org.gcube.core + common-generic-clients + + + + org.glassfish.jersey.core + jersey-client + + + junit junit 4.12 - - + + - + Java library used to implement SDI clients. \ No newline at end of file diff --git a/sdi-test-commons/src/main/java/org/gcube/sdi/test/client/SimpleSDIManagerClient.java b/sdi-test-commons/src/main/java/org/gcube/sdi/test/client/SimpleSDIManagerClient.java index e0de7f3..953d6ee 100644 --- a/sdi-test-commons/src/main/java/org/gcube/sdi/test/client/SimpleSDIManagerClient.java +++ b/sdi-test-commons/src/main/java/org/gcube/sdi/test/client/SimpleSDIManagerClient.java @@ -2,25 +2,20 @@ package org.gcube.sdi.test.client; import java.util.List; -import javax.ws.rs.client.WebTarget; -import javax.xml.namespace.QName; import javax.xml.transform.dom.DOMResult; import javax.xml.ws.EndpointReference; -import org.gcube.common.calls.jaxrs.GcubeService; -import org.gcube.common.calls.jaxrs.TargetFactory; import org.gcube.common.clients.Call; import org.gcube.common.clients.Plugin; import org.gcube.common.clients.ProxyBuilder; import org.gcube.common.clients.ProxyBuilderImpl; import org.gcube.common.clients.config.ProxyConfig; import org.gcube.common.clients.delegates.ProxyDelegate; +import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest; +import org.gcube.common.gxrest.response.inbound.GXInboundResponse; import org.gcube.spatia.data.model.profiles.ApplicationProfile; import org.gcube.spatial.data.clients.SDIClientManager; import org.gcube.spatial.data.clients.SDIGenericClient; -import org.gcube.spatial.data.clients.model.ClientInfo; -import org.gcube.spatial.data.clients.model.ConnectionDescriptor; -import org.gcube.spatial.data.clients.model.engine.Engine; import org.gcube.spatial.data.sdi.interfaces.SDIManagement; import org.gcube.spatial.data.sdi.model.ScopeConfiguration; import org.gcube.spatial.data.sdi.model.ServiceConstants; @@ -32,8 +27,8 @@ import org.w3c.dom.Node; public class SimpleSDIManagerClient implements SDIManagement{ public static ProxyBuilder contextService() { - return new ProxyBuilderImpl( - new Plugin(){ + return new ProxyBuilderImpl( + new Plugin(){ @Override public String serviceClass() {return ServiceConstants.SERVICE_CLASS;} @Override @@ -44,36 +39,52 @@ public class SimpleSDIManagerClient implements SDIManagement{ public Exception convert(Exception fault, ProxyConfig config) {return fault;} @Override public String namespace() {return ServiceConstants.NAMESPACE;} + + @Override - public WebTarget resolve(EndpointReference epr, ProxyConfig arg1) throws Exception { + public GXWebTargetAdapterRequest resolve(EndpointReference epr, ProxyConfig config) + throws Exception { DOMResult result = new DOMResult(); epr.writeTo(result); Node node =result.getNode(); Node child=node.getFirstChild(); String address = child.getTextContent(); - GcubeService service = GcubeService.service(). - withName(new QName(ServiceConstants.NAMESPACE,ServiceConstants.INTERFACE)). - andPath(ServiceConstants.INTERFACE); - return TargetFactory.stubFor(service).at(address); + GXWebTargetAdapterRequest request = + GXWebTargetAdapterRequest.newRequest(address).path(ServiceConstants.SDI.INTERFACE); + //set additional path parts or parameters here + return request; + } + @Override - public SDIManagement newProxy(ProxyDelegate delegate) {return new SimpleSDIManagerClient(delegate);} + public SDIManagement newProxy(ProxyDelegate delegate) { + return new SimpleSDIManagerClient(delegate);} }); } - private final ProxyDelegate delegate; + private final ProxyDelegate delegate; private SDIClientManager clientManager=null; - public SimpleSDIManagerClient(ProxyDelegate delegate) { - this.delegate=delegate; + public SimpleSDIManagerClient(ProxyDelegate delegate) { + this.delegate=delegate; } @Override public ScopeConfiguration getConfiguration() throws RemoteException { - Call call=new Call(){ + Call call=new Call(){ @Override - public ScopeConfiguration call(WebTarget endpoint) throws Exception { - return endpoint.request().get(ScopeConfiguration.class); + public ScopeConfiguration call(GXWebTargetAdapterRequest request) throws Exception { + GXInboundResponse response = request.get(); + if (response.hasGXError()|| + response.getHTTPCode()<200||response.getHTTPCode()>299) { + RemoteException e=new RemoteException("Received error response."); + e.setContent(response.getStreamedContentAsString()); + e.setRemoteMessage(response.getMessage()); + e.setResponseHTTPCode(response.getHTTPCode()); + throw e; + } + //MultiLocatorResponse is the expected content of the response in the form of a serialized Json + return response.tryConvertStreamedContentFromJson(ScopeConfiguration.class); } }; try { diff --git a/sdi-test-commons/src/test/java/org/gcube/sdi/test/TestsCalls.java b/sdi-test-commons/src/test/java/org/gcube/sdi/test/TestsCalls.java new file mode 100644 index 0000000..5e7c981 --- /dev/null +++ b/sdi-test-commons/src/test/java/org/gcube/sdi/test/TestsCalls.java @@ -0,0 +1,19 @@ +package org.gcube.sdi.test; + +import static org.junit.Assume.assumeTrue; + +import org.gcube.spatial.data.sdi.model.faults.RemoteException; +import org.junit.Test; + +public class TestsCalls extends GCubeSDITest{ + + @Test + public void testUtils() throws RemoteException { + assumeTrue(isTestInfrastructureEnabled()); + System.out.println(scopeConfiguration()); + System.out.println(manager().getReport()); + } + + + +}