gxRest integration

This commit is contained in:
Fabio Sinibaldi 2021-04-09 18:15:10 +02:00
parent 3ed3648739
commit 4822913bc7
24 changed files with 619 additions and 287 deletions

View File

@ -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<String> 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<String> getStylesNamesinWorkspace(String ws)throws RemoteException,Exception;
public JSONObject getStylesByLayer(String layer)throws RemoteException,Exception;
public List<String> 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;
}

View File

@ -125,8 +125,6 @@ public class GSRESTClientImpl extends AbstractGenericRESTClient implements GSRES
}
@Override
public List<String> 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;
}
}

View File

@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@ -10,57 +11,79 @@
<version>0.0.1-SNAPSHOT</version>
<name>Generic SDI Client</name>
<scm>
<scm>
<connection>scm:git:${gitBaseUrl}/gcube-sdi-suite</connection>
<developerConnection>scm:git:${gitBaseUrl}/gcube-sdi-suite</developerConnection>
<url>${gitBaseUrl}/gcube-sdi-suite</url>
</scm>
<dependencies>
<dependency>
<artifactId>sdi-interface</artifactId>
<groupId>org.gcube.spatial.data</groupId>
</dependency>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-gcube-calls</artifactId>
<groupId>org.gcube.common</groupId>
<artifactId>gxJRS</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-fw-clients</artifactId>
</dependency>
<artifactId>common-fw-clients</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-generic-clients</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.gcube.common</groupId> -->
<!-- <artifactId>authorization-client</artifactId> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.gcube.core</groupId> -->
<!-- <artifactId>common-gcube-calls</artifactId> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.gcube.core</groupId> -->
<!-- <artifactId>common-fw-clients</artifactId> -->
<!-- </dependency> -->
<!-- read JSON -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.glassfish.jersey.core</groupId> -->
<!-- <artifactId>jersey-client</artifactId> -->
<!-- </dependency> -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.glassfish.jersey.media</groupId> -->
<!-- <artifactId>jersey-media-json-jackson</artifactId> -->
<!-- </dependency> -->
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.4.0</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.glassfish.jersey.media</groupId> -->
<!-- <artifactId>jersey-media-multipart</artifactId> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>com.jayway.jsonpath</groupId> -->
<!-- <artifactId>json-path</artifactId> -->
<!-- <version>2.4.0</version> -->
<!-- </dependency> -->
<!-- TEST -->
@ -68,10 +91,10 @@
<artifactId>sdi-test-commons</artifactId>
<groupId>org.gcube.spatial.data</groupId>
<scope>test</scope>
</dependency>
</dependency>
</dependencies>
<description>Java library used to implement SDI clients.</description>
</project>

View File

