bug fixing GeonetworkResolver

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@173912 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-10-31 14:58:37 +00:00
parent 680d468dc9
commit 9b11cb352c
3 changed files with 169 additions and 117 deletions

View File

@ -393,7 +393,7 @@ public class GetResponseRecordFilter {
* @param metadataName the metadata name * @param metadataName the metadata name
* @return the metadata value by file identifier * @return the metadata value by file identifier
*/ */
private static String getMetadataValueByFileIdentifier(String fileIdentifier, String geonetworkURL, String user, String pwd, String metadataName){ public static String getMetadataValueByFileIdentifier(String fileIdentifier, String geonetworkURL, String user, String pwd, String metadataName){
String response = requestXmlMetadataGet(fileIdentifier, geonetworkURL, user, pwd); String response = requestXmlMetadataGet(fileIdentifier, geonetworkURL, user, pwd);

View File

@ -27,11 +27,9 @@ import javax.ws.rs.core.StreamingOutput;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.GeonetworkRequestFilterParameters;
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.SingleFileStreamingOutput; import org.gcube.datatransfer.resolver.SingleFileStreamingOutput;
import org.gcube.datatransfer.resolver.Util;
import org.gcube.datatransfer.resolver.gis.GeonetworkAccessParameter; import org.gcube.datatransfer.resolver.gis.GeonetworkAccessParameter;
import org.gcube.datatransfer.resolver.gis.GeonetworkInstance; import org.gcube.datatransfer.resolver.gis.GeonetworkInstance;
import org.gcube.datatransfer.resolver.gis.GeonetworkServiceInterface; import org.gcube.datatransfer.resolver.gis.GeonetworkServiceInterface;
@ -60,11 +58,17 @@ import org.w3c.dom.Document;
@Path("geonetwork") @Path("geonetwork")
public class GeonetworkResolver { public class GeonetworkResolver {
/**
*
*/
public static final String REPLACED_A_PUBLIC_UUID_PLEASE_IGNORE = "Replaced a public UUID, please ignore";
public static final String REPLACED_UUID_BY_FILTER_PLEASE_IGNORE = "Replaced UUID by "+GeonetworkResolver.class.getSimpleName()+" filters, please ignore";
private static Logger logger = LoggerFactory.getLogger(GeonetworkResolver.class); private static Logger logger = LoggerFactory.getLogger(GeonetworkResolver.class);
public static final String PATH_PARAM_MODE = "mode"; public static final String PATH_PARAM_MODE = "mode";
public static final String PATH_PARAM_REQUEST_DELIMITER = "requestDelimiter"; public static final String PATH_PARAM_REQUEST_DELIMITER = "requestDelimiter";
public static final String PATH_PARAM_OWNER = "owner"; // public static final String PATH_PARAM_OWNER = "owner";
private static final String PATH_PARAM_VISIBILITY = "visibility"; private static final String PATH_PARAM_VISIBILITY = "visibility";
private static final String PATH_PARAM_SCOPE = "scope"; private static final String PATH_PARAM_SCOPE = "scope";
@ -80,6 +84,8 @@ public class GeonetworkResolver {
public static final String UUID = "uuid"; public static final String UUID = "uuid";
public static final String SCOPE_SEPARATOR = "|";
protected Map<String, GeonetworkInstance> cacheGNInstances; protected Map<String, GeonetworkInstance> cacheGNInstances;
private String help = "https://wiki.gcube-system.org/gcube/GCube_Resource_Catalogue#Geonetwork_Resolver"; private String help = "https://wiki.gcube-system.org/gcube/GCube_Resource_Catalogue#Geonetwork_Resolver";
@ -106,18 +112,19 @@ public class GeonetworkResolver {
*/ */
@GET @GET
@Path("{"+PATH_PARAM_SCOPE+"}/{"+PATH_PARAM_MODE+"}/{"+PATH_PARAM_VISIBILITY+"}/{"+PATH_PARAM_OWNER+"}/$${"+PATH_PARAM_REMAINPATH+":(/[^?$]+)?}") @Path("{"+PATH_PARAM_SCOPE+"}/{"+PATH_PARAM_MODE+"}/{"+PATH_PARAM_VISIBILITY+"}/{filterKey}/{filterValue}/$${"+PATH_PARAM_REMAINPATH+":(/[^?$]+)?}")
public Response submitGet(@Context HttpServletRequest req, public Response submitGet(@Context HttpServletRequest req,
@PathParam(PATH_PARAM_SCOPE) @Nullable String scope, @PathParam(PATH_PARAM_SCOPE) @Nullable String scope,
@PathParam(PATH_PARAM_MODE) @Nullable String mode, @PathParam(PATH_PARAM_MODE) @Nullable String mode,
@PathParam(PATH_PARAM_VISIBILITY) @Nullable String visibility, @PathParam(PATH_PARAM_VISIBILITY) @Nullable String visibility,
@PathParam(PATH_PARAM_OWNER) @Nullable String owner, @PathParam("filterKey") @Nullable String filterKey,
@PathParam("filterValue") @Nullable String filterValue,
@PathParam(PATH_PARAM_REMAINPATH) @Nullable String remainPath, @PathParam(PATH_PARAM_REMAINPATH) @Nullable String remainPath,
@QueryParam(QUERY_PARAM_RESET_CACHE_PARAM) @Nullable String resetCache, @QueryParam(QUERY_PARAM_RESET_CACHE_PARAM) @Nullable String resetCache,
@QueryParam(QUERY_PARAM_RESET_CACHED_SCOPE_PARAM) @Nullable String resetScope) { @QueryParam(QUERY_PARAM_RESET_CACHED_SCOPE_PARAM) @Nullable String resetScope) {
logger.info(this.getClass().getSimpleName()+" GET starts..."); logger.info(this.getClass().getSimpleName()+" GET starts...");
logger.info("Params are [mode: "+mode+", scope: "+scope+", visibility: "+visibility+", owner: "+owner+", remainPath: "+remainPath+"]"); logger.info("Params are [mode: "+mode+", scope: "+scope+", visibility: "+visibility+", filterKey: "+filterKey+", filterValue: "+filterValue+", remainPath: "+remainPath+"]");
if(scope==null || scope.isEmpty()){ if(scope==null || scope.isEmpty()){
logger.error("Path Parameter 'scope' not found"); logger.error("Path Parameter 'scope' not found");
@ -129,6 +136,7 @@ public class GeonetworkResolver {
ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'mode'", GeonetworkResolver.class, help); ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'mode'", GeonetworkResolver.class, help);
} }
scope = scope.replaceAll("\\"+SCOPE_SEPARATOR, "/");
mode = mode.toUpperCase(); mode = mode.toUpperCase();
try{ try{
MODE.valueOf(mode); MODE.valueOf(mode);
@ -165,13 +173,13 @@ public class GeonetworkResolver {
resetGeonetoworkInstanceCacheForScope(scope); resetGeonetoworkInstanceCacheForScope(scope);
} }
String fullURL = Util.getFullURL(req); // String fullURL = Util.getFullURL(req);
int index = fullURL.indexOf(GeonetworkRequestFilterParameters.REQUEST_DELIMITIER); // int index = fullURL.indexOf(GeonetworkRequestFilterParameters.REQUEST_DELIMITIER);
int delimiterIndex = index+GeonetworkRequestFilterParameters.REQUEST_DELIMITIER.length(); // int delimiterIndex = index+GeonetworkRequestFilterParameters.REQUEST_DELIMITIER.length();
//BUILDING REMAINING PATH WITHOUT GeonetworkRequestFilterParameters.REQUEST_DELIMITIER // //BUILDING REMAINING PATH WITHOUT GeonetworkRequestFilterParameters.REQUEST_DELIMITIER
if(delimiterIndex<fullURL.length()){ // if(delimiterIndex<fullURL.length()){
remainPath = fullURL.substring(delimiterIndex, fullURL.length()); // remainPath = fullURL.substring(delimiterIndex, fullURL.length());
} // }
logger.info("Remaining path is: "+remainPath); logger.info("Remaining path is: "+remainPath);
String gnGetlURL = null; String gnGetlURL = null;
@ -198,7 +206,8 @@ public class GeonetworkResolver {
logger.info("The base URL is: "+baseURL); logger.info("The base URL is: "+baseURL);
//newQueryString = purgeRemainFromQueryString(remainPath, newQueryString); //newQueryString = purgeRemainFromQueryString(remainPath, newQueryString);
//logger.trace("Purged query string from "+remainPath+" is: "+newQueryString); //logger.trace("Purged query string from "+remainPath+" is: "+newQueryString);
gnGetlURL = baseURL+"?"+req.getQueryString(); String queryString = req.getQueryString()==null || req.getQueryString().isEmpty()?"":"?"+req.getQueryString();
gnGetlURL = baseURL+queryString;
logger.info("Sending get request to URL: "+gnGetlURL); logger.info("Sending get request to URL: "+gnGetlURL);
HttpResponse proxedGNResponse = httpUtils.get(gnGetlURL); HttpResponse proxedGNResponse = httpUtils.get(gnGetlURL);
@ -272,18 +281,18 @@ public class GeonetworkResolver {
// }, CACHE_RESET_DELAY, CACHE_RESET_TIME); // }, CACHE_RESET_DELAY, CACHE_RESET_TIME);
// } // }
/**
* Submit post.
*/
@SuppressWarnings("resource")
@POST @POST
@Path("/{"+PATH_PARAM_SCOPE+":(/[^/?$]+)?}}/{"+PATH_PARAM_MODE+"}/{"+PATH_PARAM_VISIBILITY+"}/{"+PATH_PARAM_OWNER+"}/{"+PATH_PARAM_REQUEST_DELIMITER+"}") @Path("{"+PATH_PARAM_SCOPE+"}/{"+PATH_PARAM_MODE+"}/{"+PATH_PARAM_VISIBILITY+"}/{filterKey}/{filterValue}/$${"+PATH_PARAM_REMAINPATH+":(/[^?$]+)?}")
public Response submitPost(@Context HttpServletRequest req, public Response submitPost(@Context HttpServletRequest req,
@PathParam(PATH_PARAM_SCOPE) @Nullable String scope, @PathParam(PATH_PARAM_SCOPE) @Nullable String scope,
@PathParam(PATH_PARAM_MODE) @Nullable String mode, @PathParam(PATH_PARAM_MODE) @Nullable String mode,
@PathParam(PATH_PARAM_VISIBILITY) @Nullable String visibility, @PathParam(PATH_PARAM_VISIBILITY) @Nullable String visibility,
@PathParam(PATH_PARAM_OWNER) @Nullable String owner, @PathParam("filterKey") @Nullable String filterKey,
@PathParam(PATH_PARAM_REQUEST_DELIMITER) @Nullable String requestDelimiter){ @PathParam("filterValue") @Nullable String filterValue,
@PathParam(PATH_PARAM_REMAINPATH) @Nullable String remainPath,
@QueryParam(QUERY_PARAM_RESET_CACHE_PARAM) @Nullable String resetCache,
@QueryParam(QUERY_PARAM_RESET_CACHED_SCOPE_PARAM) @Nullable String resetScope) {
logger.info(this.getClass().getSimpleName()+" POST starts..."); logger.info(this.getClass().getSimpleName()+" POST starts...");
if(scope==null || scope.isEmpty()){ if(scope==null || scope.isEmpty()){
@ -296,6 +305,7 @@ public class GeonetworkResolver {
ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'mode'", GeonetworkResolver.class, help); ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'mode'", GeonetworkResolver.class, help);
} }
scope = scope.replaceAll("\\"+SCOPE_SEPARATOR, "/");
mode = mode.toUpperCase(); mode = mode.toUpperCase();
try{ try{
MODE.valueOf(mode); MODE.valueOf(mode);
@ -319,19 +329,27 @@ public class GeonetworkResolver {
ExceptionManager.throwWrongParameterException(req, "The 'visibility' parameter must be value of "+toPrint, GeonetworkResolver.class, help); ExceptionManager.throwWrongParameterException(req, "The 'visibility' parameter must be value of "+toPrint, GeonetworkResolver.class, help);
} }
if(requestDelimiter==null || requestDelimiter.compareTo(VALUE_OF_REQUEST_DELIMITIER)!=0){ // if(requestDelimiter==null || requestDelimiter.compareTo(VALUE_OF_REQUEST_DELIMITIER)!=0){
logger.error("Path Parameter to REQUEST_DELIMITIER '"+VALUE_OF_REQUEST_DELIMITIER+"' not found"); // logger.error("Path Parameter to REQUEST_DELIMITIER '"+VALUE_OF_REQUEST_DELIMITIER+"' not found");
ExceptionManager.throwBadRequestException(req, "Path Parameter '"+VALUE_OF_REQUEST_DELIMITIER+"' not found as REQUEST DELIMITER", GeonetworkResolver.class, help); // ExceptionManager.throwBadRequestException(req, "Path Parameter '"+VALUE_OF_REQUEST_DELIMITIER+"' not found as REQUEST DELIMITER", GeonetworkResolver.class, help);
// }
// String fullURL = Util.getFullURL(req);
// int index = fullURL.indexOf(GeonetworkRequestFilterParameters.REQUEST_DELIMITIER);
// int delimiterIndex = index+GeonetworkRequestFilterParameters.REQUEST_DELIMITIER.length();
//BUILDING REMAINING PATH WITHOUT GeonetworkRequestFilterParameters.REQUEST_DELIMITIER
// String remainPath = null;
// if(delimiterIndex<fullURL.length()){
// remainPath = fullURL.substring(delimiterIndex, fullURL.length());
// }
//HOW TO PASS MORE THAN ONE?
Map<String,String> filters = new HashMap<String, String>();
if(filterKey!=null && filterValue!=null){
filters.put(filterKey, filterValue);
logger.debug("Added filter parmas to map filters: "+filters);
} }
String fullURL = Util.getFullURL(req);
int index = fullURL.indexOf(GeonetworkRequestFilterParameters.REQUEST_DELIMITIER);
int delimiterIndex = index+GeonetworkRequestFilterParameters.REQUEST_DELIMITIER.length();
//BUILDING REMAINING PATH WITHOUT GeonetworkRequestFilterParameters.REQUEST_DELIMITIER
String remainPath = null;
if(delimiterIndex<fullURL.length()){
remainPath = fullURL.substring(delimiterIndex, fullURL.length());
}
String gnCSWlURL = null; String gnCSWlURL = null;
try { try {
@ -393,12 +411,15 @@ public class GeonetworkResolver {
//HARVESTED LAYERS //HARVESTED LAYERS
}else{ }else{
logger.debug("Getting "+MODE.HARVEST+" layers, I'm using the owner: '"+owner +"' passed as parameter to filter layer/s returned.."); // logger.debug("Getting "+MODE.HARVEST+" layers, I'm using the owner: '"+owner +"' passed as parameter to filter layer/s returned..");
if(owner==null || owner.isEmpty()){ // if(owner==null || owner.isEmpty()){
String error = "Harvest owner is missing. It is not possible to filter layers for the request "+MODE.HARVEST + " in the scope: "+scope+", without a valid owner as input"; // String error = "Harvest owner is missing. It is not possible to filter layers for the request "+MODE.HARVEST + " in the scope: "+scope+", without a valid owner as input";
logger.error(error); // logger.error(error);
ExceptionManager.throwBadRequestException(req, error, GeonetworkResolver.class, help); // ExceptionManager.throwBadRequestException(req, error, GeonetworkResolver.class, help);
} // }
filters.put("isHarvested", "y");
logger.debug("Getting "+MODE.HARVEST+" layers, I'm using filters ["+filters+"]");
} }
if(account.getUser()!=null){ if(account.getUser()!=null){
@ -413,16 +434,18 @@ public class GeonetworkResolver {
//VRE LAYERS //VRE LAYERS
if(mode.equals(MODE.VRE)){ if(mode.equals(MODE.VRE)){
logger.debug("Getting "+MODE.VRE+" layers, the VRE account: "+account.getUser() +" will be used as owner user for filtering... Is it right?"); logger.debug("Getting "+MODE.VRE+" layers, the VRE account: "+account.getUser() +" will be used as owner user for filtering... Is it right?");
owner = account.getUser(); filters.put("ownername", account.getUser());
//HARVESTED LAYERS //HARVESTED LAYERS
}else{ }else{
logger.debug("Getting "+MODE.HARVEST+" layers, I'm using the owner: '"+owner +"' passed as parameter to filter layer/s returned.."); // logger.debug("Getting "+MODE.HARVEST+" layers, I'm using the owner: '"+owner +"' passed as parameter to filter layer/s returned..");
if(owner==null || owner.isEmpty()){ // if(owner==null || owner.isEmpty()){
String error = "Harvest owner is missing. It is not possible to filter layers for the request "+MODE.HARVEST + " in the scope: "+scope+", without a valid owner as input"; // String error = "Harvest owner is missing. It is not possible to filter layers for the request "+MODE.HARVEST + " in the scope: "+scope+", without a valid owner as input";
logger.error(error); // logger.error(error);
ExceptionManager.throwBadRequestException(req, error, GeonetworkResolver.class, help); // ExceptionManager.throwBadRequestException(req, error, GeonetworkResolver.class, help);
} // }
filters.put("isHarvested", "y");
logger.debug("Getting "+MODE.HARVEST+" layers, I added 'isHarvested = y' to filters ["+filters+"]");
} }
} }
@ -446,33 +469,68 @@ public class GeonetworkResolver {
ReusableInputStream reus = new ReusableInputStream(in); ReusableInputStream reus = new ReusableInputStream(in);
if(visibility.equals(VISIBILITY.PRV)){ if(visibility.equals(VISIBILITY.PRV)){
logger.info("Private VISIBILITY performing so getting public file identifiers to apply filtering.."); logger.info("Private VISIBILITY requested, retrieving public file identifiers to apply filtering..");
FilterGetRecords filterGetRecords = new FilterGetRecords(byteArray.toString()); FilterGetRecords filterGetRecords = new FilterGetRecords(byteArray.toString());
if(filterGetRecords.getFoundPublicIds()!=null && filterGetRecords.getFoundPublicIds().size()>0){ if(filterGetRecords.getFoundPublicIds()!=null && filterGetRecords.getFoundPublicIds().size()>0){
logger.info("I'm removing list of public IDs with "+filterGetRecords.getFoundPublicIds().size() +" item/s. Is it right?"); logger.info("I'm removing list of public IDs with "+filterGetRecords.getFoundPublicIds().size() +" item/s. Is it right?");
in = GetResponseRecordFilter.overrideResponseIdsByListIds(reus, filterGetRecords.getFoundPublicIds(), "Replaced a public UUID, please ignore"); in = GetResponseRecordFilter.overrideResponseIdsByListIds(reus, filterGetRecords.getFoundPublicIds(), REPLACED_A_PUBLIC_UUID_PLEASE_IGNORE);
} }
}else { }
// else {
//
// logger.info("Public VISIBILITY perfoming check on ownership...");
// Document doc = GetResponseRecordFilter.inputStreamToW3CDocument(reus);
// List<String> fileIdentifiers = GetResponseRecordFilter.getTextContentStringsForTagName(doc, "gmd:fileIdentifier");
// List<String> noMatchingOwner = new ArrayList<String>();
// for (String fileId : fileIdentifiers) {
// String own = GetResponseRecordFilter.getMetaCategoryByFileIdentifier(fileId, config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(), config.getAdminAccount().getPassword());
// //String own = GetResponseRecordFilter.getMetaOwnerNameByFileIdentifier(fileId, config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(), config.getAdminAccount().getPassword());
// if(own.compareTo(owner)!=0){
// logger.debug("Owner of file Identifier "+fileId+" not matching the owner passed: "+owner+", removing it..");
// noMatchingOwner.add(fileId);
// }
// }
// if(noMatchingOwner.size()>0){
// logger.info("Removing "+noMatchingOwner.size()+" layer/s not macthing the owner: "+owner);
// in = GetResponseRecordFilter.overrideResponseIdsByListIds(reus, noMatchingOwner, "Replaced UUID owned by another user, please ignore");
// }else{
// logger.info("No replace on UUIDs was applied for the owner: "+owner);
// in = reus;
// }
// }
logger.info("Public VISIBILITY perfoming check on ownership..."); if(filters.size()>0){
logger.info("Applying filtering on geonet:info... filter/s used: "+filters);
Document doc = GetResponseRecordFilter.inputStreamToW3CDocument(reus); Document doc = GetResponseRecordFilter.inputStreamToW3CDocument(reus);
List<String> fileIdentifiers = GetResponseRecordFilter.getTextContentStringsForTagName(doc, "gmd:fileIdentifier"); List<String> fileIdentifiers = GetResponseRecordFilter.getTextContentStringsForTagName(doc, "gmd:fileIdentifier");
List<String> noMatchingOwner = new ArrayList<String>(); List<String> noMatchingFilter = new ArrayList<String>();
for (String fileId : fileIdentifiers) { for (String fileId : fileIdentifiers) {
String own = GetResponseRecordFilter.getMetaCategoryByFileIdentifier(fileId, config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(), config.getAdminAccount().getPassword());
//String own = GetResponseRecordFilter.getMetaOwnerNameByFileIdentifier(fileId, config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(), config.getAdminAccount().getPassword()); //CKECKING THE FILTERS
if(own.compareTo(owner)!=0){ for (String fkey : filters.keySet()) {
logger.debug("Owner of file Identifier "+fileId+" not matching the owner passed: "+owner+", removing it.."); String value = GetResponseRecordFilter.getMetadataValueByFileIdentifier(fileId, config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(), config.getAdminAccount().getPassword(), fkey);
noMatchingOwner.add(fileId); //String own = GetResponseRecordFilter.getMetaOwnerNameByFileIdentifier(fileId, config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(), config.getAdminAccount().getPassword());
String fValue = filters.get(fkey);
if(value!=null && value.compareTo(fValue)!=0){
logger.trace(fkey +" of File Identifier "+fileId+" not matching the filter: "+fkey+" with value: "+fValue+", adding it to list to remove file identifier and exit from loop..");
noMatchingFilter.add(fileId);
//WHEN I ADD THE FILE IDENTIFIER TO FILTERED ID, I CAN EXIT FROM CKECKING FILTERS LOOP
break;
}
} }
} }
if(noMatchingOwner.size()>0){
logger.info("Removing "+noMatchingOwner.size()+" layer/s not macthing the owner: "+owner); if(noMatchingFilter.size()>0){
in = GetResponseRecordFilter.overrideResponseIdsByListIds(reus, noMatchingOwner, "Replaced UUID owned by another user, please ignore"); logger.info("Removing "+noMatchingFilter.size()+" layer/s that not macthing the filters: "+filters);
//Document doc2 = GetResponseRecordFilter.inputStreamToW3CDocument(reus);
in = GetResponseRecordFilter.overrideResponseIdsByListIds(reus, noMatchingFilter, REPLACED_UUID_BY_FILTER_PLEASE_IGNORE);
//in = GetResponseRecordFilter.w3CDocumentToInputStream(doc);
}else{ }else{
logger.info("No replace on UUIDs was applied for the owner: "+owner); logger.info("No replace on UUIDs was applied from filters: "+filters);
in = reus; in = reus;
} }
} }
ReusableInputStream reusIs = new ReusableInputStream(in); ReusableInputStream reusIs = new ReusableInputStream(in);
@ -484,11 +542,6 @@ public class GeonetworkResolver {
//.header(ConstantsResolver.CONTENT_DISPOSITION,"attachment; filename = \""+fileName+"\"") //.header(ConstantsResolver.CONTENT_DISPOSITION,"attachment; filename = \""+fileName+"\"")
.header(ConstantsResolver.CONTENT_TYPE, httpUtils.getLastContentType()).build(); .header(ConstantsResolver.CONTENT_TYPE, httpUtils.getLastContentType()).build();
//int bytes = IOUtils.copy(reusIs, out);
//logger.trace("POST - RETURN : "+IOUtils.toString(reusIs));
// if(bytes==0)
// logger.warn("ResponseBody is empty, returning empty resp");
}catch(Exception e){ }catch(Exception e){
logger.error("Error on copy the response to send to client: ", e); logger.error("Error on copy the response to send to client: ", e);
ExceptionManager.throwInternalErrorException(req, "Error on copy the response!", GeonetworkResolver.class, help); ExceptionManager.throwInternalErrorException(req, "Error on copy the response!", GeonetworkResolver.class, help);
@ -518,31 +571,31 @@ public class GeonetworkResolver {
} }
/** // /**
* Purge remain from query string. // * Purge remain from query string.
* // *
* @param remain_value the scope // * @param remain_value the scope
* @param queryString the query string // * @param queryString the query string
* @return the string // * @return the string
*/ // */
private static String purgeRemainFromQueryString(String remain_value, String queryString){ // private static String purgeRemainFromQueryString(String remain_value, String queryString){
// SCOPE is: /gcube/devsec/devVRE //// SCOPE is: /gcube/devsec/devVRE
// [INFO ] 2016-04-05 15:01:42,808 org.gcube.datatransfer.resolver.gis.geonetwork.GeonetworkResolver - //// [INFO ] 2016-04-05 15:01:42,808 org.gcube.datatransfer.resolver.gis.geonetwork.GeonetworkResolver -
// Query String is: scope=/gcube/devsec/devVRE&version=2.0.2&request=GetCapabilities&service=CSW //// Query String is: scope=/gcube/devsec/devVRE&version=2.0.2&request=GetCapabilities&service=CSW
int start = queryString.indexOf(PATH_PARAM_REMAINPATH+"="); // int start = queryString.indexOf(PATH_PARAM_REMAINPATH+"=");
//
if(start>=0){ // if(start>=0){
int end = queryString.indexOf("&", start); // int end = queryString.indexOf("&", start);
//
if(end==-1 && queryString.length()==(PATH_PARAM_REMAINPATH+"="+remain_value).length()){ //SCOPE IS THE UNIQUE PARAMETER INTO QUETY STRING // if(end==-1 && queryString.length()==(PATH_PARAM_REMAINPATH+"="+remain_value).length()){ //SCOPE IS THE UNIQUE PARAMETER INTO QUETY STRING
logger.debug("Scope is the unique parameter, returning empty query string"); // logger.debug("Scope is the unique parameter, returning empty query string");
return ""; // return "";
}else if(end<queryString.length()) // }else if(end<queryString.length())
return queryString.substring(end+1, queryString.length()); // return queryString.substring(end+1, queryString.length());
} // }
//
return queryString; // return queryString;
} // }
/** /**
* Discovery geonetwork instance. * Discovery geonetwork instance.
@ -558,31 +611,31 @@ public class GeonetworkResolver {
} }
/** // /**
* Purge scope from query string. // * Purge scope from query string.
* // *
* @param scope_value the scope_value // * @param scope_value the scope_value
* @param queryString the query string // * @param queryString the query string
* @return the string // * @return the string
*/ // */
private static String purgeScopeFromQueryString(String scope_value, String queryString){ // private static String purgeScopeFromQueryString(String scope_value, String queryString){
// SCOPE is: /gcube/devsec/devVRE //// SCOPE is: /gcube/devsec/devVRE
// [INFO ] 2016-04-05 15:01:42,808 org.gcube.datatransfer.resolver.gis.geonetwork.GeonetworkResolver - //// [INFO ] 2016-04-05 15:01:42,808 org.gcube.datatransfer.resolver.gis.geonetwork.GeonetworkResolver -
// Query String is: scope=/gcube/devsec/devVRE&version=2.0.2&request=GetCapabilities&service=CSW //// Query String is: scope=/gcube/devsec/devVRE&version=2.0.2&request=GetCapabilities&service=CSW
int start = queryString.indexOf(PATH_PARAM_SCOPE+"="); // int start = queryString.indexOf(PATH_PARAM_SCOPE+"=");
//
if(start>=0){ // if(start>=0){
int end = queryString.indexOf("&", start); // int end = queryString.indexOf("&", start);
//
if(end==-1 && queryString.length()==(PATH_PARAM_SCOPE+"="+scope_value).length()){ //SCOPE IS THE UNIQUE PARAMETER INTO QUETY STRING // if(end==-1 && queryString.length()==(PATH_PARAM_SCOPE+"="+scope_value).length()){ //SCOPE IS THE UNIQUE PARAMETER INTO QUETY STRING
logger.debug("Scope is the unique parameter, returning empty query string"); // logger.debug("Scope is the unique parameter, returning empty query string");
return ""; // return "";
}else if(end<queryString.length()) // }else if(end<queryString.length())
return queryString.substring(end+1, queryString.length()); // return queryString.substring(end+1, queryString.length());
} // }
//
return queryString; // return queryString;
} // }
/** /**
* Reset geonetowork instance cache for scope. * Reset geonetowork instance cache for scope.

View File

@ -17,7 +17,6 @@ import java.util.Map;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -125,7 +124,7 @@ public class TestResolvers {
* Storage hub test. * Storage hub test.
* @throws Exception * @throws Exception
*/ */
@Test //@Test
public void catalogueResolverTest() throws Exception{ public void catalogueResolverTest() throws Exception{
String entityName = "sarda-sarda"; String entityName = "sarda-sarda";