updated init and refactoring performed

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@173963 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-11-05 14:58:49 +00:00
parent 04d897ee7c
commit 6a557f5a03
10 changed files with 566 additions and 565 deletions

View File

@ -1,242 +1,242 @@
/** ///**
* // *
*/ // */
package org.gcube.datatransfer.resolver; //package org.gcube.datatransfer.resolver;
//
import javax.servlet.ServletException; //import javax.servlet.ServletException;
//
import org.gcube.datatransfer.resolver.GeonetworkRequestFilterParameters.MODE; //import org.gcube.datatransfer.resolver.GeonetworkRequestFilterParameters.MODE;
import org.gcube.datatransfer.resolver.GeonetworkRequestFilterParameters.VISIBILITY; //import org.gcube.datatransfer.resolver.GeonetworkRequestFilterParameters.VISIBILITY;
import org.gcube.datatransfer.resolver.gis.geonetwork.GeonetworkResolver; //import org.gcube.datatransfer.resolver.gis.geonetwork.GeonetworkResolver;
import org.slf4j.Logger; //import org.slf4j.Logger;
import org.slf4j.LoggerFactory; //import org.slf4j.LoggerFactory;
//
//
/** ///**
* The Class GeonetworkRequestDecoder. // * The Class GeonetworkRequestDecoder.
* // *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it // * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jul 27, 2016 // * Jul 27, 2016
* // *
* This class parses a request from servletpath and queryString // * This class parses a request from servletpath and queryString
* // *
* The request must be: SCOPE#PARMETERS // * The request must be: SCOPE#PARMETERS
* SCOPE must be: separated by {@link GeonetworkRequestDecoder#SCOPE_SEPARATOR} // * SCOPE must be: separated by {@link GeonetworkRequestDecoder#SCOPE_SEPARATOR}
* PARAMETERS can be: // * PARAMETERS can be:
* {@link GeonetworkResolver#PARAMETER_FILTER_PUBLIC_IDS} // * {@link GeonetworkResolver#PARAMETER_FILTER_PUBLIC_IDS}
* {@link GeonetworkResolver#PARAMETER_NO_AUTHENTICATION} // * {@link GeonetworkResolver#PARAMETER_NO_AUTHENTICATION}
*/ // */
public class GeonetworkRequestDecoder { //public class GeonetworkRequestDecoder {
//
/** // /**
* // *
*/ // */
public static final String SCOPE_SEPARATOR = "|"; // public static final String SCOPE_SEPARATOR = "|";
//
public static final Logger logger = LoggerFactory.getLogger(GeonetworkRequestDecoder.class); // public static final Logger logger = LoggerFactory.getLogger(GeonetworkRequestDecoder.class);
//
private String gnResolverUriRequest; // private String gnResolverUriRequest;
//
private GeonetworkRequestCriteria geonetworkRequestCriteria; // private GeonetworkRequestCriteria geonetworkRequestCriteria;
//
/** // /**
* Instantiates a new geonetwork request decoder. // * Instantiates a new geonetwork request decoder.
* // *
* @param theServletPath the the servlet path // * @param theServletPath the the servlet path
* @param queryString the query string // * @param queryString the query string
* @throws ServletException the servlet exception // * @throws ServletException the servlet exception
*/ // */
public GeonetworkRequestDecoder(String theServletPath, String queryString) throws ServletException{ // public GeonetworkRequestDecoder(String theServletPath, String queryString) throws ServletException{
//
int index = theServletPath.indexOf(GeonetworkRequestFilterParameters.REQUEST_DELIMITIER); // int index = theServletPath.indexOf(GeonetworkRequestFilterParameters.REQUEST_DELIMITIER);
//
if(index==-1) // if(index==-1)
throw new BadRequestException("Invalid request. Your request must append the '"+GeonetworkRequestFilterParameters.REQUEST_DELIMITIER+"' as final delimiter"); // throw new BadRequestException("Invalid request. Your request must append the '"+GeonetworkRequestFilterParameters.REQUEST_DELIMITIER+"' as final delimiter");
//
int delimiterIndex = index+GeonetworkRequestFilterParameters.REQUEST_DELIMITIER.length(); // int delimiterIndex = index+GeonetworkRequestFilterParameters.REQUEST_DELIMITIER.length();
//
String pathWithoutGN = theServletPath.substring(UriResolverRewriteFilter.SERVLET_GEONETWORK.length()+1, index); // String pathWithoutGN = theServletPath.substring(UriResolverRewriteFilter.SERVLET_GEONETWORK.length()+1, index);
logger.debug("servlet path without "+UriResolverRewriteFilter.SERVLET_GEONETWORK + " is: " +pathWithoutGN); // logger.debug("servlet path without "+UriResolverRewriteFilter.SERVLET_GEONETWORK + " is: " +pathWithoutGN);
geonetworkRequestCriteria = getGeonetworkRequestCriteria(pathWithoutGN); // geonetworkRequestCriteria = getGeonetworkRequestCriteria(pathWithoutGN);
logger.info("performing query by filters: "+geonetworkRequestCriteria); // logger.info("performing query by filters: "+geonetworkRequestCriteria);
logger.debug("scope value is: "+geonetworkRequestCriteria.getScope()); // logger.debug("scope value is: "+geonetworkRequestCriteria.getScope());
//newURI = UriResolverRewriteFilter.SERVLET_GEONETWORK + "?" + GeonetworkResolver.SCOPE + "=" + geonetworkRequestCriteria.getScope() +"&"+ GeonetworkResolver.PARAMETER_FILTER_PUBLIC_IDS +"="+geonetworkRequestCriteria.isValueOfFilterPublicIds() +"&"+GeonetworkResolver.PARAMETER_NO_AUTHENTICATION+"="+geonetworkRequestCriteria.isNoAuthOnGeonetwork(); // //newURI = UriResolverRewriteFilter.SERVLET_GEONETWORK + "?" + GeonetworkResolver.SCOPE + "=" + geonetworkRequestCriteria.getScope() +"&"+ GeonetworkResolver.PARAMETER_FILTER_PUBLIC_IDS +"="+geonetworkRequestCriteria.isValueOfFilterPublicIds() +"&"+GeonetworkResolver.PARAMETER_NO_AUTHENTICATION+"="+geonetworkRequestCriteria.isNoAuthOnGeonetwork();
//
gnResolverUriRequest = UriResolverRewriteFilter.SERVLET_GEONETWORK + "?" // gnResolverUriRequest = UriResolverRewriteFilter.SERVLET_GEONETWORK + "?"
+ GeonetworkResolver.SCOPE + "=" + geonetworkRequestCriteria.getScope() +"&" // + GeonetworkResolver.SCOPE + "=" + geonetworkRequestCriteria.getScope() +"&"
+ GeonetworkRequestFilterParameters.MODE.class.getSimpleName() +"="+geonetworkRequestCriteria.getMode() +"&" // + GeonetworkRequestFilterParameters.MODE.class.getSimpleName() +"="+geonetworkRequestCriteria.getMode() +"&"
+ GeonetworkRequestFilterParameters.VISIBILITY.class.getSimpleName()+"="+geonetworkRequestCriteria.getVisibility(); // + GeonetworkRequestFilterParameters.VISIBILITY.class.getSimpleName()+"="+geonetworkRequestCriteria.getVisibility();
//
if(geonetworkRequestCriteria.getOwner()!=null){ // if(geonetworkRequestCriteria.getOwner()!=null){
gnResolverUriRequest+="&"+GeonetworkRequestFilterParameters.OWNER_PARAM +"="+geonetworkRequestCriteria.getOwner(); // gnResolverUriRequest+="&"+GeonetworkRequestFilterParameters.OWNER_PARAM +"="+geonetworkRequestCriteria.getOwner();
} // }
//
//BUILDING REMAINING PATH WITHOUT GeonetworkRequestFilterParameters.REQUEST_DELIMITIER // //BUILDING REMAINING PATH WITHOUT GeonetworkRequestFilterParameters.REQUEST_DELIMITIER
if(delimiterIndex<theServletPath.length()){ // if(delimiterIndex<theServletPath.length()){
String remainPath = theServletPath.substring(delimiterIndex, theServletPath.length()); // String remainPath = theServletPath.substring(delimiterIndex, theServletPath.length());
gnResolverUriRequest +="&"+GeonetworkResolver.REMAIN_PATH_PARAM+"="+remainPath; // gnResolverUriRequest +="&"+GeonetworkResolver.REMAIN_PATH_PARAM+"="+remainPath;
}
if(queryString!=null && !queryString.isEmpty())
gnResolverUriRequest+="&"+queryString;
logger.info("built Geonetwork Resolver GET Request: "+gnResolverUriRequest);
/*
String[] params = pathWithoutGN.split("/");
if(params[0]==null || params[0].isEmpty()){
logger.error("Scope is null or empty, you must set a valid scope /geonetwork/root|vo|vre");
throw new ServletException("Scope is null or empty, you must set a valid scope /geonetwork/root"+SCOPE_SEPARATOR+"vo"+SCOPE_SEPARATOR+"vre");
}
geonetworkRequestCriteria = getGeonetworkRequestCriteria(params[0]);
logger.debug("scope value is: "+geonetworkRequestCriteria.getScope());
newURI = UriResolverRewriteFilter.SERVLET_GEONETWORK + "?" + GeonetworkResolver.SCOPE + "=" + geonetworkRequestCriteria.getScope() +"&"+ GeonetworkResolver.PARAMETER_FILTER_PUBLIC_IDS +"="+geonetworkRequestCriteria.isValueOfFilterPublicIds() +"&"+GeonetworkResolver.PARAMETER_NO_AUTHENTICATION+"="+geonetworkRequestCriteria.isNoAuthOnGeonetwork();
logger.debug(GeonetworkResolver.PARAMETER_FILTER_PUBLIC_IDS +" is: "+geonetworkRequestCriteria.isValueOfFilterPublicIds());
logger.debug(GeonetworkResolver.PARAMETER_NO_AUTHENTICATION +" is: "+geonetworkRequestCriteria.isNoAuthOnGeonetwork());
*/
// if(params.length>1){
// String remainPath = "";
//// newURI +="&remainPath=";
// for (int i = 1; i < params.length; i++) {
// String httpGetParam = params[i];
// if(httpGetParam!=null && !httpGetParam.isEmpty())
// remainPath+="/"+httpGetParam;
// }
// newURI +="&"+GeonetworkResolver.REMAIN_PATH+"="+remainPath;
// } // }
// //
// if(queryString!=null && !queryString.isEmpty()) // if(queryString!=null && !queryString.isEmpty())
// newURI+="&"+queryString; // gnResolverUriRequest+="&"+queryString;
//
} // logger.info("built Geonetwork Resolver GET Request: "+gnResolverUriRequest);
// /*
// String[] params = pathWithoutGN.split("/");
/** // if(params[0]==null || params[0].isEmpty()){
* Gets the geonetwork request criteria. // logger.error("Scope is null or empty, you must set a valid scope /geonetwork/root|vo|vre");
// throw new ServletException("Scope is null or empty, you must set a valid scope /geonetwork/root"+SCOPE_SEPARATOR+"vo"+SCOPE_SEPARATOR+"vre");
* Creates a request criteria from input parameter pathWithoutGN // }
* The parameter pathWithoutGN should be an ordered string (like REST request): //
* MODE/SCOPE/VISIBILITY/OWNER // geonetworkRequestCriteria = getGeonetworkRequestCriteria(params[0]);
* MODE must be: {@link MODE} // logger.debug("scope value is: "+geonetworkRequestCriteria.getScope());
* SCOPE must be: ROOT|VO|VRE // newURI = UriResolverRewriteFilter.SERVLET_GEONETWORK + "?" + GeonetworkResolver.SCOPE + "=" + geonetworkRequestCriteria.getScope() +"&"+ GeonetworkResolver.PARAMETER_FILTER_PUBLIC_IDS +"="+geonetworkRequestCriteria.isValueOfFilterPublicIds() +"&"+GeonetworkResolver.PARAMETER_NO_AUTHENTICATION+"="+geonetworkRequestCriteria.isNoAuthOnGeonetwork();
* VISIBILITY must be: {@link VISIBILITY} // logger.debug(GeonetworkResolver.PARAMETER_FILTER_PUBLIC_IDS +" is: "+geonetworkRequestCriteria.isValueOfFilterPublicIds());
* OWNER (is optional): filter by owner // logger.debug(GeonetworkResolver.PARAMETER_NO_AUTHENTICATION +" is: "+geonetworkRequestCriteria.isNoAuthOnGeonetwork());
* @param pathWithoutGN the path without Geonetwork base URL // */
* //// if(params.length>1){
* @return the geonetwork request criteria //// String remainPath = "";
* @throws ServletException the servlet exception ////// newURI +="&remainPath=";
*/ //// for (int i = 1; i < params.length; i++) {
private static GeonetworkRequestCriteria getGeonetworkRequestCriteria(String pathWithoutGN) throws ServletException{ //// String httpGetParam = params[i];
//// if(httpGetParam!=null && !httpGetParam.isEmpty())
String[] params = pathWithoutGN.split("/"); //// remainPath+="/"+httpGetParam;
MODE mode = null; //// }
String theScope = null; //// newURI +="&"+GeonetworkResolver.REMAIN_PATH+"="+remainPath;
VISIBILITY visibility = null; //// }
String owner = null; ////
//// if(queryString!=null && !queryString.isEmpty())
if(params.length < 3){ //// newURI+="&"+queryString;
throw new BadRequestException("Bad request. Read the request "+pathWithoutGN+". You must pass a valid request like [GEONETWORK_BASE_URL]/SCOPE/MODE/VISIBILITY/OWNER"); //
} // }
//
//SCOPE //
if(params[0]!=null && !params[0].isEmpty()){ // /**
theScope = params[0]; // * Gets the geonetwork request criteria.
logger.debug("Read parameter scope: "+theScope); //
theScope = theScope.replaceAll("\\"+SCOPE_SEPARATOR, "/"); // * Creates a request criteria from input parameter pathWithoutGN
if (!theScope.startsWith("/")) // * The parameter pathWithoutGN should be an ordered string (like REST request):
theScope="/"+theScope; // * MODE/SCOPE/VISIBILITY/OWNER
}else{ // * MODE must be: {@link MODE}
logger.error("The first parameter 'scope' is null or empty, you must set a valid scope as ROOT"+SCOPE_SEPARATOR+"VO"+SCOPE_SEPARATOR+"VRE as first parameter"); // * SCOPE must be: ROOT|VO|VRE
throw new ServletException("Scope is null or empty. You must pass a valid scope as ROOT"+SCOPE_SEPARATOR+"VO"+SCOPE_SEPARATOR+"VRE as first parameter"); // * VISIBILITY must be: {@link VISIBILITY}
} // * OWNER (is optional): filter by owner
// * @param pathWithoutGN the path without Geonetwork base URL
//MODE // *
if(params[1]!=null && !params[1].isEmpty()){ // * @return the geonetwork request criteria
String modeTU = params[1].toUpperCase(); // * @throws ServletException the servlet exception
logger.debug("Read parameter mode (to upper case): "+modeTU); // */
try{ // private static GeonetworkRequestCriteria getGeonetworkRequestCriteria(String pathWithoutGN) throws ServletException{
mode = MODE.valueOf(modeTU); //
if(mode==null){ // String[] params = pathWithoutGN.split("/");
logger.error("Mode is null"); // MODE mode = null;
throw new Exception("Mode is null"); // String theScope = null;
} // VISIBILITY visibility = null;
// String owner = null;
logger.info("MODE IS: "+mode); //
// if(params.length < 3){
}catch (Exception e) { // throw new BadRequestException("Bad request. Read the request "+pathWithoutGN+". You must pass a valid request like [GEONETWORK_BASE_URL]/SCOPE/MODE/VISIBILITY/OWNER");
logger.error("The second parameter is wrong, Have you pass a valid parameter MODE like vre/harvest?"); // }
throw new BadRequestException("Bad parameter. You must set a valid MODE parameter as "+MODE.VRE + " or "+MODE.HARVEST+" as second parameter"); //
} // //SCOPE
}else // if(params[0]!=null && !params[0].isEmpty()){
throw new BadRequestException("The parameter MODE is null or empty. You must pass a valid MODE parameter as "+MODE.VRE + " or "+MODE.HARVEST +" as second parameter"); // theScope = params[0];
// logger.debug("Read parameter scope: "+theScope);
//VISIBILITY // theScope = theScope.replaceAll("\\"+SCOPE_SEPARATOR, "/");
if(params[2]!=null && !params[2].isEmpty()){ // if (!theScope.startsWith("/"))
String visTU = params[2].toUpperCase(); // theScope="/"+theScope;
logger.debug("Read parameter mode (to upper case): "+visTU); // }else{
try{ // logger.error("The first parameter 'scope' is null or empty, you must set a valid scope as ROOT"+SCOPE_SEPARATOR+"VO"+SCOPE_SEPARATOR+"VRE as first parameter");
visibility = VISIBILITY.valueOf(visTU); // throw new ServletException("Scope is null or empty. You must pass a valid scope as ROOT"+SCOPE_SEPARATOR+"VO"+SCOPE_SEPARATOR+"VRE as first parameter");
if(visibility==null){ // }
logger.error("VISIBILITY is null"); //
throw new Exception("VISIBILITY is null"); // //MODE
} // if(params[1]!=null && !params[1].isEmpty()){
// String modeTU = params[1].toUpperCase();
logger.info("VISIBILITY IS: "+visibility); // logger.debug("Read parameter mode (to upper case): "+modeTU);
// try{
}catch (Exception e) { // mode = MODE.valueOf(modeTU);
logger.error("The third parameter is wrong, Have you pass a valid parameter VISIBILITY like vre/harvest?"); // if(mode==null){
throw new BadRequestException("Bad parameter. You must set a valid VISIBILITY parameter as "+VISIBILITY.PRV + " or "+VISIBILITY.PUB+ " as third parameter"); // logger.error("Mode is null");
} // throw new Exception("Mode is null");
}else // }
throw new BadRequestException("The parameter VISIBILITY is null or empty. You must pass a valid VISIBILITY parameter as "+VISIBILITY.PRV + " or "+VISIBILITY.PUB +" as third parameter"); //
// logger.info("MODE IS: "+mode);
//
//OWNER // }catch (Exception e) {
if(params.length > 3 && params[3]!=null && params[3]!=GeonetworkRequestFilterParameters.REQUEST_DELIMITIER){ // logger.error("The second parameter is wrong, Have you pass a valid parameter MODE like vre/harvest?");
owner = params[3]; // throw new BadRequestException("Bad parameter. You must set a valid MODE parameter as "+MODE.VRE + " or "+MODE.HARVEST+" as second parameter");
logger.debug("Read parameter owner: "+owner); // }
} // }else
// throw new BadRequestException("The parameter MODE is null or empty. You must pass a valid MODE parameter as "+MODE.VRE + " or "+MODE.HARVEST +" as second parameter");
return new GeonetworkRequestCriteria(theScope, mode, owner, visibility); //
} // //VISIBILITY
// if(params[2]!=null && !params[2].isEmpty()){
// String visTU = params[2].toUpperCase();
/** // logger.debug("Read parameter mode (to upper case): "+visTU);
* Gets the geonetwork resolver uri request. // try{
* // visibility = VISIBILITY.valueOf(visTU);
* @return the geonetwork resolver uri request // if(visibility==null){
*/ // logger.error("VISIBILITY is null");
public String getGeonetworkResolverURIRequest() { // throw new Exception("VISIBILITY is null");
// }
return gnResolverUriRequest; //
} // logger.info("VISIBILITY IS: "+visibility);
//
/** // }catch (Exception e) {
* Gets the geonetwork request criteria. // logger.error("The third parameter is wrong, Have you pass a valid parameter VISIBILITY like vre/harvest?");
* // throw new BadRequestException("Bad parameter. You must set a valid VISIBILITY parameter as "+VISIBILITY.PRV + " or "+VISIBILITY.PUB+ " as third parameter");
* @return the geonetworkRequestCriteria // }
*/ // }else
public GeonetworkRequestCriteria getGeonetworkRequestCriteria() { // throw new BadRequestException("The parameter VISIBILITY is null or empty. You must pass a valid VISIBILITY parameter as "+VISIBILITY.PRV + " or "+VISIBILITY.PUB +" as third parameter");
//
return geonetworkRequestCriteria; //
} // //OWNER
// if(params.length > 3 && params[3]!=null && params[3]!=GeonetworkRequestFilterParameters.REQUEST_DELIMITIER){
// owner = params[3];
/* (non-Javadoc) // logger.debug("Read parameter owner: "+owner);
* @see java.lang.Object#toString() // }
*/ //
@Override // return new GeonetworkRequestCriteria(theScope, mode, owner, visibility);
public String toString() { // }
//
StringBuilder builder = new StringBuilder(); //
builder.append("GeonetworkRequestDecoder [gnResolverUriRequest="); // /**
builder.append(gnResolverUriRequest); // * Gets the geonetwork resolver uri request.
builder.append(", geonetworkRequestCriteria="); // *
builder.append(geonetworkRequestCriteria); // * @return the geonetwork resolver uri request
builder.append("]"); // */
return builder.toString(); // public String getGeonetworkResolverURIRequest() {
} //
// return gnResolverUriRequest;
// }
//
} // /**
// * Gets the geonetwork request criteria.
// *
// * @return the geonetworkRequestCriteria
// */
// public GeonetworkRequestCriteria getGeonetworkRequestCriteria() {
//
// return geonetworkRequestCriteria;
// }
//
//
// /* (non-Javadoc)
// * @see java.lang.Object#toString()
// */
// @Override
// public String toString() {
//
// StringBuilder builder = new StringBuilder();
// builder.append("GeonetworkRequestDecoder [gnResolverUriRequest=");
// builder.append(gnResolverUriRequest);
// builder.append(", geonetworkRequestCriteria=");
// builder.append(geonetworkRequestCriteria);
// builder.append("]");
// return builder.toString();
// }
//
//
//
//}