@ -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<Class<?>> toRegisterClasses=new HashSet<Class<?>>();
private Set<Object> 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> T makeCall(Call<WebTarget, T> call) throws Exception{
protected <T> T makeCall(Call<GXWebTargetAdapterRequest, T> 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> T post(String path,Entity<?> entity,Class<T> returnClazz) throws Exception {
return makeCall(new Call<WebTarget, T>() {
return makeCall(new Call<GXWebTargetAdapterRequest, T>() {
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> T get(String path, Class<T> clazz) throws Exception{
return makeCall(new Call<WebTarget, T>() {
return makeCall(new Call<GXWebTargetAdapterRequest, T>() {
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> T check(Response resp, Class<T> 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> T check(GXInboundResponse resp, Class<T> 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);
}
}

View File

@ -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<String, String> 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<String, String> entry: requestContext.getHeaders()){
// rc.getHeaders().put(entry.getKey(), Collections.singletonList((Object)entry.getValue()));
// }
// }
}

View File

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

View File

@ -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";

View File

@ -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";

View File

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

View File

@ -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;

View File

@ -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<WebTarget, Metadata>{
public class MetadataPlugin extends SDIAbstractPlugin<GXWebTargetAdapterRequest, Metadata>{
public MetadataPlugin() {
super("sdi-service/gcube/service");
@ -25,21 +22,21 @@ public class MetadataPlugin extends SDIAbstractPlugin<WebTarget, Metadata>{
return arg0;
}
@Override
public Metadata newProxy(ProxyDelegate<WebTarget> arg0) {
public Metadata newProxy(ProxyDelegate<GXWebTargetAdapterRequest> 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;
}
}

View File

@ -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<S, P> implements Plugin<S, P>{
public static ProxyBuilder<Metadata> metadata() {
return new ProxyBuilderImpl<WebTarget,Metadata>(metadata_plugin);
return new ProxyBuilderImpl<GXWebTargetAdapterRequest,Metadata>(metadata_plugin);
}
public static ProxyBuilder<SDIManagement> management() {
return new ProxyBuilderImpl<WebTarget,SDIManagement>(sdi_plugin);
return new ProxyBuilderImpl<GXWebTargetAdapterRequest,SDIManagement>(sdi_plugin);
}

View File

@ -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<WebTarget, SDIManagement>{
public class SDIPlugin extends SDIAbstractPlugin<GXWebTargetAdapterRequest, SDIManagement>{
public SDIPlugin() {
super("sdi-service/gcube/service");
@ -25,21 +26,21 @@ public class SDIPlugin extends SDIAbstractPlugin<WebTarget, SDIManagement>{
return arg0;
}
@Override
public SDIManagement newProxy(ProxyDelegate<WebTarget> arg0) {
public SDIManagement newProxy(ProxyDelegate<GXWebTargetAdapterRequest> 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;
}
}

View File

@ -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<Class<?>> toRegisterClasses=new HashSet<Class<?>>();
private Set<Object> 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> T makeCall(Call<GXWebTargetAdapterRequest, T> 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> T post(String path,Entity<?> entity,Class<T> returnClazz) throws Exception {
return makeCall(new Call<GXWebTargetAdapterRequest, T>() {
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> T get(String path, Class<T> clazz) throws Exception{
return makeCall(new Call<GXWebTargetAdapterRequest, T>() {
public T call(GXWebTargetAdapterRequest endpoint) throws Exception {
return check(endpoint.path(path).get(),clazz);
};
});
}
protected static <T> T check(GXInboundResponse resp, Class<T> 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);
}
}
}

View File

@ -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<WebTarget> delegate;
private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
public DefaultMetadata(ProxyDelegate<WebTarget> config){
public DefaultMetadata(ProxyDelegate<GXWebTargetAdapterRequest> config){
this.delegate = config;
}
@ -36,12 +38,13 @@ public class DefaultMetadata implements Metadata{
@Override
public TemplateCollection getAvailableTemplates() {
Call<WebTarget, Set<TemplateDescriptor>> call = new Call<WebTarget, Set<TemplateDescriptor>>() {
Call<GXWebTargetAdapterRequest, Set<TemplateDescriptor>> call = new Call<GXWebTargetAdapterRequest, Set<TemplateDescriptor>>() {
@Override
public Set<TemplateDescriptor> call(WebTarget templates) throws Exception {
public Set<TemplateDescriptor> call(GXWebTargetAdapterRequest templates) throws Exception {
GenericType<Set<TemplateDescriptor>> generic=new GenericType<Set<TemplateDescriptor>>() {
};
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<WebTarget,MetadataReport> applyTemplatesCall=null; //needs uploaded id
Call<WebTarget,MetadataReport> publishCall=null; //needs uploaded id
Call<GXWebTargetAdapterRequest,MetadataReport> applyTemplatesCall=null; //needs uploaded id
Call<GXWebTargetAdapterRequest,MetadataReport> publishCall=null; //needs uploaded id
try{
Call<WebTarget,String> uploadCall=new Call<WebTarget, String>() {
Call<GXWebTargetAdapterRequest,String> uploadCall=new Call<GXWebTargetAdapterRequest, String>() {
@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<WebTarget, MetadataReport>() {
applyTemplatesCall=new Call<GXWebTargetAdapterRequest, MetadataReport>() {
@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<TemplateInvocation>(options.getTemplateInvocations()),MediaType.APPLICATION_JSON));
checkResponse(resp);
return resp.readEntity(MetadataReport.class);
return ResponseUtils.check(endpoint.path(id).put(Entity.entity(
new HashSet<TemplateInvocation>(options.getTemplateInvocations()),MediaType.APPLICATION_JSON)), MetadataReport.class);
}
};
publishCall=new Call<WebTarget,MetadataReport>(){
publishCall=new Call<GXWebTargetAdapterRequest,MetadataReport>(){
@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<String,String> 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)));
}
}
}

View File

@ -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<WebTarget> delegate;
private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
private SDIClientManager clientManager=null;
public DefaultSDIManagement(ProxyDelegate<WebTarget> delegate) {
public DefaultSDIManagement(ProxyDelegate<GXWebTargetAdapterRequest> 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<WebTarget, ScopeConfiguration> call=new Call<WebTarget,ScopeConfiguration>(){
Call<GXWebTargetAdapterRequest, ScopeConfiguration> call=
new Call<GXWebTargetAdapterRequest,ScopeConfiguration>(){
@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<WebTarget, HealthReport> call=new Call<WebTarget,HealthReport>(){
Call<GXWebTargetAdapterRequest, HealthReport> call=new Call<GXWebTargetAdapterRequest,HealthReport>(){
@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<WebTarget, ApplicationProfile> call=new Call<WebTarget,ApplicationProfile>(){
Call<GXWebTargetAdapterRequest, ApplicationProfile> call=new Call<GXWebTargetAdapterRequest,ApplicationProfile>(){
@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 {

View File

@ -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> T check(GXInboundResponse resp, Class<T> 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> T check(GXInboundResponse resp, Class<T> 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);
// }
// }
}

View File

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

View File

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

View File

@ -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

View File

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

View File

@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@ -10,45 +11,49 @@
<version>0.0.2-SNAPSHOT</version>
<name>SDI test commons</name>
<scm>
<scm>
<connection>scm:git:${gitBaseUrl}/gcube-sdi-suite</connection>
<developerConnection>scm:git:${gitBaseUrl}/gcube-sdi-suite</developerConnection>
<url>${gitBaseUrl}/gcube-sdi-suite</url>
</scm>
<dependencies>
<dependency>
<artifactId>sdi-interface</artifactId>
<groupId>org.gcube.spatial.data</groupId>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-fw-clients</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-generic-clients</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-jaxrs-client</artifactId>
<version>[1.0.0,2.0.0)</version>
<artifactId>gxJRS</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-fw-clients</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-generic-clients</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<description>Java library used to implement SDI clients.</description>
</project>

View File

@ -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<SDIManagement> contextService() {
return new ProxyBuilderImpl<WebTarget,SDIManagement>(
new Plugin<WebTarget, SDIManagement>(){
return new ProxyBuilderImpl<GXWebTargetAdapterRequest,SDIManagement>(
new Plugin<GXWebTargetAdapterRequest, SDIManagement>(){
@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<WebTarget> delegate) {return new SimpleSDIManagerClient(delegate);}
public SDIManagement newProxy(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
return new SimpleSDIManagerClient(delegate);}
});
}
private final ProxyDelegate<WebTarget> delegate;
private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
private SDIClientManager clientManager=null;
public SimpleSDIManagerClient(ProxyDelegate<WebTarget> delegate) {
this.delegate=delegate;
public SimpleSDIManagerClient(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
this.delegate=delegate;
}
@Override
public ScopeConfiguration getConfiguration() throws RemoteException {
Call<WebTarget, ScopeConfiguration> call=new Call<WebTarget,ScopeConfiguration>(){
Call<GXWebTargetAdapterRequest, ScopeConfiguration> call=new Call<GXWebTargetAdapterRequest,ScopeConfiguration>(){
@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 {

View File

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