diff --git a/CHANGELOG.md b/CHANGELOG.md index e40e236..eb234c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm # Changelog for org.gcube.spatial.data.ws-thredds +## [v0.2.5-SNAPSHOT] +Fixes #21265 + + ## [v0.2.4] Default validate flag= false From http to https diff --git a/pom.xml b/pom.xml index 8111d02..c2c79c3 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ org.gcube.spatial.data ws-thredds - 0.2.4 + 0.2.5-SNAPSHOT ws-thredds prototype of WS integration with data-transfer for Thredds pubblication @@ -41,32 +41,47 @@ org.gcube.spatial.data sdi-library - [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) - - - com.fasterxml.jackson.core - jackson-annotations - - + [1.0.0-SNAPSHOT,1.3.0-SNAPSHOT) + + + + + + + + + org.gcube.common + storagehub-client-library + + + org.gcube.data.transfer data-transfer-library [1.2.0-SNAPSHOT,2.0.0-SNAPSHOT) - - - - - org.gcube.common - storagehub-client-library + com.fasterxml.jackson.core + jackson-core + [2.8.4,) + + + com.fasterxml.jackson.core + jackson-databind + [2.8.4,) + + + + + com.jayway.jsonpath + json-path + 2.5.0 + + org.slf4j diff --git a/src/main/java/org/gcube/usecases/ws/thredds/Constants.java b/src/main/java/org/gcube/usecases/ws/thredds/Constants.java index 20823ea..ce0fb41 100644 --- a/src/main/java/org/gcube/usecases/ws/thredds/Constants.java +++ b/src/main/java/org/gcube/usecases/ws/thredds/Constants.java @@ -18,6 +18,7 @@ public class Constants { public static final String SDI_THREDDS_BASE_URL="sdi-service/gcube/service/Thredds"; + public static final String SDI_CONFIG_PATH="sdi-service/gcube/service/SDI"; public static final String SIS_PLUGIN_ID="SIS/GEOTK"; diff --git a/src/main/java/org/gcube/usecases/ws/thredds/engine/impl/ThreddsController.java b/src/main/java/org/gcube/usecases/ws/thredds/engine/impl/ThreddsController.java index db56f4c..30c46ce 100644 --- a/src/main/java/org/gcube/usecases/ws/thredds/engine/impl/ThreddsController.java +++ b/src/main/java/org/gcube/usecases/ws/thredds/engine/impl/ThreddsController.java @@ -9,6 +9,7 @@ import java.io.InputStream; import java.io.PrintWriter; import java.net.URL; import java.nio.file.Files; +import java.util.List; import java.util.Set; import javax.ws.rs.client.Client; @@ -49,11 +50,23 @@ import org.gcube.usecases.ws.thredds.faults.UnableToLockException; import org.glassfish.jersey.client.ClientConfig; import org.glassfish.jersey.client.ClientProperties; +import com.jayway.jsonpath.Configuration; +import com.jayway.jsonpath.DocumentContext; +import com.jayway.jsonpath.JsonPath; +import com.jayway.jsonpath.Option; + import lombok.extern.slf4j.Slf4j; @Slf4j public class ThreddsController { + static Configuration JSON_PATH_ALWAYS_LIST_CONFIG= Configuration.builder(). + options(Option.ALWAYS_RETURN_LIST, + Option.SUPPRESS_EXCEPTIONS, + Option.DEFAULT_PATH_LEAF_TO_NULL).build(); + + + private String hostname; private String operatingPath; private String targetToken; @@ -61,10 +74,9 @@ public class ThreddsController { public ThreddsController(String path,String targetToken) throws InternalException { operatingPath=path; this.targetToken=targetToken; - setTargetToken(); + hostname=getThreddsHost(); - if(hostname==null) throw new InternalException("Unable to find a thredds instance in target scope "+ScopeUtils.getCurrentScope()); - resetCallerToken(); + if(hostname==null) throw new InternalException("Invalid hostnam in context "+ScopeUtils.getCurrentScope()); } private static final String truncate(String toTruncate) { @@ -292,8 +304,24 @@ public class ThreddsController { } - private static String getThreddsHost(){ - return getGCoreEndpointHostname(ServiceConstants.SERVICE_CLASS, "Thredds"); + private String getThreddsHost() throws InternalException{ + setTargetToken(); + try{ + String sdiUrl="https://"+getSDIServiceHost()+"/"+Constants.SDI_CONFIG_PATH; + log.info("checking sdI configuration at {}",sdiUrl); + Response resp=getWebClient().target(sdiUrl).request(MediaType.APPLICATION_JSON_TYPE).get(); + String respString=resp.readEntity(String.class); + if(!(resp.getStatus()>=200&&resp.getStatus()<300)) + throw new InternalException("Failed to contact SDI. Message "+respString); + + DocumentContext sourceCtx=JsonPath.using(JSON_PATH_ALWAYS_LIST_CONFIG).parse(respString); + return new URL(((List) sourceCtx.read("$.threddsConfiguration..baseEndpoint")).get(0)).getHost(); + }catch(Throwable t) { + log.error("Unable to read SDI configuration",t); + throw new InternalException("Unable to gt configuration from SDI",t); + }finally { + resetCallerToken(); + } } private static String getGCoreEndpointHostname(String serviceClass,String serviceName) { diff --git a/src/test/java/org/gcube/usecases/ws/thredds/GetTrhreddsInfoTest.java b/src/test/java/org/gcube/usecases/ws/thredds/GetTrhreddsInfoTest.java new file mode 100644 index 0000000..9a2c3cd --- /dev/null +++ b/src/test/java/org/gcube/usecases/ws/thredds/GetTrhreddsInfoTest.java @@ -0,0 +1,17 @@ +package org.gcube.usecases.ws.thredds; + +import org.gcube.data.transfer.library.utils.ScopeUtils; +import org.gcube.usecases.ws.thredds.faults.InternalException; + +public class GetTrhreddsInfoTest { + + + public static void main(String[] args) throws InternalException { + SyncEngine engine=SyncEngine.get(); + // ROOT + System.out.println(engine.getAvailableCatalogsByToken("***REMOVED***")); + // MEI + System.out.println(engine.getAvailableCatalogsByToken("54f577de-d259-407e-b30d-29bf9e7c0dee-843339462")); + } + +} diff --git a/src/test/java/org/gcube/usecases/ws/thredds/TestInit.java b/src/test/java/org/gcube/usecases/ws/thredds/TestInit.java new file mode 100644 index 0000000..f378b5e --- /dev/null +++ b/src/test/java/org/gcube/usecases/ws/thredds/TestInit.java @@ -0,0 +1,24 @@ +package org.gcube.usecases.ws.thredds; + +import org.gcube.spatial.data.sdi.utils.ScopeUtils; +import org.gcube.usecases.ws.thredds.faults.InternalException; + +public class TestInit { + + public static void main(String[] args) throws InternalException { + TokenSetter.set("/gcube/devsec/devVRE"); + + System.out.println("Context "+ScopeUtils.getCurrentScope()+" token "+ScopeUtils.getCurrentCaller()); + final SyncEngine engine=SyncEngine.get(); + + +// // TO BE INTRODUCED LATER +// engine.getAvailableCatalogsByToken(Security.getToken()).forEach((CatalogBean c)->{ +// +// System.out.println(c); +// +// }); + + } + +} diff --git a/src/test/java/org/gcube/usecases/ws/thredds/TokenCheck.java b/src/test/java/org/gcube/usecases/ws/thredds/TokenCheck.java new file mode 100644 index 0000000..6a8e82f --- /dev/null +++ b/src/test/java/org/gcube/usecases/ws/thredds/TokenCheck.java @@ -0,0 +1,11 @@ +package org.gcube.usecases.ws.thredds; + +public class TokenCheck { + +// +// public static void main (String[] args) { +// System.out.println(Security.getContext("8e74a17c-92f1-405a-b591-3a6090066248-98187548")); +// System.out.println(Security.getContext("0e2c7963-8d3e-4ea6-a56d-ffda530dd0fa-98187548")); +// } +// +}