View File

@ -1,237 +1,237 @@
/** ///**
* // *
*/ // */
package org.gcube.datatransfer.resolver; //package org.gcube.datatransfer.resolver;
//
import java.io.IOException; //import java.io.IOException;
import java.util.HashSet; //import java.util.HashSet;
import java.util.Set; //import java.util.Set;
//
import javax.servlet.Filter; //import javax.servlet.Filter;
import javax.servlet.FilterChain; //import javax.servlet.FilterChain;
import javax.servlet.FilterConfig; //import javax.servlet.FilterConfig;
import javax.servlet.ServletException; //import javax.servlet.ServletException;
import javax.servlet.ServletRequest; //import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; //import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest; //import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; //import javax.servlet.http.HttpServletResponse;
//
import org.gcube.datatransfer.resolver.catalogue.CatalogueRequestParameter; //import org.gcube.datatransfer.resolver.catalogue.CatalogueRequestParameter;
import org.gcube.datatransfer.resolver.catalogue.UrlEncoderUtil; //import org.gcube.datatransfer.resolver.catalogue.UrlEncoderUtil;
import org.slf4j.Logger; //import org.slf4j.Logger;
import org.slf4j.LoggerFactory; //import org.slf4j.LoggerFactory;
//
//
//
/** ///**
* The Class UriResolverRewriteFilter. // * The Class UriResolverRewriteFilter.
* // *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it // * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Dec 5, 2016 // * Dec 5, 2016
*/ // */
public class UriResolverRewriteFilter implements Filter{ //public class UriResolverRewriteFilter implements Filter{
//
/** // /**
* // *
*/ // */
public static final String SERVLET_URI_RESOLVER = "/uri-resolver"; // public static final String SERVLET_URI_RESOLVER = "/uri-resolver";
//
private static final String PATH_SEPARATOR = "/"; // private static final String PATH_SEPARATOR = "/";
public static final String SERVLET_GEONETWORK = "/geonetwork"; // public static final String SERVLET_GEONETWORK = "/geonetwork";
public static final String REQUEST_PARAMETER_SEPARATOR = "#"; // public static final String REQUEST_PARAMETER_SEPARATOR = "#";
//
public static final String PARAMETER_SMP_ID = "smp-id"; // public static final String PARAMETER_SMP_ID = "smp-id";
public static final String SERVLET_STORAGE_ID = "id"; // public static final String SERVLET_STORAGE_ID = "id";
//
public static final String PARAMETER_ENC_CATALOGUE_LINK = "cl"; // public static final String PARAMETER_ENC_CATALOGUE_LINK = "cl";
public static final String PARAMETER_DIRECT_CATALOGUE_LINK = "dl"; // public static final String PARAMETER_DIRECT_CATALOGUE_LINK = "dl";
public static final String SERVLET_CATALOGUE = "/catalogue"; // public static final String SERVLET_CATALOGUE = "/catalogue";
//
protected static final Logger logger = LoggerFactory.getLogger(UriResolverRewriteFilter.class); // protected static final Logger logger = LoggerFactory.getLogger(UriResolverRewriteFilter.class);
private FilterConfig config; // private FilterConfig config;
//
private static final Set<String> resourceCataloguesCodes = new HashSet<String>(ResourceCatalogueCodes.codes()); // private static final Set<String> resourceCataloguesCodes = new HashSet<String>(ResourceCatalogueCodes.codes());
//
//private ApplicationProfileReaderForCatalogueResolver appPrfCatResolver = new ApplicationProfileReaderForCatalogueResolver(scope, useRootScope) // //private ApplicationProfileReaderForCatalogueResolver appPrfCatResolver = new ApplicationProfileReaderForCatalogueResolver(scope, useRootScope)
//
/** // /**
* Gets the config. // * Gets the config.
* // *
* @return the config // * @return the config
*/ // */
public FilterConfig getConfig() { // public FilterConfig getConfig() {
//
return config; // return config;
} // }
//
/* (non-Javadoc) // /* (non-Javadoc)
* @see javax.servlet.Filter#destroy() // * @see javax.servlet.Filter#destroy()
*/ // */
@Override // @Override
public void destroy() { // public void destroy() {
logger.trace("run destroy"); // logger.trace("run destroy");
} // }
//
//
/* (non-Javadoc) // /* (non-Javadoc)
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) // * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
*/ // */
@Override // @Override
public void doFilter(ServletRequest req, ServletResponse response, FilterChain chain) throws IOException, ServletException { // public void doFilter(ServletRequest req, ServletResponse response, FilterChain chain) throws IOException, ServletException {
/* wrap the request in order to read the inputstream multiple times */ // /* wrap the request in order to read the inputstream multiple times */
MultiReadHttpServletRequest multiReadRequest = new MultiReadHttpServletRequest((HttpServletRequest) req); // MultiReadHttpServletRequest multiReadRequest = new MultiReadHttpServletRequest((HttpServletRequest) req);
String requestURI = multiReadRequest.getRequestURI(); // String requestURI = multiReadRequest.getRequestURI();
String queryString = multiReadRequest.getQueryString(); // String queryString = multiReadRequest.getQueryString();
String servletPath = multiReadRequest.getServletPath(); // String servletPath = multiReadRequest.getServletPath();
logger.debug("Request URI: " + requestURI + ", QueryString: " +queryString+ ", Servlet path: "+servletPath); // logger.debug("Request URI: " + requestURI + ", QueryString: " +queryString+ ", Servlet path: "+servletPath);
//
try{ // try{
//IS A REQUEST FOR GEONETWORK AUTHENTICATION? (CKAN HARVESTING?) // //IS A REQUEST FOR GEONETWORK AUTHENTICATION? (CKAN HARVESTING?)
if(servletPath.startsWith(SERVLET_GEONETWORK) || servletPath.startsWith(SERVLET_URI_RESOLVER+SERVLET_GEONETWORK)){ // if(servletPath.startsWith(SERVLET_GEONETWORK) || servletPath.startsWith(SERVLET_URI_RESOLVER+SERVLET_GEONETWORK)){
logger.debug("It is a request to geonetwork"); // logger.debug("It is a request to geonetwork");
GeonetworkRequestDecoder grd = new GeonetworkRequestDecoder(servletPath, queryString); // GeonetworkRequestDecoder grd = new GeonetworkRequestDecoder(servletPath, queryString);
logger.debug("forward to: "+grd.getGeonetworkResolverURIRequest()); // logger.debug("forward to: "+grd.getGeonetworkResolverURIRequest());
multiReadRequest.getRequestDispatcher(grd.getGeonetworkResolverURIRequest()).forward(multiReadRequest, response); // multiReadRequest.getRequestDispatcher(grd.getGeonetworkResolverURIRequest()).forward(multiReadRequest, response);
//
}else{ // }else{
logger.debug("checking if it is a request to catologue..."); // logger.debug("checking if it is a request to catologue...");
boolean isCatalogueServletReference = servletPath.startsWith(SERVLET_CATALOGUE); // boolean isCatalogueServletReference = servletPath.startsWith(SERVLET_CATALOGUE);
//
String idCodeCatalogue = null; // String idCodeCatalogue = null;
boolean isIdCodeCatalogue = false; // boolean isIdCodeCatalogue = false;
String splittedServletPath[] = servletPath.split(PATH_SEPARATOR); // String splittedServletPath[] = servletPath.split(PATH_SEPARATOR);
if(!isCatalogueServletReference){ // if(!isCatalogueServletReference){
idCodeCatalogue = splittedServletPath[1]; // idCodeCatalogue = splittedServletPath[1];
logger.trace("checking if the code: "+idCodeCatalogue+" belongs to a catalogue code"); // logger.trace("checking if the code: "+idCodeCatalogue+" belongs to a catalogue code");
isIdCodeCatalogue = resourceCataloguesCodes.contains(idCodeCatalogue); // isIdCodeCatalogue = resourceCataloguesCodes.contains(idCodeCatalogue);
logger.debug("\tIs it a catalogue code? "+isIdCodeCatalogue); // logger.debug("\tIs it a catalogue code? "+isIdCodeCatalogue);
} // }
//
if(isCatalogueServletReference || isIdCodeCatalogue){ // if(isCatalogueServletReference || isIdCodeCatalogue){
//
//int startIndex = requestURI.indexOf(SERVLET_CATALOGUE))+SERVLET_CATALOGUE.length(); // //int startIndex = requestURI.indexOf(SERVLET_CATALOGUE))+SERVLET_CATALOGUE.length();
//String vreName = requestURI.substring(beginIndex) // //String vreName = requestURI.substring(beginIndex)
HttpServletRequest request = (HttpServletRequest) req; // HttpServletRequest request = (HttpServletRequest) req;
logger.trace("method is: "+request.getMethod()); // logger.trace("method is: "+request.getMethod());
//
if(request.getMethod().compareToIgnoreCase("POST")==0){ // if(request.getMethod().compareToIgnoreCase("POST")==0){
logger.debug("Managing as Catalogue POST request.."); // logger.debug("Managing as Catalogue POST request..");
logger.debug("forward to: " + SERVLET_CATALOGUE); // logger.debug("forward to: " + SERVLET_CATALOGUE);
multiReadRequest.getRequestDispatcher(SERVLET_CATALOGUE).forward(multiReadRequest, response); // multiReadRequest.getRequestDispatcher(SERVLET_CATALOGUE).forward(multiReadRequest, response);
}else{ // }else{
logger.debug("Managing as Catalogue GET request.."); // logger.debug("Managing as Catalogue GET request..");
String newURI = SERVLET_CATALOGUE; // String newURI = SERVLET_CATALOGUE;
//String[] pathSplit = newServletPath.split(PATH_SEPARATOR); // //String[] pathSplit = newServletPath.split(PATH_SEPARATOR);
if(isIdCodeCatalogue){ // if(isIdCodeCatalogue){
//TO BUILD A COMPLETE URL // //TO BUILD A COMPLETE URL
// logger.debug("is a catalogue code, rebuilding complete url..."); // // logger.debug("is a catalogue code, rebuilding complete url...");
// ResourceCatalogueCodes rcc = ResourceCatalogueCodes.valueOfId(idCodeCatalogue); // // ResourceCatalogueCodes rcc = ResourceCatalogueCodes.valueOfId(idCodeCatalogue);
// newServletPath = SERVLET_CATALOGUE+splittedServletPath[2]+PATH_SEPARATOR+rcc.getValue()+PATH_SEPARATOR+splittedServletPath[3]; // // newServletPath = SERVLET_CATALOGUE+splittedServletPath[2]+PATH_SEPARATOR+rcc.getValue()+PATH_SEPARATOR+splittedServletPath[3];
// logger.debug("rebuilded complete url: "+newServletPath); // // logger.debug("rebuilded complete url: "+newServletPath);
logger.debug("is a catalogue code, resolving a short url in clear ..."); // logger.debug("is a catalogue code, resolving a short url in clear ...");
ResourceCatalogueCodes rcc = ResourceCatalogueCodes.valueOfCodeId(idCodeCatalogue); // ResourceCatalogueCodes rcc = ResourceCatalogueCodes.valueOfCodeId(idCodeCatalogue);
logger.debug("found VRE name: "+splittedServletPath[2]); // logger.debug("found VRE name: "+splittedServletPath[2]);
String gcubeScope = CatalogueRequestParameter.GCUBE_SCOPE.getKey() +"="+splittedServletPath[2]; // String gcubeScope = CatalogueRequestParameter.GCUBE_SCOPE.getKey() +"="+splittedServletPath[2];
String eC = CatalogueRequestParameter.ENTITY_CONTEXT.getKey() +"="+rcc.getValue(); // String eC = CatalogueRequestParameter.ENTITY_CONTEXT.getKey() +"="+rcc.getValue();
logger.debug("found id code: "+idCodeCatalogue+", resolving it with context name: "+eC); // logger.debug("found id code: "+idCodeCatalogue+", resolving it with context name: "+eC);
String eN = CatalogueRequestParameter.ENTITY_NAME.getKey() +"="+splittedServletPath[3]; // String eN = CatalogueRequestParameter.ENTITY_NAME.getKey() +"="+splittedServletPath[3];
logger.debug("found entity name: "+eN); // logger.debug("found entity name: "+eN);
String encodedQuery = UrlEncoderUtil.encodeQuery(gcubeScope,eC,eN); // String encodedQuery = UrlEncoderUtil.encodeQuery(gcubeScope,eC,eN);
newURI+= "?" + PARAMETER_DIRECT_CATALOGUE_LINK + "=" + encodedQuery; // newURI+= "?" + PARAMETER_DIRECT_CATALOGUE_LINK + "=" + encodedQuery;
}else // }else
if(splittedServletPath.length==5){ // if(splittedServletPath.length==5){
logger.info("resolving a complete URL in clear..."); // logger.info("resolving a complete URL in clear...");
logger.debug("found VRE name: "+splittedServletPath[2]); // logger.debug("found VRE name: "+splittedServletPath[2]);
String gcubeScope = CatalogueRequestParameter.GCUBE_SCOPE.getKey() +"="+splittedServletPath[2]; // String gcubeScope = CatalogueRequestParameter.GCUBE_SCOPE.getKey() +"="+splittedServletPath[2];
String eC = CatalogueRequestParameter.ENTITY_CONTEXT.getKey() +"="+splittedServletPath[3]; // String eC = CatalogueRequestParameter.ENTITY_CONTEXT.getKey() +"="+splittedServletPath[3];
logger.debug("found context name: "+eC); // logger.debug("found context name: "+eC);
String eN = CatalogueRequestParameter.ENTITY_NAME.getKey() +"="+splittedServletPath[4]; // String eN = CatalogueRequestParameter.ENTITY_NAME.getKey() +"="+splittedServletPath[4];
logger.debug("found entity name: "+eN); // logger.debug("found entity name: "+eN);
String encodedQuery = UrlEncoderUtil.encodeQuery(gcubeScope,eC,eN); // String encodedQuery = UrlEncoderUtil.encodeQuery(gcubeScope,eC,eN);
newURI+= "?" + PARAMETER_DIRECT_CATALOGUE_LINK + "=" + encodedQuery; // newURI+= "?" + PARAMETER_DIRECT_CATALOGUE_LINK + "=" + encodedQuery;
}else{ // }else{
//
logger.info("Resolving an encrypted URL to catalogue..."); // logger.info("Resolving an encrypted URL to catalogue...");
int lastSlash = requestURI.lastIndexOf(PATH_SEPARATOR); // int lastSlash = requestURI.lastIndexOf(PATH_SEPARATOR);
String toCatalogueLink = requestURI.substring(lastSlash + 1, requestURI.length()); // String toCatalogueLink = requestURI.substring(lastSlash + 1, requestURI.length());
newURI+= "?" + PARAMETER_ENC_CATALOGUE_LINK + "=" + toCatalogueLink; // newURI+= "?" + PARAMETER_ENC_CATALOGUE_LINK + "=" + toCatalogueLink;
} // }
//
logger.debug("forward to: " + newURI); // logger.debug("forward to: " + newURI);
multiReadRequest.getRequestDispatcher(newURI).forward(multiReadRequest, response); // multiReadRequest.getRequestDispatcher(newURI).forward(multiReadRequest, response);
} // }
//
//chain.doFilter(multiReadRequest, response); // //chain.doFilter(multiReadRequest, response);
}else{ // }else{
logger.debug("It is a request to workspace/storage"); // logger.debug("It is a request to workspace/storage");
//LAST CASE, IS WORKSPACE REQUEST? // //LAST CASE, IS WORKSPACE REQUEST?
if (queryString == null) { // IS A /XXXXX // if (queryString == null) { // IS A /XXXXX
logger.debug("QueryString is null, is It a new SMP public uri by ID?"); // logger.debug("QueryString is null, is It a new SMP public uri by ID?");
int lastSlash = requestURI.lastIndexOf(PATH_SEPARATOR); // int lastSlash = requestURI.lastIndexOf(PATH_SEPARATOR);
if (lastSlash + 1 == requestURI.length()) { // if (lastSlash + 1 == requestURI.length()) {
logger.debug("'/' is last index, doFilter Request"); // logger.debug("'/' is last index, doFilter Request");
// req.getRequestDispatcher("/").forward(req, res); // // req.getRequestDispatcher("/").forward(req, res);
chain.doFilter(multiReadRequest, response); // chain.doFilter(multiReadRequest, response);
} // }
else { // else {
String toStorageID = requestURI.substring(lastSlash + 1, requestURI.length()); // String toStorageID = requestURI.substring(lastSlash + 1, requestURI.length());
// String newURI = requestURI.replace(toReplace, // // String newURI = requestURI.replace(toReplace,
// SERVLET_RESOLVER_BY_ID+"?"+SMP_ID+"="+toReplace); // // SERVLET_RESOLVER_BY_ID+"?"+SMP_ID+"="+toReplace);
String newURI = SERVLET_STORAGE_ID + "?" + PARAMETER_SMP_ID + "=" + toStorageID; // String newURI = SERVLET_STORAGE_ID + "?" + PARAMETER_SMP_ID + "=" + toStorageID;
logger.debug("forward to: " + newURI); // logger.debug("forward to: " + newURI);
multiReadRequest.getRequestDispatcher(newURI).forward(multiReadRequest, response); // multiReadRequest.getRequestDispatcher(newURI).forward(multiReadRequest, response);
} // }
} // }
else { // else {
logger.debug("It is NOT a SMP public uri by ID, doFilter Request"); // logger.debug("It is NOT a SMP public uri by ID, doFilter Request");
chain.doFilter(multiReadRequest, response); // chain.doFilter(multiReadRequest, response);
} // }
} // }
//
} // }
}catch(BadRequestException bre){ // }catch(BadRequestException bre){
if (response instanceof HttpServletResponse){ // if (response instanceof HttpServletResponse){
HttpServletResponse httpResponse = (HttpServletResponse) response; // HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, bre.getMessage()); // httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, bre.getMessage());
} // }
} // }
} // }
//
//
/** // /**
* Gets the scope. // * Gets the scope.
* // *
* @param scope the scope // * @param scope the scope
* @return the scope // * @return the scope
*/ // */
private static String getScope(String scope){ // private static String getScope(String scope){
logger.debug("Read scope path: "+scope); // logger.debug("Read scope path: "+scope);
// String scope = servletPath.substring(servletPath.indexOf("/"), servletPath.length()); //// String scope = servletPath.substring(servletPath.indexOf("/"), servletPath.length());
return PATH_SEPARATOR+scope.replaceAll("_", PATH_SEPARATOR); // return PATH_SEPARATOR+scope.replaceAll("_", PATH_SEPARATOR);
} // }
//
/* (non-Javadoc) // /* (non-Javadoc)
* @see javax.servlet.Filter#init(javax.servlet.FilterConfig) // * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
*/ // */
@Override // @Override
public void init(FilterConfig config) throws ServletException { // public void init(FilterConfig config) throws ServletException {
logger.trace("run init"); // logger.trace("run init");
this.config = config; // this.config = config;
} // }
//
/*public static void main(String[] args) { // /*public static void main(String[] args) {
//
String split = "/catalogue/NextNext/dataset/sarda-sarda"; // String split = "/catalogue/NextNext/dataset/sarda-sarda";
//
String[] array = split.split("/"); // String[] array = split.split("/");
//
System.out.println(array.length); // System.out.println(array.length);
//
for (int i = 0; i < array.length; i++) { // for (int i = 0; i < array.length; i++) {
System.out.println(i+" "+array[i]); // System.out.println(i+" "+array[i]);
} // }
//
System.out.println(array[2]); // System.out.println(array[2]);
//
}*/ // }*/
} //}

