Added use of context-utility to be ready to comply both with SG 3 and 4

This commit is contained in:
Luca Frosini 2023-02-23 12:24:11 +01:00
parent ecc108a8b7
commit 4f1734de8a
3 changed files with 9 additions and 21 deletions

View File

@ -63,6 +63,10 @@
<groupId>org.gcube.common</groupId>
<artifactId>gcube-jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-utility</artifactId>
</dependency>
<!-- Added to support Java 11 JDK -->
<dependency>

View File

@ -22,6 +22,7 @@ import javax.ws.rs.core.MediaType;
import org.gcube.common.gxhttp.reference.GXConnection.HTTPMETHOD;
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
import org.gcube.common.http.GXHTTPUtility;
import org.gcube.gcat.api.GCatConstants;
/**
@ -104,7 +105,7 @@ abstract class GCatClient {
}
protected void initRequest() throws UnsupportedEncodingException {
gxhttpStringRequest = GXHTTPStringRequest.newRequest(serviceURL.toString());
gxhttpStringRequest = GXHTTPUtility.getGXHTTPStringRequest(serviceURL.toString());
for(String name : headers.keySet()) {
gxhttpStringRequest.header(name, headers.get(name));
}

View File

@ -8,10 +8,9 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.context.ContextUtility;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.gcat.api.GCatConstants;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.resources.discovery.icclient.ICFactory;
@ -33,7 +32,7 @@ public class GCatClientDiscovery {
protected static void forceToURL(String adddress) throws MalformedURLException {
if(adddress!=null && adddress.compareTo("")!=0) {
String context = getContext();
String context = ContextUtility.getCurrentContextFullName();
URL url = new URL(adddress);
clients.put(context, url);
}
@ -88,24 +87,8 @@ public class GCatClientDiscovery {
return addresses;
}
protected static String getContext() {
String context = null;
if (SecurityTokenProvider.instance.get() == null) {
if (ScopeProvider.instance.get() == null) {
throw new RuntimeException(
"Null Token and Scope. Please set your token first.");
}
context = ScopeProvider.instance.get();
} else {
context = SecurityTokenProvider.instance.get();
}
return context;
}
public static URL getServiceURL() throws MalformedURLException {
String context = getContext();
String context = ContextUtility.getCurrentContextFullName();
URL url = clients.get(context);
if(url==null){