Feature #8494 completed

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@148667 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2017-05-15 12:45:20 +00:00
parent 040e2b9e1b
commit 62451f5516
8 changed files with 227 additions and 140 deletions

View File

@ -81,4 +81,9 @@
</Change>
<Change>[Task #7807] Provide a check for HAProxy</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.1-12-0"
date="2017-05-15">
<Change>[Feature #8494] Remove GeoServices query from URI-Resolver
</Change>
</Changeset>
</ReleaseNotes>

View File

@ -8,7 +8,7 @@
</parent>
<groupId>org.gcube.data.transfer</groupId>
<artifactId>uri-resolver</artifactId>
<version>1.11.0-SNAPSHOT</version>
<version>1.12.0-SNAPSHOT</version>
<packaging>war</packaging>
<description>The URI Resolver is an HTTP URI resolver implemented as an HTTP servlet which gives access trough HTTP to different protocols URIs. </description>

View File

@ -1,8 +1,8 @@
package org.gcube.datatransfer.resolver.gis;
import org.gcube.datatransfer.resolver.gis.entity.ServerParameters;
import org.gcube.datatransfer.resolver.gis.exception.GeonetworkInstanceException;
import org.gcube.spatial.data.geonetwork.LoginLevel;
import org.gcube.spatial.data.geonetwork.model.Account.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -22,8 +22,6 @@ public class GeonetworkAccessParameter implements GeonetworkServiceInterface{
protected String scope;
protected ServerParameters serverParam;
/**
* The Enum GeonetworkLoginLevel.
*
@ -38,15 +36,26 @@ public class GeonetworkAccessParameter implements GeonetworkServiceInterface{
ADMIN
}
/**
* Instantiates a new geonetowrk access parameter.
* The Enum AccountType.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* May 15, 2017
*/
public static enum AccountType{
CKAN,
SCOPE
}
/**
* Instantiates a new geonetwork access parameter.
*
* @param scope the scope
* @param serverParam the server param
*/
public GeonetworkAccessParameter(String scope, ServerParameters serverParam) {
public GeonetworkAccessParameter(String scope) {
this.scope = scope;
this.serverParam = serverParam;
}
@ -54,7 +63,7 @@ public class GeonetworkAccessParameter implements GeonetworkServiceInterface{
* @see org.gcube.datatransfer.resolver.gis.GeonetworkServiceInterface#getGeonetworkInstance(boolean, org.gcube.datatransfer.resolver.gis.GeonetowrkAccessParameter.GeonetworkLoginLevel)
*/
public GeonetworkInstance getGeonetworkInstance(boolean authenticate, GeonetworkLoginLevel loginLevel) throws GeonetworkInstanceException {
return instanceGeonetwork(authenticate, loginLevel);
return instanceGeonetwork(authenticate, loginLevel, null);
}
/**
@ -62,20 +71,19 @@ public class GeonetworkAccessParameter implements GeonetworkServiceInterface{
*
* @param authenticate the authenticate
* @param loginLevel the login level
* @param accType the acc type
* @return the geonetwork instance
* @throws GeonetworkInstanceException the geonetwork instance exception
*/
private GeonetworkInstance instanceGeonetwork(boolean authenticate, GeonetworkLoginLevel loginLevel) throws GeonetworkInstanceException{
private GeonetworkInstance instanceGeonetwork(boolean authenticate, GeonetworkLoginLevel loginLevel, AccountType accType) throws GeonetworkInstanceException{
if(scope == null || scope.isEmpty())
throw new GeonetworkInstanceException("Scope is null");
if(serverParam.getUrl() == null || serverParam.getUrl().isEmpty())
throw new GeonetworkInstanceException("Geonetwork url is null or empty");
LoginLevel level = toLoginLevel(loginLevel);
Type type = toType(accType);
if(geonetworkInstance==null)
geonetworkInstance = new GeonetworkInstance(scope, authenticate, level);
geonetworkInstance = new GeonetworkInstance(scope, authenticate, level, type);
return geonetworkInstance;
@ -96,7 +104,7 @@ public class GeonetworkAccessParameter implements GeonetworkServiceInterface{
throw new GeonetworkInstanceException("Geonetwork url is null or empty");*/
if(geonetworkInstance==null)
geonetworkInstance = new GeonetworkInstance(scope, false, null);
geonetworkInstance = new GeonetworkInstance(scope, false, null, null);
return geonetworkInstance;
}
@ -109,6 +117,7 @@ public class GeonetworkAccessParameter implements GeonetworkServiceInterface{
}
/**
* To login level.
*
@ -117,6 +126,10 @@ public class GeonetworkAccessParameter implements GeonetworkServiceInterface{
*/
public static final LoginLevel toLoginLevel(GeonetworkLoginLevel loginLevel){
if(loginLevel==null)
return null;
switch (loginLevel) {
case ADMIN:
return LoginLevel.ADMIN;
@ -128,8 +141,33 @@ public class GeonetworkAccessParameter implements GeonetworkServiceInterface{
return LoginLevel.PRIVATE;
case SCOPE:
return LoginLevel.SCOPE;
default:
logger.info("Returning null converting "+loginLevel+" "+LoginLevel.class.getName() +" a new level has been added?");
return null;
}
return null;
}
/**
* To type.
*
* @param accType the acc type
* @return the type
*/
private static Type toType(AccountType accType) {
if(accType==null)
return null;
switch (accType) {
case CKAN:
return Type.CKAN;
case SCOPE:
return Type.SCOPE;
default:
logger.info("Returning null converting "+accType+" "+Type.class.getName() +" a new type has been added?");
return null;
}
}
}

View File

@ -5,6 +5,9 @@ import org.gcube.datatransfer.resolver.gis.exception.GeonetworkInstanceException
import org.gcube.spatial.data.geonetwork.GeoNetwork;
import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher;
import org.gcube.spatial.data.geonetwork.LoginLevel;
import org.gcube.spatial.data.geonetwork.configuration.Configuration;
import org.gcube.spatial.data.geonetwork.model.Account;
import org.gcube.spatial.data.geonetwork.model.Account.Type;
import org.gcube.spatial.data.geonetwork.model.faults.AuthorizationException;
import org.gcube.spatial.data.geonetwork.model.faults.MissingConfigurationException;
import org.gcube.spatial.data.geonetwork.model.faults.MissingServiceEndpointException;
@ -30,6 +33,9 @@ public class GeonetworkInstance {
private Logger logger = LoggerFactory.getLogger(GeonetworkInstance.class);
private String scope;
private Account account;
private LoginLevel level;
private Type type;
/**
* Instantiates a new geonetwork instance.
@ -38,41 +44,54 @@ public class GeonetworkInstance {
* @throws GeonetworkInstanceException the geonetwork instance exception
*/
public GeonetworkInstance(String scope) throws GeonetworkInstanceException{
this(scope, false, null);
this(scope, false, null, null);
}
/**
* Creates a new configuration for Gis publisher with parameter passed in input. Executes the login on geonetwork instance if authenticate param is true, no otherwise
* Use scope found in ScopeProvider
*
* @param authenticate the authenticate
* @param level the level
* @param type the type
* @throws Exception the exception
*/
public GeonetworkInstance(boolean authenticate, LoginLevel level) throws Exception {
try {
createInstanceGeonetworkPublisher(authenticate, level);
this.level = level;
createInstanceGeonetworkPublisher(authenticate);
} catch (Exception e) {
logger.error("Sorry, an error occurred in getting geonetwork instance",e);
throw new Exception("Sorry, an error occurred in getting geonetwork instance",e);
}
}
/**
* Instantiates a new geonetwork instance.
* set the scope provider to input scope
*
* @param scope the scope
* @param authenticate the authenticate
* @param level the level
* @param type the type
* @throws GeonetworkInstanceException the geonetwork instance exception
*/
public GeonetworkInstance(String scope, boolean authenticate, LoginLevel level) throws GeonetworkInstanceException {
public GeonetworkInstance(String scope, boolean authenticate, LoginLevel level, Type type) throws GeonetworkInstanceException {
this.scope = scope;
this.level = level;
this.type = type;
String originalScope = ScopeProvider.instance.get();
logger.debug("Instancing GeonetworkInstance with scope: "+scope + ", authenticate: "+authenticate +", login level: "+level);
this.scope = scope;
try {
ScopeProvider.instance.set(scope);
logger.info("setting scope "+scope);
createInstanceGeonetworkPublisher(authenticate, level);
createInstanceGeonetworkPublisher(authenticate);
if(this.type!=null){
Configuration config = geonetworkPublisher.getConfiguration();
this.account=config.getScopeConfiguration().getAccounts().get(type);
}
//logger.info("Admin: "+config.getAdminAccount().getUser()+", Pwd: "+config.getAdminAccount().getPassword());
} catch (Exception e) {
String message = "Sorry, an error occurred in instancing geonetwork";
logger.warn(message, e);
@ -93,13 +112,14 @@ public class GeonetworkInstance {
*
* @param authenticate the authenticate
* @param level the level
* @param type the type
* @throws Exception the exception
*/
private void createInstanceGeonetworkPublisher(boolean authenticate, LoginLevel level) throws Exception {
private void createInstanceGeonetworkPublisher(boolean authenticate) throws Exception {
logger.debug("creating new geonetworkPublisher..");
this.geonetworkPublisher = GeoNetwork.get();
if(authenticate && level!=null)
authenticateOnGeoenetwork(level);
if(authenticate && this.level!=null)
authenticateOnGeoenetwork(this.level);
}
/**
@ -133,8 +153,6 @@ public class GeonetworkInstance {
}
/**
* Gets the geonetwork publisher.
*
@ -144,6 +162,13 @@ public class GeonetworkInstance {
return geonetworkPublisher;
}
/**
* @return the account
*/
public Account getAccount() {
return account;
}
/**
* Gets the scope.
@ -164,8 +189,16 @@ public class GeonetworkInstance {
StringBuilder builder = new StringBuilder();
builder.append("GeonetworkInstance [geonetworkPublisher=");
builder.append(geonetworkPublisher);
builder.append(", logger=");
builder.append(logger);
builder.append(", scope=");
builder.append(scope);
builder.append(", account=");
builder.append(account);
builder.append(", level=");
builder.append(level);
builder.append(", type=");
builder.append(type);
builder.append("]");
return builder.toString();
}

View File

@ -20,9 +20,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader;
import org.gcube.datatransfer.resolver.gis.GeoRuntimeReader.GEO_SERVICE;
import org.gcube.datatransfer.resolver.gis.GeonetworkAccessParameter.GeonetworkLoginLevel;
import org.gcube.datatransfer.resolver.gis.entity.ServerParameters;
import org.gcube.datatransfer.resolver.gis.exception.GeonetworkInstanceException;
import org.gcube.datatransfer.resolver.gis.exception.IllegalArgumentException;
import org.gcube.datatransfer.resolver.gis.property.ApplicationProfileGenericResourcePropertyReader;
@ -56,7 +54,7 @@ public class GisResolver extends HttpServlet{
/** The logger. */
private static final Logger logger = LoggerFactory.getLogger(GisResolver.class);
protected Map<String, ServerParameters> cachedServerParams; //A cache: scope - geonetwork parameters
protected Map<String, GeonetworkInstance> cachedGeonetworkInstances; //A cache: scope - geonetwork instances
protected Map<String, String> cachedGisViewerApplHostname; //A cache: scope - GisViewerApp hostname
protected Map<String, String> cachedGeoExplorerApplHostname; //A cache: scope - GisViewerApp hostname
@ -68,7 +66,7 @@ public class GisResolver extends HttpServlet{
public static final long CACHE_RESET_TIME = 30*60*1000;
//TEN MINUTES
public static final long CACHE_RESET_DELAY = 10*1000;
public static final long CACHE_RESET_DELAY = 10*60*1000;
/* (non-Javadoc)
* @see javax.servlet.GenericServlet#init()
@ -89,46 +87,66 @@ public class GisResolver extends HttpServlet{
}, CACHE_RESET_DELAY, CACHE_RESET_TIME);
}
/**
* Gets the cached server parameters.
* Gets the cached geonetwork instance.
*
* @param scope the scope
* @return the cached server parameters
* @return the cached geonetwork instance
* @throws Exception the exception
*/
protected ServerParameters getCachedServerParameters(String scope) throws Exception{
protected GeonetworkInstance getCachedGeonetworkInstance(String scope) throws Exception{
if(cachedServerParams==null)
if(cachedGeonetworkInstances==null)
reseCacheServerParameters();
logger.info("Tentative to recovering gis server param from cache to scope "+scope);
ServerParameters serverParam = cachedServerParams.get(scope);
logger.info("Attempt to get the GeonetworkInstance from cache by scope: "+scope);
GeonetworkInstance geonInstance = cachedGeonetworkInstances.get(scope);
if(serverParam==null){
logger.info("Gis server param is null, reading from application profile..");
GeoRuntimeReader reader = new GeoRuntimeReader();
if(geonInstance==null){
logger.info("GeonetworkInstance is null in cache, reading from library...");
try {
serverParam = reader.retrieveGisParameters(scope, GEO_SERVICE.GEONETWORK);
cachedServerParams.put(scope, serverParam);
logger.info("Updated Gis server cache! Scope "+scope+" linking "+serverParam);
geonInstance = discoveryGeonetworkInstance(scope);
cachedGeonetworkInstances.put(scope, geonInstance);
logger.info("Updated GeonetworkInstance cache! Scope "+scope+" linking "+geonInstance);
} catch (Exception e) {
logger.error("An error occurred on reading application profile to "+GEO_SERVICE.GEONETWORK, e);
throw new Exception("Sorry, An error occurred on reading configuration to "+GEO_SERVICE.GEONETWORK);
logger.error("An error occurred on getting GeonetworkInstance for scope: "+scope, e);
throw new Exception("Sorry, An error occurred on getting GeonetworkInstance for scope: "+scope);
}
}else
logger.info("Cache gis server param is not null using it");
logger.info("GeonetworkInstance is not null using it");
logger.info("returning geonetworkParams "+serverParam);
logger.info("returning GeonetworkInstance: "+geonInstance);
return serverParam;
return geonInstance;
}
/**
* Discovery geonetwork instance.
*
* @param scope the scope
* @return the geonetwork instance
* @throws GeonetworkInstanceException the geonetwork instance exception
*/
private GeonetworkInstance discoveryGeonetworkInstance(String scope) throws GeonetworkInstanceException{
GeonetworkAccessParameter gntwAccess = new GeonetworkAccessParameter(scope);
if(cachedGeonetworkInstances==null)
reseCacheServerParameters();
return gntwAccess.getGeonetworkInstance(true, GeonetworkLoginLevel.ADMIN);
}
/**
* Rese cache server parameters.
*/
private void reseCacheServerParameters(){
cachedServerParams = new HashMap<String, ServerParameters>();
logger.info("Cache server params reset!");
cachedGeonetworkInstances = new HashMap<String, GeonetworkInstance>();
logger.info("Cache of GeonetworkInstances reset!");
}
/**
@ -136,7 +154,7 @@ public class GisResolver extends HttpServlet{
*/
private void reseCacheGisViewerApplicationHostname(){
cachedGisViewerApplHostname = new HashMap<String, String>();
logger.info("Cache Gis Viewer Hostname reset!");
logger.info("Cache of Gis Viewer Hostname reset!");
}
/**
@ -144,7 +162,7 @@ public class GisResolver extends HttpServlet{
*/
private void reseCacheGeoExplorerApplicationHostname() {
cachedGeoExplorerApplHostname = new HashMap<String, String>();
logger.info("Cache Geo Explorer Hostname reset!");
logger.info("Cache of Geo Explorer Hostname reset!");
}
/**
@ -283,9 +301,10 @@ public class GisResolver extends HttpServlet{
try {
if(isGisLink){
ScopeProvider.instance.set(scope);
ServerParameters geonetworkParams = getCachedServerParameters(scope);
String wmsRequest = getLayerWmsRequest(scope, gisUUID, geonetworkParams);
//ScopeProvider.instance.set(scope);
//ServerParameters geonetworkParams = getCachedServerParameters(scope);
String wmsRequest = getLayerWmsRequest(scope, gisUUID);
logger.info("wms url is: " + wmsRequest);
wmsRequest = URLEncoder.encode(wmsRequest, UTF_8);
logger.info("encoded WMS url is: " + wmsRequest);
@ -366,20 +385,20 @@ public class GisResolver extends HttpServlet{
return wmsRequest+"&"+PARAM_SEPARATOR_REPLACEMENT_KEY+"="+PARAM_SEPARATOR_REPLACEMENT_VALUE;
}
/**
* Gets the layer wms request.
*
* @param scope the scope
* @param gisUUID the gis uuid
* @param geonetworkParams the geonetwork params
* @return the layer wms request
* @throws Exception the exception
*/
protected String getLayerWmsRequest(String scope, String gisUUID, ServerParameters geonetworkParams) throws Exception{
protected String getLayerWmsRequest(String scope, String gisUUID) throws Exception{
try {
GeonetworkServiceInterface gntwAccess = new GeonetworkAccessParameter(scope, geonetworkParams);
return MetadataConverter.getWMSOnLineResource(gntwAccess.getGeonetworkInstance(true, GeonetworkLoginLevel.ADMIN), gisUUID);
GeonetworkInstance gi = getCachedGeonetworkInstance(scope);
return MetadataConverter.getWMSOnLineResource(gi, gisUUID);
}catch (GeonetworkInstanceException e){
logger.error("An error occurred when instancing geonetowrk gis layer with UUID "+gisUUID, e);
throw new IllegalArgumentException("Sorry, An error occurred when instancing geonetwork with UUID: "+gisUUID);
@ -389,6 +408,7 @@ public class GisResolver extends HttpServlet{
}
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@ -397,6 +417,7 @@ public class GisResolver extends HttpServlet{
this.doGet(req, resp);
}
/**
* Send error.
*
@ -405,16 +426,12 @@ public class GisResolver extends HttpServlet{
* @param message the message
* @throws IOException Signals that an I/O exception has occurred.
*/
protected void sendError(HttpServletResponse response, int status, String message) throws IOException
{
// response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
protected void sendError(HttpServletResponse response, int status, String message) throws IOException{
response.setStatus(status);
logger.info("error message: "+message);
logger.info("writing response...");
StringReader sr = new StringReader(message);
IOUtils.copy(sr, response.getOutputStream());
// response.getWriter().write(resultMessage.toString());
logger.info("response writed");
response.flushBuffer();
}
@ -431,6 +448,7 @@ public class GisResolver extends HttpServlet{
response.sendRedirect(response.encodeRedirectURL(redirectTo));
}
/**
* Gets the request url.
*
@ -443,11 +461,6 @@ public class GisResolver extends HttpServlet{
String serverName = req.getServerName(); // hostname.com
int serverPort = req.getServerPort(); // 80
String contextPath = req.getContextPath(); // /mywebapp
// String servletPath = req.getServletPath(); // /servlet/MyServlet
// String pathInfo = req.getPathInfo(); // /a/b;c=123
// String queryString = req.getQueryString(); // d=789
// Reconstruct original requesting URL
StringBuffer url = new StringBuffer();
url.append(scheme).append("://").append(serverName);
@ -460,39 +473,39 @@ public class GisResolver extends HttpServlet{
return url.toString();
}
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
GisResolver gisResolver = new GisResolver();
String scope = "/gcube/devsec/devVRE";
String UUID = "177e1c3c-4a22-4ad9-b015-bfc443d16cb8";
try {
// ScopeProvider.instance.set(scope);
// ServerParameters geonetworkParams = gisResolver.getCachedServerParameters(scope);
// String wmsRequest = gisResolver.getLayerWmsRequest(scope, UUID, geonetworkParams);
// logger.info("Final url is: " + wmsRequest);
// wmsRequest = URLEncoder.encode(wmsRequest, UTF_8);
// logger.info("Encoded WMS request is: " + wmsRequest);
// String gisPortletUrl = gisResolver.getGisViewerApplicationURL(scope);
// logger.info("Gis Viewer Application url is: " + gisPortletUrl);
//// logger.info("WmsRequest is: " + wmsRequest);
//// wmsRequest = encodeURLWithParamDelimiter(wmsRequest);
//// logger.info("Encoded url is: " + wmsRequest);
//// wmsRequest = appendParamReplacement(wmsRequest);
// gisPortletUrl+="?wmsrequest="+wmsRequest;
// /**
// * The main method.
// *
// * @param args the arguments
// */
// public static void main(String[] args) {
// GisResolver gisResolver = new GisResolver();
// String scope = "/gcube/devsec/devVRE";
// String UUID = "177e1c3c-4a22-4ad9-b015-bfc443d16cb8";
// try {
//// ScopeProvider.instance.set(scope);
//// ServerParameters geonetworkParams = gisResolver.getCachedServerParameters(scope);
//// String wmsRequest = gisResolver.getLayerWmsRequest(scope, UUID, geonetworkParams);
//// logger.info("Final url is: " + wmsRequest);
//// wmsRequest = URLEncoder.encode(wmsRequest, UTF_8);
//// logger.info("Encoded WMS request is: " + wmsRequest);
//// String gisPortletUrl = gisResolver.getGisViewerApplicationURL(scope);
//// logger.info("Gis Viewer Application url is: " + gisPortletUrl);
////// logger.info("WmsRequest is: " + wmsRequest);
////// wmsRequest = encodeURLWithParamDelimiter(wmsRequest);
////// logger.info("Encoded url is: " + wmsRequest);
////// wmsRequest = appendParamReplacement(wmsRequest);
//// gisPortletUrl+="?wmsrequest="+wmsRequest;
////
//// System.out.println(gisPortletUrl);
//// urlRedirect(req, resp, gisPortletUrl);
//
// System.out.println(gisPortletUrl);
// urlRedirect(req, resp, gisPortletUrl);
ScopeProvider.instance.set(scope);
String geoExplorerURL = gisResolver.getGeoExplorerApplicationURL(scope);
logger.info("GeoExplorer url is: " + geoExplorerURL);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// ScopeProvider.instance.set(scope);
// String geoExplorerURL = gisResolver.getGeoExplorerApplicationURL(scope);
// logger.info("GeoExplorer url is: " + geoExplorerURL);
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
}

View File

@ -11,19 +11,20 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class MetadataConverter.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jan 7, 2016
* May 15, 2017
*/
public class MetadataConverter {
private static final String GEOSERVER = "/geoserver";
protected static final String SERVICE_WMS = "service=wms";
protected static Logger logger = LoggerFactory.getLogger(MetadataConverter.class);
public static final String NOT_FOUND = "";
/**
* Gets the geoserver base uri.
*
@ -32,42 +33,42 @@ public class MetadataConverter {
* geoserver url otherwise
*/
public static GeoserverBaseUri getGeoserverBaseUri(String uri){
GeoserverBaseUri geoserverBaseUri = new GeoserverBaseUri();
if(uri==null)
return geoserverBaseUri; //uri is empty
// Remove each string after "?"
int end = uri.toLowerCase().lastIndexOf("?");
if(end==-1){
logger.trace("char ? not found in geoserver uri, return: "+uri);
return geoserverBaseUri; //uri is empty
}
String geoserverUrl = uri.substring(0, uri.toLowerCase().lastIndexOf("?"));
int index = geoserverUrl.lastIndexOf(GEOSERVER);
if(index>-1){ //FOUND the string GEOSERVER into URL
logger.trace("found geoserver string: "+GEOSERVER+" in "+geoserverUrl);
//THERE IS SCOPE?
int lastSlash = geoserverUrl.lastIndexOf("/");
int includeGeoserverString = index+GEOSERVER.length();
int endUrl = lastSlash>includeGeoserverString?lastSlash:includeGeoserverString;
logger.trace("indexs - lastSlash: ["+lastSlash+"], includeGeoserverString: ["+includeGeoserverString+"], endUrl: ["+endUrl+"]");
int startScope = includeGeoserverString+1<endUrl?includeGeoserverString+1:endUrl; //INCLUDE SLASH
String scope = geoserverUrl.substring(startScope, endUrl);
logger.trace("geoserver url include scope: "+geoserverUrl.substring(includeGeoserverString, endUrl));
geoserverBaseUri.setBaseUrl(geoserverUrl.substring(0, endUrl));
geoserverBaseUri.setScope(scope);
return geoserverBaseUri;
}
else{
@ -76,9 +77,9 @@ public class MetadataConverter {
// GET LAST INDEX OF '/' AND CONCATENATE GEOSERVER
String urlConn = geoserverUrl.substring(0, geoserverUrl.lastIndexOf("/"))+GEOSERVER;
logger.trace("tentative concatenating string 'geoserver' at http url "+urlConn);
try {
try {
if(HttpRequestUtil.urlExists(urlConn, false)){
logger.trace("url: "+urlConn+" - open a connection, return "+urlConn);
geoserverBaseUri.setBaseUrl(urlConn);
@ -97,7 +98,8 @@ public class MetadataConverter {
return geoserverBaseUri;
}
}
/**
* Gets the WMS on line resource.
*
@ -107,32 +109,28 @@ public class MetadataConverter {
* @throws Exception the exception
*/
public static String getWMSOnLineResource(GeonetworkInstance geonetowrkInstance, String uuid) throws Exception{
String fullWmsPath = "";
boolean foundGeoserverUrl = false;
String layerName = "";
// boolean isOwsService = false;
// GeoserverBaseUri tempBaseUri = null;
//GEOSERVER URL
// String geoserverBaseUrlOnlineResource = "";
try{
logger.trace("geonetowrkInstance is null? "+(geonetowrkInstance==null));
Metadata meta = geonetowrkInstance.getGeonetworkPublisher().getById(uuid);
if(meta.getDistributionInfo()!=null && meta.getDistributionInfo()!=null){
for (DigitalTransferOptions item: meta.getDistributionInfo().getTransferOptions()) {
// System.out.println(++i +" item DigitalTransferOptions options: "+item);
if(item.getOnLines()!=null){
Collection<? extends OnlineResource> onlineResources = item.getOnLines();
for (OnlineResource onlineResource : onlineResources) {
String geoserverUrl = onlineResource.getLinkage()!=null? onlineResource.getLinkage().toString():"";
//FIND ONLINE RESOURCES WITH GEOSERVER WMS PROTOCOL
if(!geoserverUrl.isEmpty()){
int indexServiceWMS = geoserverUrl.toLowerCase().lastIndexOf(SERVICE_WMS);
fullWmsPath = geoserverUrl;
@ -154,7 +152,7 @@ public class MetadataConverter {
}
break;
}
if(!foundGeoserverUrl)
logger.trace(SERVICE_WMS+" not found for "+uuid);
}
@ -169,13 +167,13 @@ public class MetadataConverter {
logger.trace("returning: "+fullWmsPath);
return fullWmsPath;
}
/*
public static void main(String[] args) throws Exception {
// String geoserver = "http://www.fao.org/figis/a/wms/?service=WMS&version=1.1.0&request=GetMap&layers=area:FAO_AREAS&styles=Species_prob, puppa&bbox=-180.0,-88.0,180.0,90.0000000694&width=667&height=330&srs=EPSG:4326&format=image%2Fpng";
// String geoserver = "http://www.fao.org/figis/a/wms/?service=WMS&version=1.1.0&request=GetMap&layers=area:FAO_AREAS&styles=Species_prob, puppa&bbox=-180.0,-88.0,180.0,90.0000000694&width=667&height=330&srs=EPSG:4326&format=image%2Fpng";
// System.out.println(MetadataConverter.getGeoserverBaseUri(geoserver));
String user ="admin";
String pwd = "admin";
boolean authenticate = true;

View File

@ -135,7 +135,7 @@ public class GeonetworkResolver extends HttpServlet{
try {
// ServerParameters geonetworkParams = getGeonetworkCachedServerParameters(scopeValue);
GeonetworkServiceInterface gntwAccess = new GeonetworkAccessParameter(scopeValue, null);
GeonetworkServiceInterface gntwAccess = new GeonetworkAccessParameter(scopeValue);
GeonetworkInstance gnInstance = gntwAccess.getGeonetworkInstance();
HTTPCallsUtils httpUtils = new HTTPCallsUtils();
Configuration config = gnInstance.getGeonetworkPublisher().getConfiguration();
@ -286,7 +286,7 @@ public class GeonetworkResolver extends HttpServlet{
try {
GeonetworkServiceInterface gntwAccess = new GeonetworkAccessParameter(scope, null);
GeonetworkServiceInterface gntwAccess = new GeonetworkAccessParameter(scope);
GeonetworkInstance gnInstance = gntwAccess.getGeonetworkInstance();
ScopeProvider.instance.set(scope);

View File

@ -23,7 +23,7 @@ public class GeonetworkQueryTest {
//private String[] scopes = {"/gcube/devNext/NextNext"};
private String[] scopesProd = {"/d4science.research-infrastructures.eu"};
private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/SIASPA"};
//private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/fisheriesandecosystematmii"};