View File

@ -18,16 +18,15 @@ import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification; import com.google.common.cache.RemovalNotification;
/** /**
* The Class CatalogueApplicationProfilesCache. * The Class LoadingCatalogueApplicationProfilesCache.
* *
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Nov 5, 2018 * Nov 5, 2018
*/ */
public class CatalogueApplicationProfilesCache { public class LoadingCatalogueApplicationProfilesCache {
private static Logger logger = LoggerFactory.getLogger(CatalogueApplicationProfilesCache.class); private static Logger logger = LoggerFactory.getLogger(LoadingCatalogueApplicationProfilesCache.class);
private static LoadingCache<String, String> catalogueApplicationProfiles; private static LoadingCache<String, String> catalogueApplicationProfiles;
static{ static{
@ -38,7 +37,7 @@ public class CatalogueApplicationProfilesCache {
public String load(String vreName) public String load(String vreName)
throws Exception { throws Exception {
logger.info(CatalogueApplicationProfilesCache.class.getSimpleName() +" loaded"); logger.info(LoadingCatalogueApplicationProfilesCache.class.getSimpleName() +" loaded");
return loadApplicationProfiles(vreName); return loadApplicationProfiles(vreName);
} }
@ -49,7 +48,7 @@ public class CatalogueApplicationProfilesCache {
@Override @Override
public void onRemoval(RemovalNotification<String, String> arg0) { public void onRemoval(RemovalNotification<String, String> arg0) {
logger.info(CatalogueApplicationProfilesCache.class.getSimpleName() +" cache expired"); logger.info(LoadingCatalogueApplicationProfilesCache.class.getSimpleName() +" cache expired");
} }
}; };
@ -62,7 +61,7 @@ public class CatalogueApplicationProfilesCache {
ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(UriResolverStartupListener.getContextScope(), true); ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(UriResolverStartupListener.getContextScope(), true);
catalogueApplicationProfiles.asMap().putAll(appPrCatResolver.getHashVreNameScope()); catalogueApplicationProfiles.asMap().putAll(appPrCatResolver.getHashVreNameScope());
logger.info(CatalogueApplicationProfilesCache.class.getSimpleName() +" instancied "+catalogueApplicationProfiles); logger.info(LoadingCatalogueApplicationProfilesCache.class.getSimpleName() +" instancied "+catalogueApplicationProfiles);
logger.info("Pre-Loaded cache is: "+catalogueApplicationProfiles.toString()); logger.info("Pre-Loaded cache is: "+catalogueApplicationProfiles.toString());
} }

View File

@ -20,14 +20,14 @@ import com.google.common.cache.RemovalNotification;
/** /**
* The Class GeoExplorerApplicationURLCache. * The Class LoadingGeoExplorerApplicationURLCache.
* *
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Nov 5, 2018 * Nov 5, 2018
*/ */
public class GeoExplorerApplicationURLCache { public class LoadingGeoExplorerApplicationURLCache {
private static Logger logger = LoggerFactory.getLogger(GeoExplorerApplicationURLCache.class); private static Logger logger = LoggerFactory.getLogger(LoadingGeoExplorerApplicationURLCache.class);
//A cache (Scope, GeoExplorer-URL) //A cache (Scope, GeoExplorer-URL)
private static LoadingCache<String, String> geoExplorerApplicationURLCache; private static LoadingCache<String, String> geoExplorerApplicationURLCache;
@ -38,14 +38,14 @@ public class GeoExplorerApplicationURLCache {
@Override @Override
public String load(String scope) public String load(String scope)
throws Exception { throws Exception {
logger.info(GeoExplorerApplicationURLCache.class.getSimpleName() +" loaded"); logger.info(LoadingGeoExplorerApplicationURLCache.class.getSimpleName() +" loaded");
return loadGeoExplorerApplicationURL(scope); return loadGeoExplorerApplicationURL(scope);
} }
}; };
RemovalListener<String, String> removalListener = new RemovalListener<String, String>() { RemovalListener<String, String> removalListener = new RemovalListener<String, String>() {
public void onRemoval(RemovalNotification<String, String> removal) { public void onRemoval(RemovalNotification<String, String> removal) {
logger.info(GeoExplorerApplicationURLCache.class.getSimpleName() +" cache expired"); logger.info(LoadingGeoExplorerApplicationURLCache.class.getSimpleName() +" cache expired");
} }
}; };
@ -54,7 +54,7 @@ public class GeoExplorerApplicationURLCache {
1, TimeUnit.DAYS).removalListener(removalListener). 1, TimeUnit.DAYS).removalListener(removalListener).
build(loader); build(loader);
logger.info(GeoExplorerApplicationURLCache.class.getSimpleName() +" instancied"); logger.info(LoadingGeoExplorerApplicationURLCache.class.getSimpleName() +" instancied");
} }
/** /**

View File

@ -20,16 +20,15 @@ import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification; import com.google.common.cache.RemovalNotification;
/** /**
* The Class GeonetworkInstanceCache. * The Class LoadingGeonetworkInstanceCache.
* *
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Nov 5, 2018 * Nov 5, 2018
*/ */
public class GeonetworkInstanceCache { public class LoadingGeonetworkInstanceCache {
private static Logger logger = LoggerFactory.getLogger(GeonetworkInstanceCache.class); private static Logger logger = LoggerFactory.getLogger(LoadingGeonetworkInstanceCache.class);
//A cache (Scope, GeonetworkInstance) //A cache (Scope, GeonetworkInstance)
private static LoadingCache<String, GeonetworkInstance> geonetworkInstancesCache; private static LoadingCache<String, GeonetworkInstance> geonetworkInstancesCache;
@ -40,14 +39,14 @@ public class GeonetworkInstanceCache {
@Override @Override
public GeonetworkInstance load(String scope) public GeonetworkInstance load(String scope)
throws Exception { throws Exception {
logger.info(GeonetworkInstanceCache.class.getSimpleName() +" loaded"); logger.info(LoadingGeonetworkInstanceCache.class.getSimpleName() +" loaded");
return loadGeonetworkInstance(scope); return loadGeonetworkInstance(scope);
} }
}; };
RemovalListener<String, GeonetworkInstance> removalListener = new RemovalListener<String, GeonetworkInstance>() { RemovalListener<String, GeonetworkInstance> removalListener = new RemovalListener<String, GeonetworkInstance>() {
public void onRemoval(RemovalNotification<String, GeonetworkInstance> removal) { public void onRemoval(RemovalNotification<String, GeonetworkInstance> removal) {
logger.info(GeonetworkInstanceCache.class.getSimpleName() +" cache expired"); logger.info(LoadingGeonetworkInstanceCache.class.getSimpleName() +" cache expired");
} }
}; };
@ -56,7 +55,7 @@ public class GeonetworkInstanceCache {
1, TimeUnit.DAYS).removalListener(removalListener). 1, TimeUnit.DAYS).removalListener(removalListener).
build(loader); build(loader);
logger.info(GeonetworkInstanceCache.class.getSimpleName() +" instancied"); logger.info(LoadingGeonetworkInstanceCache.class.getSimpleName() +" instancied");
} }

