4953: Uri Resolver: remove jumps of scope from Readers (for Generic and Runtime resource)
Task-Url: https://support.d4science.org/issues/4953 All jumps has been removed When is need to set scope in order to discovery a certain resource in a specific scope in the end the original scope is restored git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@131174 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
406af9e14d
commit
e082f323c7
|
@ -11,18 +11,18 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
import org.gcube.resources.discovery.client.queries.api.Query;
|
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||||
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The Class ApplicationProfileReader.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
* @Oct 13, 2014
|
* Sep 6, 2016
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ApplicationProfileReader {
|
public class ApplicationProfileReader {
|
||||||
|
|
||||||
|
@ -42,9 +42,10 @@ public class ApplicationProfileReader {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Instantiates a new application profile reader.
|
||||||
*
|
*
|
||||||
* @param scope - the scope to be searched
|
* @param scope - the scope to be searched
|
||||||
* @param genericResource - the name of generic resource
|
* @param secondaryType the secondary type
|
||||||
* @param portletClassName - the AppId of generic resource
|
* @param portletClassName - the AppId of generic resource
|
||||||
*/
|
*/
|
||||||
public ApplicationProfileReader(String scope, String secondaryType, String portletClassName) {
|
public ApplicationProfileReader(String scope, String secondaryType, String portletClassName) {
|
||||||
|
@ -54,13 +55,18 @@ public class ApplicationProfileReader {
|
||||||
this.applicationProfile = readProfileFromInfrastrucure();
|
this.applicationProfile = readProfileFromInfrastrucure();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the application profile.
|
||||||
|
*
|
||||||
|
* @return the application profile
|
||||||
|
*/
|
||||||
public ApplicationProfile getApplicationProfile() {
|
public ApplicationProfile getApplicationProfile() {
|
||||||
return applicationProfile;
|
return applicationProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this method looks up the applicationProfile profile among the ones available in the infrastructure
|
* this method looks up the applicationProfile profile among the ones available in the infrastructure.
|
||||||
* @param portletClassName your servlet class name will be used ad unique identifier for your applicationProfile
|
*
|
||||||
* @return the applicationProfile profile
|
* @return the applicationProfile profile
|
||||||
*/
|
*/
|
||||||
private ApplicationProfile readProfileFromInfrastrucure() {
|
private ApplicationProfile readProfileFromInfrastrucure() {
|
||||||
|
@ -68,21 +74,16 @@ public class ApplicationProfileReader {
|
||||||
ApplicationProfile appProf = new ApplicationProfile();
|
ApplicationProfile appProf = new ApplicationProfile();
|
||||||
String queryString = GcubeQuery.getGcubeGenericQueryString(secondaryType, appId);
|
String queryString = GcubeQuery.getGcubeGenericQueryString(secondaryType, appId);
|
||||||
|
|
||||||
logger.info("Trying to fetch applicationProfile profile from the infrastructure for " + secondaryType + " scope: " + scope);
|
logger.info("Trying to fetch ApplicationProfile in the scope: "+scope+", SecondaryType: " + secondaryType + ", AppId: " + appId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String infra = ScopeUtil.getInfrastructureNameFromScope(this.scope);
|
|
||||||
ScopeProvider.instance.set(infra);
|
|
||||||
logger.info("scope provider set instance: "+infra);
|
|
||||||
|
|
||||||
Query q = new QueryBox(queryString);
|
Query q = new QueryBox(queryString);
|
||||||
|
|
||||||
DiscoveryClient<String> client = client();
|
DiscoveryClient<String> client = client();
|
||||||
List<String> appProfile = client.submit(q);
|
List<String> appProfile = client.submit(q);
|
||||||
|
|
||||||
if (appProfile == null || appProfile.size() == 0)
|
if (appProfile == null || appProfile.size() == 0)
|
||||||
throw new ApplicationProfileNotFoundException("Your applicationProfile is not registered in the infrastructure");
|
throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType + ", AppId: " + appId +" is not registered in the scope: "+scope);
|
||||||
else {
|
else {
|
||||||
String elem = appProfile.get(0);
|
String elem = appProfile.get(0);
|
||||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||||
|
@ -116,7 +117,6 @@ public class ApplicationProfileReader {
|
||||||
logger.warn("Null or empty <ThumbnailURL> element in <Body>" + appProf.getName());
|
logger.warn("Null or empty <ThumbnailURL> element in <Body>" + appProf.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
currValue = helper.evaluate("/Resource/Profile/Body/EndPoint[Scope='"+scope.toString()+"']/Scope/text()");
|
currValue = helper.evaluate("/Resource/Profile/Body/EndPoint[Scope='"+scope.toString()+"']/Scope/text()");
|
||||||
|
|
||||||
if (currValue != null && currValue.size() > 0) {
|
if (currValue != null && currValue.size() > 0) {
|
||||||
|
@ -168,13 +168,13 @@ public class ApplicationProfileReader {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Error while trying to fetch applicationProfile profile from the infrastructure", e);
|
logger.error("Error while trying to fetch applicationProfile profile from the infrastructure", e);
|
||||||
return null;
|
return null;
|
||||||
}finally{
|
|
||||||
logger.info("Resetting scope provider...");
|
|
||||||
ScopeProvider.instance.reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Object#toString()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
|
@ -17,27 +17,27 @@ public class ScopeUtil {
|
||||||
public static final Logger logger = LoggerFactory.getLogger(ScopeUtil.class);
|
public static final Logger logger = LoggerFactory.getLogger(ScopeUtil.class);
|
||||||
|
|
||||||
|
|
||||||
public static String getInfrastructureNameFromScope(String scope) throws Exception{
|
// public static String getInfrastructureNameFromScope(String scope) throws Exception{
|
||||||
|
//
|
||||||
if(scope==null || scope.isEmpty()){
|
// if(scope==null || scope.isEmpty()){
|
||||||
throw new Exception("Scope is null or empty");
|
// throw new Exception("Scope is null or empty");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if(!scope.startsWith(SCOPE_SEPARATOR)){
|
// if(!scope.startsWith(SCOPE_SEPARATOR)){
|
||||||
logger.warn("Input scope: "+scope+" not have / is a really scope?");
|
// logger.warn("Input scope: "+scope+" not have / is a really scope?");
|
||||||
scope = SCOPE_SEPARATOR+scope;
|
// scope = SCOPE_SEPARATOR+scope;
|
||||||
logger.warn("Tentative as scope: "+scope);
|
// logger.warn("Tentative as scope: "+scope);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
String[] splitScope = scope.split(SCOPE_SEPARATOR);
|
// String[] splitScope = scope.split(SCOPE_SEPARATOR);
|
||||||
|
//
|
||||||
String rootScope = SCOPE_SEPARATOR + splitScope[1];
|
// String rootScope = SCOPE_SEPARATOR + splitScope[1];
|
||||||
|
//
|
||||||
if(rootScope.length()<2){
|
// if(rootScope.length()<2){
|
||||||
throw new Exception("Infrastructure name not found in "+scope);
|
// throw new Exception("Infrastructure name not found in "+scope);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return rootScope;
|
// return rootScope;
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,13 +40,15 @@ public class GeoRuntimeReader {
|
||||||
{
|
{
|
||||||
|
|
||||||
ServerParameters parameters = new ServerParameters();
|
ServerParameters parameters = new ServerParameters();
|
||||||
|
String originalScope = null;
|
||||||
try{
|
try{
|
||||||
|
|
||||||
boolean isGeoserver = geoservice.equals(GEO_SERVICE.GEOSERVER);
|
boolean isGeoserver = geoservice.equals(GEO_SERVICE.GEOSERVER);
|
||||||
|
|
||||||
String resourceName = isGeoserver ? GEOSERVER_RESOURCE_NAME : GEONETWORK_RESOURCE_NAME;
|
String resourceName = isGeoserver ? GEOSERVER_RESOURCE_NAME : GEONETWORK_RESOURCE_NAME;
|
||||||
|
|
||||||
|
originalScope = ScopeProvider.instance.get();
|
||||||
|
|
||||||
ScopeProvider.instance.set(scope);
|
ScopeProvider.instance.set(scope);
|
||||||
|
|
||||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||||
|
@ -91,8 +93,13 @@ public class GeoRuntimeReader {
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
logger.error("Sorry, an error occurred on reading parameters in Runtime Resources",e);
|
logger.error("Sorry, an error occurred on reading parameters in Runtime Resources",e);
|
||||||
}finally{
|
}finally{
|
||||||
logger.info("Resetting scope provider...");
|
if(originalScope!=null && !originalScope.isEmpty()){
|
||||||
|
ScopeProvider.instance.set(originalScope);
|
||||||
|
logger.info("scope provider setted to orginal scope: "+originalScope);
|
||||||
|
}else{
|
||||||
ScopeProvider.instance.reset();
|
ScopeProvider.instance.reset();
|
||||||
|
logger.info("scope provider reset");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return parameters;
|
return parameters;
|
||||||
|
|
|
@ -68,7 +68,9 @@ public class GeonetworkInstance {
|
||||||
public GeonetworkInstance(String scope, boolean authenticate, LoginLevel level) throws GeonetworkInstanceException {
|
public GeonetworkInstance(String scope, boolean authenticate, LoginLevel level) throws GeonetworkInstanceException {
|
||||||
logger.debug("Instancing GeonetworkInstance with scope: "+scope + ", authenticate: "+authenticate +", login level: "+level);
|
logger.debug("Instancing GeonetworkInstance with scope: "+scope + ", authenticate: "+authenticate +", login level: "+level);
|
||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
|
String originalScope = null;
|
||||||
try {
|
try {
|
||||||
|
originalScope = ScopeProvider.instance.get();
|
||||||
ScopeProvider.instance.set(scope);
|
ScopeProvider.instance.set(scope);
|
||||||
logger.info("setting scope "+scope);
|
logger.info("setting scope "+scope);
|
||||||
createInstanceGeonetworkPublisher(authenticate, level);
|
createInstanceGeonetworkPublisher(authenticate, level);
|
||||||
|
@ -77,8 +79,13 @@ public class GeonetworkInstance {
|
||||||
logger.warn(message, e);
|
logger.warn(message, e);
|
||||||
throw new GeonetworkInstanceException(message);
|
throw new GeonetworkInstanceException(message);
|
||||||
}finally{
|
}finally{
|
||||||
logger.info("resetting scope");
|
if(originalScope!=null && !originalScope.isEmpty()){
|
||||||
|
ScopeProvider.instance.set(originalScope);
|
||||||
|
logger.info("scope provider setted to orginal scope: "+originalScope);
|
||||||
|
}else{
|
||||||
ScopeProvider.instance.reset();
|
ScopeProvider.instance.reset();
|
||||||
|
logger.info("scope provider reset");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader;
|
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader;
|
||||||
import org.gcube.datatransfer.resolver.applicationprofile.ScopeUtil;
|
|
||||||
import org.gcube.datatransfer.resolver.gis.GeoRuntimeReader.GEO_SERVICE;
|
import org.gcube.datatransfer.resolver.gis.GeoRuntimeReader.GEO_SERVICE;
|
||||||
import org.gcube.datatransfer.resolver.gis.GeonetworkAccessParameter.GeonetworkLoginLevel;
|
import org.gcube.datatransfer.resolver.gis.GeonetworkAccessParameter.GeonetworkLoginLevel;
|
||||||
import org.gcube.datatransfer.resolver.gis.entity.ServerParameters;
|
import org.gcube.datatransfer.resolver.gis.entity.ServerParameters;
|
||||||
|
@ -155,17 +154,16 @@ public class GisResolver extends HttpServlet{
|
||||||
if(cachedGisViewerApplHostname==null)
|
if(cachedGisViewerApplHostname==null)
|
||||||
reseCacheGisViewerApplicationHostname();
|
reseCacheGisViewerApplicationHostname();
|
||||||
|
|
||||||
String infra = ScopeUtil.getInfrastructureNameFromScope(scope);
|
|
||||||
logger.info("Tentative of recovering gis viewer application hostname from cache for scope: "+scope);
|
logger.info("Tentative of recovering gis viewer application hostname from cache for scope: "+scope);
|
||||||
String gisViewerAppHostname = cachedGisViewerApplHostname.get(infra);
|
String gisViewerAppHostname = cachedGisViewerApplHostname.get(scope);
|
||||||
if(gisViewerAppHostname==null){
|
if(gisViewerAppHostname==null){
|
||||||
logger.info("Gis viewer application hostname is null, reading from application profile..");
|
logger.info("Gis viewer application hostname is null, reading from application profile..");
|
||||||
if(gisViewerAppPropertyReader==null)
|
if(gisViewerAppPropertyReader==null)
|
||||||
resetGisViewerAppEndPoint();
|
resetGisViewerAppEndPoint();
|
||||||
|
|
||||||
ApplicationProfileReader reader = new ApplicationProfileReader(infra, gisViewerAppPropertyReader.getGenericResource(), gisViewerAppPropertyReader.getAppId());
|
ApplicationProfileReader reader = new ApplicationProfileReader(scope, gisViewerAppPropertyReader.getGenericResource(), gisViewerAppPropertyReader.getAppId());
|
||||||
String url = reader.getApplicationProfile().getUrl();
|
String url = reader.getApplicationProfile().getUrl();
|
||||||
cachedGisViewerApplHostname.put(infra, url);
|
cachedGisViewerApplHostname.put(scope, url);
|
||||||
logger.info("Updated GisViewerApplication cache! Scope "+scope+" linking "+url);
|
logger.info("Updated GisViewerApplication cache! Scope "+scope+" linking "+url);
|
||||||
return url;
|
return url;
|
||||||
}else
|
}else
|
||||||
|
@ -363,7 +361,7 @@ public class GisResolver extends HttpServlet{
|
||||||
logger.trace("omitted contextPath: "+contextPath);
|
logger.trace("omitted contextPath: "+contextPath);
|
||||||
return url.toString();
|
return url.toString();
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
GisResolver gisResolver = new GisResolver();
|
GisResolver gisResolver = new GisResolver();
|
||||||
String scope = "/gcube/devsec/devVRE";
|
String scope = "/gcube/devsec/devVRE";
|
||||||
|
@ -388,5 +386,5 @@ public class GisResolver extends HttpServlet{
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ import org.gcube.datatransfer.resolver.gis.GeonetworkInstance;
|
||||||
import org.gcube.datatransfer.resolver.gis.GeonetworkServiceInterface;
|
import org.gcube.datatransfer.resolver.gis.GeonetworkServiceInterface;
|
||||||
import org.gcube.datatransfer.resolver.gis.entity.ServerParameters;
|
import org.gcube.datatransfer.resolver.gis.entity.ServerParameters;
|
||||||
import org.gcube.datatransfer.resolver.gis.exception.IllegalArgumentException;
|
import org.gcube.datatransfer.resolver.gis.exception.IllegalArgumentException;
|
||||||
|
import org.gcube.datatransfer.resolver.gis.geonetwork.HTTPCallsUtils.HttpResponse;
|
||||||
import org.gcube.datatransfer.resolver.gis.util.GetResponseRecordFilter;
|
import org.gcube.datatransfer.resolver.gis.util.GetResponseRecordFilter;
|
||||||
import org.gcube.spatial.data.geonetwork.configuration.Configuration;
|
import org.gcube.spatial.data.geonetwork.configuration.Configuration;
|
||||||
import org.gcube.spatial.data.geonetwork.model.Account;
|
import org.gcube.spatial.data.geonetwork.model.Account;
|
||||||
|
@ -153,10 +154,14 @@ public class GeonetworkResolver extends HttpServlet{
|
||||||
logger.trace("Purged query string from "+remainValue+" is: "+newQueryString);
|
logger.trace("Purged query string from "+remainValue+" is: "+newQueryString);
|
||||||
String gnGetlURL = newQueryString==null || newQueryString.isEmpty()? baseURL : baseURL+"?"+newQueryString;
|
String gnGetlURL = newQueryString==null || newQueryString.isEmpty()? baseURL : baseURL+"?"+newQueryString;
|
||||||
logger.info("Sending get request to URL: "+gnGetlURL);
|
logger.info("Sending get request to URL: "+gnGetlURL);
|
||||||
String response = httpUtils.get(gnGetlURL);
|
HttpResponse response = httpUtils.get(gnGetlURL);
|
||||||
|
|
||||||
|
switch(response.getStatus()){
|
||||||
|
case HttpServletResponse.SC_OK:
|
||||||
|
|
||||||
logger.info("Response return Content-Type: "+httpUtils.getLastContentType());
|
logger.info("Response return Content-Type: "+httpUtils.getLastContentType());
|
||||||
resp.setContentType(httpUtils.getLastContentType());
|
resp.setContentType(httpUtils.getLastContentType());
|
||||||
InputStream in = IOUtils.toInputStream(response);
|
InputStream in = IOUtils.toInputStream(response.getResponse());
|
||||||
OutputStream out = resp.getOutputStream();
|
OutputStream out = resp.getOutputStream();
|
||||||
try{
|
try{
|
||||||
int bytes = IOUtils.copy(in, out);
|
int bytes = IOUtils.copy(in, out);
|
||||||
|
@ -168,6 +173,17 @@ public class GeonetworkResolver extends HttpServlet{
|
||||||
IOUtils.closeQuietly(in);
|
IOUtils.closeQuietly(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HttpServletResponse.SC_FORBIDDEN:
|
||||||
|
|
||||||
|
sendError(resp, response.getStatus(), "Sorry, you are not authorized to perform this request");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
sendError(resp, response.getStatus(), "Sorry, an error occurred on resolving geonetwork request with scope "+scopeValue);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (IllegalArgumentException e){
|
} catch (IllegalArgumentException e){
|
||||||
logger.error("IllegalArgumentException:", e);
|
logger.error("IllegalArgumentException:", e);
|
||||||
sendError(resp, HttpServletResponse.SC_BAD_REQUEST, "Illegal argument to carry out the request!");
|
sendError(resp, HttpServletResponse.SC_BAD_REQUEST, "Illegal argument to carry out the request!");
|
||||||
|
@ -252,6 +268,7 @@ public class GeonetworkResolver extends HttpServlet{
|
||||||
String noAuthentication = req.getParameter(PARAMETER_NO_AUTHENTICATION);
|
String noAuthentication = req.getParameter(PARAMETER_NO_AUTHENTICATION);
|
||||||
boolean filterPublicMetadataIDsB = false;
|
boolean filterPublicMetadataIDsB = false;
|
||||||
boolean noAuthenticationB = false;
|
boolean noAuthenticationB = false;
|
||||||
|
String originalScope = null;
|
||||||
|
|
||||||
if (scope == null || scope.equals("")) {
|
if (scope == null || scope.equals("")) {
|
||||||
logger.debug("Scope not found");
|
logger.debug("Scope not found");
|
||||||
|
@ -279,6 +296,8 @@ public class GeonetworkResolver extends HttpServlet{
|
||||||
GeonetworkServiceInterface gntwAccess = new GeonetworkAccessParameter(scope, null);
|
GeonetworkServiceInterface gntwAccess = new GeonetworkAccessParameter(scope, null);
|
||||||
GeonetworkInstance gnInstance = gntwAccess.getGeonetworkInstance();
|
GeonetworkInstance gnInstance = gntwAccess.getGeonetworkInstance();
|
||||||
|
|
||||||
|
originalScope = ScopeProvider.instance.get();
|
||||||
|
|
||||||
ScopeProvider.instance.set(scope);
|
ScopeProvider.instance.set(scope);
|
||||||
logger.info("set scope provider "+scope);
|
logger.info("set scope provider "+scope);
|
||||||
Configuration config = gnInstance.getGeonetworkPublisher().getConfiguration();
|
Configuration config = gnInstance.getGeonetworkPublisher().getConfiguration();
|
||||||
|
@ -380,10 +399,15 @@ public class GeonetworkResolver extends HttpServlet{
|
||||||
sendError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, error);
|
sendError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, error);
|
||||||
return;
|
return;
|
||||||
}finally{
|
}finally{
|
||||||
|
if(originalScope!=null && !originalScope.isEmpty()){
|
||||||
|
ScopeProvider.instance.set(originalScope);
|
||||||
|
logger.info("scope provider setted to orginal scope: "+originalScope);
|
||||||
|
}else{
|
||||||
ScopeProvider.instance.reset();
|
ScopeProvider.instance.reset();
|
||||||
logger.info("scope provider reset");
|
logger.info("scope provider reset");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the geonetwork cached server parameters.
|
* Gets the geonetwork cached server parameters.
|
||||||
|
|
|
@ -130,7 +130,7 @@ public class HTTPCallsUtils {
|
||||||
* @return The HTTP response as a String if the HTTP response code was 200 (OK).
|
* @return The HTTP response as a String if the HTTP response code was 200 (OK).
|
||||||
* @throws MalformedURLException the malformed url exception
|
* @throws MalformedURLException the malformed url exception
|
||||||
*/
|
*/
|
||||||
public String get(String url) throws MalformedURLException {
|
public HttpResponse get(String url) throws MalformedURLException {
|
||||||
|
|
||||||
GetMethod httpMethod = null;
|
GetMethod httpMethod = null;
|
||||||
try {
|
try {
|
||||||
|
@ -146,7 +146,7 @@ public class HTTPCallsUtils {
|
||||||
logger.warn("ResponseBody is empty");
|
logger.warn("ResponseBody is empty");
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return response;
|
return new HttpResponse(HttpStatus.SC_OK, response);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.info("("+lastHttpStatus+") " + HttpStatus.getStatusText(lastHttpStatus) + " -- " + url );
|
logger.info("("+lastHttpStatus+") " + HttpStatus.getStatusText(lastHttpStatus) + " -- " + url );
|
||||||
|
@ -160,13 +160,13 @@ public class HTTPCallsUtils {
|
||||||
httpMethod.releaseConnection();
|
httpMethod.releaseConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return new HttpResponse(lastHttpStatus, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show content type.
|
* Show content type.
|
||||||
*
|
*
|
||||||
* @param entity the entity
|
* @param method the new content type
|
||||||
*/
|
*/
|
||||||
private void setContentType(HttpMethod method) {
|
private void setContentType(HttpMethod method) {
|
||||||
final Header contentTypeHeader=method.getResponseHeader("Content-Type");
|
final Header contentTypeHeader=method.getResponseHeader("Content-Type");
|
||||||
|
@ -174,6 +174,8 @@ public class HTTPCallsUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the last content type.
|
||||||
|
*
|
||||||
* @return the lastContentType
|
* @return the lastContentType
|
||||||
*/
|
*/
|
||||||
public String getLastContentType() {
|
public String getLastContentType() {
|
||||||
|
@ -342,6 +344,7 @@ public class HTTPCallsUtils {
|
||||||
*
|
*
|
||||||
* @param url The URL where to connect to.
|
* @param url The URL where to connect to.
|
||||||
* @param requestEntity The request to be sent.
|
* @param requestEntity The request to be sent.
|
||||||
|
* @param parameterMap the parameter map
|
||||||
* @return The HTTP response as a String if the HTTP response code was 200 (OK).
|
* @return The HTTP response as a String if the HTTP response code was 200 (OK).
|
||||||
* the HTTP response or <TT>null</TT> on errors.
|
* the HTTP response or <TT>null</TT> on errors.
|
||||||
*/
|
*/
|
||||||
|
@ -667,4 +670,97 @@ public class HTTPCallsUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class HttpResponse.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
* Sep 7, 2016
|
||||||
|
*/
|
||||||
|
public class HttpResponse {
|
||||||
|
int status;
|
||||||
|
String response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new http response.
|
||||||
|
*/
|
||||||
|
public HttpResponse() {
|
||||||
|
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new http response.
|
||||||
|
*
|
||||||
|
* @param status the status
|
||||||
|
* @param response the response
|
||||||
|
*/
|
||||||
|
public HttpResponse(int status, String response) {
|
||||||
|
|
||||||
|
super();
|
||||||
|
this.status = status;
|
||||||
|
this.response = response;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the status.
|
||||||
|
*
|
||||||
|
* @return the status
|
||||||
|
*/
|
||||||
|
public int getStatus() {
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the response.
|
||||||
|
*
|
||||||
|
* @return the response
|
||||||
|
*/
|
||||||
|
public String getResponse() {
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the status.
|
||||||
|
*
|
||||||
|
* @param status the status to set
|
||||||
|
*/
|
||||||
|
public void setStatus(int status) {
|
||||||
|
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the response.
|
||||||
|
*
|
||||||
|
* @param response the response to set
|
||||||
|
*/
|
||||||
|
public void setResponse(String response) {
|
||||||
|
|
||||||
|
this.response = response;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Object#toString()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("HttpResponse [status=");
|
||||||
|
builder.append(status);
|
||||||
|
builder.append(", response=");
|
||||||
|
builder.append(response);
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,15 @@
|
||||||
<html>
|
<!DOCTYPE HTML>
|
||||||
|
<html lang="en-US">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="refresh" content="0; url=https://dev4.d4science.org/ckan">
|
||||||
|
<script type="text/javascript">
|
||||||
|
window.location.href = "https://dev4.d4science.org/ckan"
|
||||||
|
</script>
|
||||||
|
<title>Page Redirection</title>
|
||||||
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h2>The URI resolver </h2>
|
<!-- Note: don't tell people to `click` the link, just tell them that it is a link. -->
|
||||||
<p>See wiki page: <a href="https://gcube.wiki.gcube-system.org/gcube/index.php/URI_Resolver">URI Resolver gCube Wiki</a></p>
|
If you are not redirected automatically, follow the <a href='https://dev4.d4science.org/ckan'>link to example</a>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -0,0 +1,58 @@
|
||||||
|
import it.geosolutions.geonetwork.util.GNSearchRequest;
|
||||||
|
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.gcube.spatial.data.geonetwork.GeoNetwork;
|
||||||
|
import org.gcube.spatial.data.geonetwork.GeoNetworkReader;
|
||||||
|
import org.gcube.spatial.data.geonetwork.LoginLevel;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
* Aug 31, 2016
|
||||||
|
*/
|
||||||
|
public class GeonetworkQueryTest {
|
||||||
|
|
||||||
|
private String[] scopes = {"/gcube/devsec/devVRE"};
|
||||||
|
|
||||||
|
private String[] scopesProd = {"/d4science.research-infrastructures.eu"};
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getCount() throws Exception{
|
||||||
|
try{
|
||||||
|
for(String scope:scopes){
|
||||||
|
ScopeProvider.instance.set(scope);
|
||||||
|
GeoNetworkReader reader=GeoNetwork.get();
|
||||||
|
final GNSearchRequest req=new GNSearchRequest();
|
||||||
|
// req.addParam("keyword", "Thredds");
|
||||||
|
req.addParam(GNSearchRequest.Param.any,"");
|
||||||
|
int publicCount=reader.query(req).getCount();
|
||||||
|
reader.login(LoginLevel.CKAN);
|
||||||
|
int totalCount=reader.query(req).getCount();
|
||||||
|
System.out.println("SCOPE "+scope+" found "+totalCount+" (public : "+publicCount+", private :"+(totalCount-publicCount)+")");
|
||||||
|
}
|
||||||
|
}catch(Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// @Test
|
||||||
|
public void getCountProd() throws Exception{
|
||||||
|
try{
|
||||||
|
for(String scope:scopesProd){
|
||||||
|
ScopeProvider.instance.set(scope);
|
||||||
|
GeoNetworkReader reader=GeoNetwork.get();
|
||||||
|
final GNSearchRequest req=new GNSearchRequest();
|
||||||
|
// req.addParam("keyword", "Thredds");
|
||||||
|
req.addParam(GNSearchRequest.Param.any,"Thredds");
|
||||||
|
int publicCount=reader.query(req).getCount();
|
||||||
|
reader.login(LoginLevel.SCOPE);
|
||||||
|
int totalCount=reader.query(req).getCount();
|
||||||
|
System.out.println("SCOPE "+scope+" found "+totalCount+" (public : "+publicCount+", private :"+(totalCount-publicCount)+")");
|
||||||
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
* Sep 7, 2016
|
||||||
|
*/
|
||||||
|
public class GisResolverTest {
|
||||||
|
|
||||||
|
|
||||||
|
// public void resolve(){
|
||||||
|
// GisResolver gisResolver = new GisResolver();
|
||||||
|
// String scope = "/gcube/devsec/devVRE";
|
||||||
|
// String UUID = "177e1c3c-4a22-4ad9-b015-bfc443d16cb8";
|
||||||
|
// try {
|
||||||
|
// ServerParameters geonetworkParams = gisResolver.getCachedServerParameters(scope);
|
||||||
|
// String wmsRequest = gisResolver.getLayerWmsRequest(scope, UUID, geonetworkParams);
|
||||||
|
// System.out.println("Final url is: " + wmsRequest);
|
||||||
|
// wmsRequest = URLEncoder.encode(wmsRequest, UTF_8);
|
||||||
|
// System.out.println("Encoded WMS request is: " + wmsRequest);
|
||||||
|
// String gisPortletUrl = gisResolver.getGisViewerApplicationURL(scope);
|
||||||
|
// System.out.println("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);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// // TODO Auto-generated catch block
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
Loading…
Reference in New Issue