This commit is contained in:
Fabio Sinibaldi 2021-04-26 18:27:13 +02:00
parent 952965d4a1
commit a6e9347cbb
7 changed files with 122 additions and 22 deletions

View File

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

49
pom.xml
View File

@ -8,7 +8,7 @@
</parent>
<groupId>org.gcube.spatial.data</groupId>
<artifactId>ws-thredds</artifactId>
<version>0.2.4</version>
<version>0.2.5-SNAPSHOT</version>
<name>ws-thredds</name>
<description>prototype of WS integration with data-transfer for Thredds pubblication</description>
@ -41,32 +41,47 @@
<dependency>
<groupId>org.gcube.spatial.data</groupId>
<artifactId>sdi-library</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</exclusion>
</exclusions>
<version>[1.0.0-SNAPSHOT,1.3.0-SNAPSHOT)</version>
<!-- <exclusions> -->
<!-- <exclusion> -->
<!-- <groupId>com.fasterxml.jackson.core</groupId> -->
<!-- <artifactId>jackson-annotations</artifactId> -->
<!-- </exclusion> -->
<!-- </exclusions> -->
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-library</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.data.transfer</groupId>
<artifactId>data-transfer-library</artifactId>
<version>[1.2.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<!-- OLD HL -->
<!-- <dependency> <groupId>org.gcube.common</groupId> <artifactId>home-library-jcr</artifactId>
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version> </dependency> <dependency>
<groupId>org.gcube.common</groupId> <artifactId>home-library</artifactId>
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version> </dependency> -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-library</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>[2.8.4,)</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>[2.8.4,)</version>
</dependency>
<!-- JSON paths -->
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>

View File

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

View File

@ -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<String>) 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) {

View File

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

View File

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

View File

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