View File

@ -18,15 +18,16 @@ import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification; import com.google.common.cache.RemovalNotification;
/** /**
* The Class GisViewerApplicationURLCache. * The Class LoadingGisViewerApplicationURLCache.
* *
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Nov 5, 2018 * Nov 5, 2018
*/ */
public class GisViewerApplicationURLCache { public class LoadingGisViewerApplicationURLCache {
private static Logger logger = LoggerFactory.getLogger(GisViewerApplicationURLCache.class); private static Logger logger = LoggerFactory.getLogger(LoadingGisViewerApplicationURLCache.class);
//A cache (Scope, GisViewerApplication-URL) //A cache (Scope, GisViewerApplication-URL)
private static LoadingCache<String, String> gisViewerApplicationURLCache; private static LoadingCache<String, String> gisViewerApplicationURLCache;
@ -37,14 +38,14 @@ public class GisViewerApplicationURLCache {
@Override @Override
public String load(String scope) public String load(String scope)
throws Exception { throws Exception {
logger.info(GisViewerApplicationURLCache.class.getSimpleName() +" loaded"); logger.info(LoadingGisViewerApplicationURLCache.class.getSimpleName() +" loaded");
return loadGisViewerApplicationURL(scope); return loadGisViewerApplicationURL(scope);
} }
}; };
RemovalListener<String, String> removalListener = new RemovalListener<String, String>() { RemovalListener<String, String> removalListener = new RemovalListener<String, String>() {
public void onRemoval(RemovalNotification<String, String> removal) { public void onRemoval(RemovalNotification<String, String> removal) {
logger.info(GisViewerApplicationURLCache.class.getSimpleName() +" cache expired"); logger.info(LoadingGisViewerApplicationURLCache.class.getSimpleName() +" cache expired");
} }
}; };
@ -53,7 +54,7 @@ public class GisViewerApplicationURLCache {
1, TimeUnit.DAYS).removalListener(removalListener). 1, TimeUnit.DAYS).removalListener(removalListener).
build(loader); build(loader);
logger.info(GisViewerApplicationURLCache.class.getSimpleName() +" instancied"); logger.info(LoadingGisViewerApplicationURLCache.class.getSimpleName() +" instancied");
} }

