Resource Registry clients now follows redirects and support https. Fixes #8757

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-publisher@150484 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-06-22 15:25:14 +00:00
parent d2d65449ba
commit 62b7901b20
1 changed files with 45 additions and 3 deletions

View File

@ -1,5 +1,6 @@
package org.gcube.informationsystem.resourceregistry.publisher;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -7,16 +8,21 @@ import java.util.Random;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.resourceregistry.api.Constants;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.resources.discovery.icclient.ICFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ResourceRegistryPublisherFactory {
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryPublisherFactory.class);
protected static Map<String, ResourceRegistryPublisher> publishers;
static {
@ -34,7 +40,14 @@ public class ResourceRegistryPublisherFactory {
private static String statusFormat = "$resource/Profile/DeploymentData/Status/text() eq 'ready'";
private static String containsFormat = "$entry/@EntryName eq '%1s'";
private static SimpleQuery getQuery(){
private static String serviceEndpointCategoryFormat = "$resource/Profile/Category/text() eq '%1s'";
private static String serviceEndpointNameFormat = "$resource/Profile/Name/text() eq '%1s'";
private static String serviceEndpointstatusFormat = "$resource/Profile/RunTime/Status/text() eq 'READY'";
private static SimpleQuery queryForService(){
return ICFactory.queryFor(GCoreEndpoint.class)
.addCondition(String.format(classFormat, Constants.SERVICE_CLASS))
.addCondition(String.format(nameFormat, Constants.SERVICE_NAME))
@ -44,6 +57,35 @@ public class ResourceRegistryPublisherFactory {
.setResult("$entry/text()");
}
private static SimpleQuery queryForProxy(){
return ICFactory.queryFor(ServiceEndpoint.class)
.addCondition(String.format(serviceEndpointCategoryFormat, Constants.SERVICE_CLASS))
.addCondition(String.format(serviceEndpointNameFormat, Constants.SERVICE_NAME))
.addCondition(String.format(serviceEndpointstatusFormat))
.addVariable("$entry","$resource/Profile/AccessPoint/Interface/Endpoint")
.addCondition(String.format(containsFormat, Constants.SERVICE_ENTRY_NAME))
.setResult("$entry/text()");
}
protected static List<String> getAddresses(){
List<String> addresses = new ArrayList<>();
try {
SimpleQuery proxyQuery = queryForProxy();
addresses = ICFactory.client().submit(proxyQuery);
if(addresses==null || addresses.isEmpty()){
throw new Exception("No ResourceRegistry Proxy Found");
}
} catch (Exception e) {
logger.debug("{}. Trying to look for the Service Endpoint.", e.getMessage());
SimpleQuery serviceQuery = queryForService();
addresses = ICFactory.client().submit(serviceQuery);
}
return addresses;
}
public static ResourceRegistryPublisher create(){
if(FORCED_URL!=null){
return new ResourceRegistryPublisherImpl(FORCED_URL);
@ -63,8 +105,8 @@ public class ResourceRegistryPublisherFactory {
ResourceRegistryPublisher publisher = publishers.get(key);
if(publisher==null){
SimpleQuery query = getQuery();
List<String> addresses = ICFactory.client().submit(query);
List<String> addresses = getAddresses();
if(addresses==null || addresses.isEmpty()){
String error = String.format("No %s:%s found in the current context", Constants.SERVICE_CLASS, Constants.SERVICE_NAME);