View File

@ -15,8 +15,9 @@ import javax.servlet.ServletContextListener;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.annotation.WebListener; import javax.servlet.annotation.WebListener;
import org.gcube.datatransfer.resolver.caches.GeonetworkInstanceCache; import org.gcube.datatransfer.resolver.caches.LoadingCatalogueApplicationProfilesCache;
import org.gcube.datatransfer.resolver.caches.GisViewerApplicationURLCache; import org.gcube.datatransfer.resolver.caches.LoadingGeonetworkInstanceCache;
import org.gcube.datatransfer.resolver.caches.LoadingGisViewerApplicationURLCache;
import org.gcube.datatransfer.resolver.gis.property.ApplicationProfileGenericResourceReader; import org.gcube.datatransfer.resolver.gis.property.ApplicationProfileGenericResourceReader;
import org.gcube.datatransfer.resolver.gis.property.PropertyFileNotFoundException; import org.gcube.datatransfer.resolver.gis.property.PropertyFileNotFoundException;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -70,13 +71,14 @@ public class UriResolverStartupListener implements ServletContextListener {
gisViewerProfile = loadApplicationProfile(event.getServletContext(), GIS_VIEWER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES); gisViewerProfile = loadApplicationProfile(event.getServletContext(), GIS_VIEWER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES);
geoExplorerProfile = loadApplicationProfile(event.getServletContext(), GEO_EXPLORER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES); geoExplorerProfile = loadApplicationProfile(event.getServletContext(), GEO_EXPLORER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES);
new GeonetworkInstanceCache(); new LoadingGeonetworkInstanceCache();
new GisViewerApplicationURLCache(); new LoadingGisViewerApplicationURLCache();
new LoadingCatalogueApplicationProfilesCache();
logger.info("Context initialized with: "); logger.info("Context initialized with: ");
logger.info("Scope: "+contextScope); logger.info("Scope: "+contextScope);
logger.info("GisViewerProfile: "+gisViewerProfile); logger.info("GisViewerProfile: "+gisViewerProfile.getAppId() + " "+gisViewerProfile.getGenericResource());
logger.info("GeoExplorerProfile: "+geoExplorerProfile); logger.info("GeoExplorerProfile: "+geoExplorerProfile. getAppId() + " "+geoExplorerProfile.getGenericResource());
} }
/* (non-Javadoc) /* (non-Javadoc)

View File

@ -18,7 +18,7 @@ import javax.ws.rs.core.Response.Status;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.ResourceCatalogueCodes; import org.gcube.datatransfer.resolver.ResourceCatalogueCodes;
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileNotFoundException; import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileNotFoundException;
import org.gcube.datatransfer.resolver.caches.CatalogueApplicationProfilesCache; import org.gcube.datatransfer.resolver.caches.LoadingCatalogueApplicationProfilesCache;
import org.gcube.datatransfer.resolver.catalogue.CatalogueRequest; import org.gcube.datatransfer.resolver.catalogue.CatalogueRequest;
import org.gcube.datatransfer.resolver.catalogue.resource.ApplicationProfileReaderForCatalogueResolver; import org.gcube.datatransfer.resolver.catalogue.resource.ApplicationProfileReaderForCatalogueResolver;
import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigurationsReader; import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigurationsReader;
@ -51,7 +51,7 @@ public class CatalogueResolver {
//ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(vreName, true); //ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(vreName, true);
String fullScope = CatalogueApplicationProfilesCache.getCache().get(vreName); String fullScope = LoadingCatalogueApplicationProfilesCache.getCache().get(vreName);
logger.debug("Read fullScope: "+fullScope + " for VRE_NAME: "+vreName +" into Application Profile "+ApplicationProfileReaderForCatalogueResolver.RESOURCE_NAME); logger.debug("Read fullScope: "+fullScope + " for VRE_NAME: "+vreName +" into Application Profile "+ApplicationProfileReaderForCatalogueResolver.RESOURCE_NAME);
//String fullScope = appPrCatResolver.getHashVreNameScope().get(vreName); //String fullScope = appPrCatResolver.getHashVreNameScope().get(vreName);

View File

@ -15,9 +15,9 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.caches.GeoExplorerApplicationURLCache; import org.gcube.datatransfer.resolver.caches.LoadingGeoExplorerApplicationURLCache;
import org.gcube.datatransfer.resolver.caches.GeonetworkInstanceCache; import org.gcube.datatransfer.resolver.caches.LoadingGeonetworkInstanceCache;
import org.gcube.datatransfer.resolver.caches.GisViewerApplicationURLCache; import org.gcube.datatransfer.resolver.caches.LoadingGisViewerApplicationURLCache;
import org.gcube.datatransfer.resolver.gis.GeonetworkInstance; import org.gcube.datatransfer.resolver.gis.GeonetworkInstance;
import org.gcube.datatransfer.resolver.gis.MetadataConverter; import org.gcube.datatransfer.resolver.gis.MetadataConverter;
import org.gcube.datatransfer.resolver.gis.entity.GisLayerItem; import org.gcube.datatransfer.resolver.gis.entity.GisLayerItem;
@ -155,11 +155,11 @@ public class GisResolver {
protected String getGisViewerApplicationURL(String scope) throws Exception{ protected String getGisViewerApplicationURL(String scope) throws Exception{
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 = GisViewerApplicationURLCache.getCache().get(scope); String gisViewerAppHostname = LoadingGisViewerApplicationURLCache.getCache().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..");
String url = GisViewerApplicationURLCache.loadGisViewerApplicationURL(scope); String url = LoadingGisViewerApplicationURLCache.loadGisViewerApplicationURL(scope);
GisViewerApplicationURLCache.getCache().put(scope, url); LoadingGisViewerApplicationURLCache.getCache().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
@ -203,13 +203,13 @@ public class GisResolver {
protected GeonetworkInstance getCachedGeonetworkInstance(String scope) throws Exception{ protected GeonetworkInstance getCachedGeonetworkInstance(String scope) throws Exception{
logger.info("Attempt to get the GeonetworkInstance from cache by scope: "+scope); logger.info("Attempt to get the GeonetworkInstance from cache by scope: "+scope);
GeonetworkInstance geonInstance = GeonetworkInstanceCache.getCache().get(scope); GeonetworkInstance geonInstance = LoadingGeonetworkInstanceCache.getCache().get(scope);
if(geonInstance==null){ if(geonInstance==null){
logger.info("GeonetworkInstance is null in cache, reading from library..."); logger.info("GeonetworkInstance is null in cache, reading from library...");
try { try {
geonInstance = GeonetworkInstanceCache.loadGeonetworkInstance(scope); geonInstance = LoadingGeonetworkInstanceCache.loadGeonetworkInstance(scope);
GeonetworkInstanceCache.getCache().put(scope, geonInstance); LoadingGeonetworkInstanceCache.getCache().put(scope, geonInstance);
logger.info("Updated GeonetworkInstance cache! Scope "+scope+" linking "+geonInstance); logger.info("Updated GeonetworkInstance cache! Scope "+scope+" linking "+geonInstance);
} catch (Exception e) { } catch (Exception e) {
logger.error("An error occurred on getting GeonetworkInstance for scope: "+scope, e); logger.error("An error occurred on getting GeonetworkInstance for scope: "+scope, e);
@ -234,11 +234,11 @@ public class GisResolver {
protected String getGeoExplorerApplicationURL(String scope) throws Exception{ protected String getGeoExplorerApplicationURL(String scope) throws Exception{
logger.info("Tentative of recovering geo explorer application hostname from cache for scope: "+scope); logger.info("Tentative of recovering geo explorer application hostname from cache for scope: "+scope);
String geoExplorerApplicationHostname = GeoExplorerApplicationURLCache.getCache().get(scope); String geoExplorerApplicationHostname = LoadingGeoExplorerApplicationURLCache.getCache().get(scope);
if(geoExplorerApplicationHostname==null){ if(geoExplorerApplicationHostname==null){
logger.info("GeoExplorer application hostname is null, reading from application profile.."); logger.info("GeoExplorer application hostname is null, reading from application profile..");
String url = GeoExplorerApplicationURLCache.loadGeoExplorerApplicationURL(scope); String url = LoadingGeoExplorerApplicationURLCache.loadGeoExplorerApplicationURL(scope);
GeoExplorerApplicationURLCache.getCache().put(scope, url); LoadingGeoExplorerApplicationURLCache.getCache().put(scope, url);
logger.info("Updated GeoExplorerApplication cache! Scope "+scope+" linking "+url); logger.info("Updated GeoExplorerApplication cache! Scope "+scope+" linking "+url);
return url; return url;
}else }else

View File

@ -1,43 +1,43 @@
import javax.servlet.ServletException; //import javax.servlet.ServletException;
//
import org.gcube.datatransfer.resolver.GeonetworkRequestDecoder; //import org.gcube.datatransfer.resolver.GeonetworkRequestDecoder;
//
//
/** ///**
* // *
*/ // */
/** ///**
* // *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it // * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jul 27, 2016 // * Jul 27, 2016
*/ // */
public class GeonetworkRequestDecoderTest { //public class GeonetworkRequestDecoderTest {
//
//
//@Test // //@Test
public void test1() throws ServletException{ // public void test1() throws ServletException{
String request = "/geonetwork/gcube|devsec|devVRE#filterpublicids"; // String request = "/geonetwork/gcube|devsec|devVRE#filterpublicids";
System.out.println("Testing request: "+request); // System.out.println("Testing request: "+request);
GeonetworkRequestDecoder gd = new GeonetworkRequestDecoder(request,""); // GeonetworkRequestDecoder gd = new GeonetworkRequestDecoder(request,"");
System.out.println(gd); // System.out.println(gd);
} // }
//
//@Test // //@Test
public void test2() throws ServletException{ // public void test2() throws ServletException{
String request = "/geonetwork/gcube|devsec|devVRE#noauthentication"; // String request = "/geonetwork/gcube|devsec|devVRE#noauthentication";
System.out.println("Testing request: "+request); // System.out.println("Testing request: "+request);
GeonetworkRequestDecoder gd = new GeonetworkRequestDecoder(request,""); // GeonetworkRequestDecoder gd = new GeonetworkRequestDecoder(request,"");
System.out.println(gd); // System.out.println(gd);
} // }
//
//
//@Test // //@Test
public void test3() throws ServletException{ // public void test3() throws ServletException{
String request = "/geonetwork/gcube#filterpublicids"; // String request = "/geonetwork/gcube#filterpublicids";
System.out.println("Testing request: "+request); // System.out.println("Testing request: "+request);
GeonetworkRequestDecoder gd = new GeonetworkRequestDecoder(request,""); // GeonetworkRequestDecoder gd = new GeonetworkRequestDecoder(request,"");
System.out.println(gd); // System.out.println(gd);
} // }
//
//
} //}