Start working on task #9538
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@152545 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
23e94b337a
commit
50b1839a5e
|
@ -88,7 +88,13 @@
|
||||||
</Changeset>
|
</Changeset>
|
||||||
<Changeset component="org.gcube.data-transfer.uri-resolver.1-13-0"
|
<Changeset component="org.gcube.data-transfer.uri-resolver.1-13-0"
|
||||||
date="2017-07-03">
|
date="2017-07-03">
|
||||||
<Change>[Feature #9108] Edit the GenericResource (ApplicationProfile-Gis Viewer Application)
|
<Change>[Feature #9108] Edit the GenericResource
|
||||||
|
(ApplicationProfile-Gis Viewer Application)
|
||||||
|
</Change>
|
||||||
|
</Changeset>
|
||||||
|
<Changeset component="org.gcube.data-transfer.uri-resolver.1-14-0"
|
||||||
|
date="2017-08-30">
|
||||||
|
<Change>[Task #9538] Geonetwork-Uri Resolver enhancement: provide new filters and improve current ones
|
||||||
</Change>
|
</Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
</ReleaseNotes>
|
</ReleaseNotes>
|
2
pom.xml
2
pom.xml
|
@ -8,7 +8,7 @@
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>org.gcube.data.transfer</groupId>
|
<groupId>org.gcube.data.transfer</groupId>
|
||||||
<artifactId>uri-resolver</artifactId>
|
<artifactId>uri-resolver</artifactId>
|
||||||
<version>1.13.0-SNAPSHOT</version>
|
<version>1.14.0-SNAPSHOT</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<description>The URI Resolver is an HTTP URI resolver implemented as an HTTP servlet which gives access trough HTTP to different protocols URIs. </description>
|
<description>The URI Resolver is an HTTP URI resolver implemented as an HTTP servlet which gives access trough HTTP to different protocols URIs. </description>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.datatransfer.resolver;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
* Aug 29, 2017
|
||||||
|
*/
|
||||||
|
public class BadRequestException extends ServletException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 567117691399245474L;
|
||||||
|
|
||||||
|
public BadRequestException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BadRequestException(String arg0){
|
||||||
|
super(arg0);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,109 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.datatransfer.resolver;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class GeonetworkRequestCriteria.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
* Jun 15, 2016
|
||||||
|
*/
|
||||||
|
public class CopyOfGeonetworkRequestCriteria {
|
||||||
|
|
||||||
|
private String scope;
|
||||||
|
private boolean valueOfFilterPublicIds;
|
||||||
|
private boolean authOnGeonetwork;
|
||||||
|
private boolean noAuthOnGeonetwork;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new geonetwork request criteria.
|
||||||
|
*
|
||||||
|
* @param scope the scope
|
||||||
|
* @param valueOfFilterPublicIds the value of filter public ids
|
||||||
|
* @param noAuthOnGeonetowrk the no auth on geonetowrk
|
||||||
|
*/
|
||||||
|
public CopyOfGeonetworkRequestCriteria(String scope, boolean valueOfFilterPublicIds, boolean noAuthOnGeonetowrk){
|
||||||
|
this.scope = scope;
|
||||||
|
this.valueOfFilterPublicIds = valueOfFilterPublicIds;
|
||||||
|
this.noAuthOnGeonetwork = noAuthOnGeonetowrk;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if is no auth on geonetwork.
|
||||||
|
*
|
||||||
|
* @return the noAuthOnGeonetwork
|
||||||
|
*/
|
||||||
|
public boolean isNoAuthOnGeonetwork() {
|
||||||
|
|
||||||
|
return noAuthOnGeonetwork;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the scope.
|
||||||
|
*
|
||||||
|
* @return the scope
|
||||||
|
*/
|
||||||
|
public String getScope() {
|
||||||
|
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if is value of filter public ids.
|
||||||
|
*
|
||||||
|
* @return the valueOfFilterPublicIds
|
||||||
|
*/
|
||||||
|
public boolean isValueOfFilterPublicIds() {
|
||||||
|
|
||||||
|
return valueOfFilterPublicIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the scope.
|
||||||
|
*
|
||||||
|
* @param scope the scope to set
|
||||||
|
*/
|
||||||
|
public void setScope(String scope) {
|
||||||
|
|
||||||
|
this.scope = scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of filter public ids.
|
||||||
|
*
|
||||||
|
* @param valueOfFilterPublicIds the valueOfFilterPublicIds to set
|
||||||
|
*/
|
||||||
|
public void setValueOfFilterPublicIds(boolean valueOfFilterPublicIds) {
|
||||||
|
|
||||||
|
this.valueOfFilterPublicIds = valueOfFilterPublicIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Object#toString()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("GeonetworkRequestCriteria [scope=");
|
||||||
|
builder.append(scope);
|
||||||
|
builder.append(", valueOfFilterPublicIds=");
|
||||||
|
builder.append(valueOfFilterPublicIds);
|
||||||
|
builder.append(", authOnGeonetwork=");
|
||||||
|
builder.append(authOnGeonetwork);
|
||||||
|
builder.append(", noAuthOnGeonetwork=");
|
||||||
|
builder.append(noAuthOnGeonetwork);
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -3,6 +3,9 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.datatransfer.resolver;
|
package org.gcube.datatransfer.resolver;
|
||||||
|
|
||||||
|
import org.gcube.datatransfer.resolver.GeonetworkRequestFilterParameters.MODE;
|
||||||
|
import org.gcube.datatransfer.resolver.GeonetworkRequestFilterParameters.VISIBILITY;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class GeonetworkRequestCriteria.
|
* The Class GeonetworkRequestCriteria.
|
||||||
|
@ -13,38 +16,26 @@ package org.gcube.datatransfer.resolver;
|
||||||
public class GeonetworkRequestCriteria {
|
public class GeonetworkRequestCriteria {
|
||||||
|
|
||||||
private String scope;
|
private String scope;
|
||||||
private boolean valueOfFilterPublicIds;
|
private MODE mode;
|
||||||
private boolean authOnGeonetwork;
|
private String owner; //This is optional
|
||||||
private boolean noAuthOnGeonetwork;
|
private VISIBILITY visibility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new geonetwork request criteria.
|
* @param scope
|
||||||
*
|
* @param mode
|
||||||
* @param scope the scope
|
* @param owner
|
||||||
* @param valueOfFilterPublicIds the value of filter public ids
|
* @param visibility
|
||||||
* @param noAuthOnGeonetowrk the no auth on geonetowrk
|
|
||||||
*/
|
*/
|
||||||
public GeonetworkRequestCriteria(String scope, boolean valueOfFilterPublicIds, boolean noAuthOnGeonetowrk){
|
public GeonetworkRequestCriteria(
|
||||||
|
String scope, MODE mode, String owner, VISIBILITY visibility) {
|
||||||
|
|
||||||
|
super();
|
||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
this.valueOfFilterPublicIds = valueOfFilterPublicIds;
|
this.mode = mode;
|
||||||
this.noAuthOnGeonetwork = noAuthOnGeonetowrk;
|
this.owner = owner;
|
||||||
|
this.visibility = visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if is no auth on geonetwork.
|
|
||||||
*
|
|
||||||
* @return the noAuthOnGeonetwork
|
|
||||||
*/
|
|
||||||
public boolean isNoAuthOnGeonetwork() {
|
|
||||||
|
|
||||||
return noAuthOnGeonetwork;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the scope.
|
|
||||||
*
|
|
||||||
* @return the scope
|
* @return the scope
|
||||||
*/
|
*/
|
||||||
public String getScope() {
|
public String getScope() {
|
||||||
|
@ -52,21 +43,31 @@ public class GeonetworkRequestCriteria {
|
||||||
return scope;
|
return scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if is value of filter public ids.
|
* @return the mode
|
||||||
*
|
|
||||||
* @return the valueOfFilterPublicIds
|
|
||||||
*/
|
*/
|
||||||
public boolean isValueOfFilterPublicIds() {
|
public MODE getMode() {
|
||||||
|
|
||||||
return valueOfFilterPublicIds;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the owner
|
||||||
|
*/
|
||||||
|
public String getOwner() {
|
||||||
|
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the visibility
|
||||||
|
*/
|
||||||
|
public VISIBILITY getVisibility() {
|
||||||
|
|
||||||
|
return visibility;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the scope.
|
|
||||||
*
|
|
||||||
* @param scope the scope to set
|
* @param scope the scope to set
|
||||||
*/
|
*/
|
||||||
public void setScope(String scope) {
|
public void setScope(String scope) {
|
||||||
|
@ -74,18 +75,29 @@ public class GeonetworkRequestCriteria {
|
||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the value of filter public ids.
|
* @param mode the mode to set
|
||||||
*
|
|
||||||
* @param valueOfFilterPublicIds the valueOfFilterPublicIds to set
|
|
||||||
*/
|
*/
|
||||||
public void setValueOfFilterPublicIds(boolean valueOfFilterPublicIds) {
|
public void setMode(MODE mode) {
|
||||||
|
|
||||||
this.valueOfFilterPublicIds = valueOfFilterPublicIds;
|
this.mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param owner the owner to set
|
||||||
|
*/
|
||||||
|
public void setOwner(String owner) {
|
||||||
|
|
||||||
|
this.owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param visibility the visibility to set
|
||||||
|
*/
|
||||||
|
public void setVisibility(VISIBILITY visibility) {
|
||||||
|
|
||||||
|
this.visibility = visibility;
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
|
@ -96,14 +108,16 @@ public class GeonetworkRequestCriteria {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("GeonetworkRequestCriteria [scope=");
|
builder.append("GeonetworkRequestCriteria [scope=");
|
||||||
builder.append(scope);
|
builder.append(scope);
|
||||||
builder.append(", valueOfFilterPublicIds=");
|
builder.append(", mode=");
|
||||||
builder.append(valueOfFilterPublicIds);
|
builder.append(mode);
|
||||||
builder.append(", authOnGeonetwork=");
|
builder.append(", owner=");
|
||||||
builder.append(authOnGeonetwork);
|
builder.append(owner);
|
||||||
builder.append(", noAuthOnGeonetwork=");
|
builder.append(", visibility=");
|
||||||
builder.append(noAuthOnGeonetwork);
|
builder.append(visibility);
|
||||||
builder.append("]");
|
builder.append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@ package org.gcube.datatransfer.resolver;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.gcube.datatransfer.resolver.GeonetworkRequestFilterParameters.MODE;
|
||||||
|
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;
|
||||||
|
@ -34,7 +35,7 @@ public class GeonetworkRequestDecoder {
|
||||||
|
|
||||||
public static final Logger logger = LoggerFactory.getLogger(GeonetworkRequestDecoder.class);
|
public static final Logger logger = LoggerFactory.getLogger(GeonetworkRequestDecoder.class);
|
||||||
|
|
||||||
private String newURI;
|
private String gnResolverUriRequest;
|
||||||
|
|
||||||
private GeonetworkRequestCriteria geonetworkRequestCriteria;
|
private GeonetworkRequestCriteria geonetworkRequestCriteria;
|
||||||
|
|
||||||
|
@ -46,12 +47,44 @@ public class GeonetworkRequestDecoder {
|
||||||
* @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{
|
||||||
String path = theServletPath;
|
|
||||||
String pathWithoutGN = path.substring(UriResolverRewriteFilter.SERVLET_GEONETWORK.length()+1, path.length());
|
int index = theServletPath.indexOf(GeonetworkRequestFilterParameters.REQUEST_DELIMITIER);
|
||||||
|
|
||||||
|
if(index==-1)
|
||||||
|
throw new BadRequestException("Invalid request. Your request must append the '"+GeonetworkRequestFilterParameters.REQUEST_DELIMITIER+"' as final delimiter");
|
||||||
|
|
||||||
|
int delimiterIndex = index+GeonetworkRequestFilterParameters.REQUEST_DELIMITIER.length();
|
||||||
|
|
||||||
|
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);
|
||||||
|
logger.info("performing query by filters: "+geonetworkRequestCriteria);
|
||||||
|
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();
|
||||||
|
|
||||||
|
gnResolverUriRequest = UriResolverRewriteFilter.SERVLET_GEONETWORK + "?"
|
||||||
|
+ GeonetworkResolver.SCOPE + "=" + geonetworkRequestCriteria.getScope() +"&"
|
||||||
|
+ GeonetworkRequestFilterParameters.MODE.class.getSimpleName() +"="+geonetworkRequestCriteria.getMode() +"&"
|
||||||
|
+ GeonetworkRequestFilterParameters.VISIBILITY.class.getSimpleName()+"="+geonetworkRequestCriteria.getVisibility();
|
||||||
|
|
||||||
|
if(geonetworkRequestCriteria.getOwner()!=null){
|
||||||
|
gnResolverUriRequest+="&"+GeonetworkRequestFilterParameters.OWNER_PARAM +"="+geonetworkRequestCriteria.getOwner();
|
||||||
|
}
|
||||||
|
|
||||||
|
//BUILDING REMAINING PATH WITHOUT GeonetworkRequestFilterParameters.REQUEST_DELIMITIER
|
||||||
|
if(delimiterIndex<theServletPath.length()){
|
||||||
|
String remainPath = theServletPath.substring(delimiterIndex, theServletPath.length());
|
||||||
|
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("/");
|
String[] params = pathWithoutGN.split("/");
|
||||||
if(params[0]==null || params[0].isEmpty()){
|
if(params[0]==null || params[0].isEmpty()){
|
||||||
logger.error("Scope is null or empty, you must set a valid scope /geonetwork/root_vo_vre");
|
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");
|
throw new ServletException("Scope is null or empty, you must set a valid scope /geonetwork/root"+SCOPE_SEPARATOR+"vo"+SCOPE_SEPARATOR+"vre");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,59 +93,127 @@ public class GeonetworkRequestDecoder {
|
||||||
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();
|
||||||
logger.debug(GeonetworkResolver.PARAMETER_FILTER_PUBLIC_IDS +" is: "+geonetworkRequestCriteria.isValueOfFilterPublicIds());
|
logger.debug(GeonetworkResolver.PARAMETER_FILTER_PUBLIC_IDS +" is: "+geonetworkRequestCriteria.isValueOfFilterPublicIds());
|
||||||
logger.debug(GeonetworkResolver.PARAMETER_NO_AUTHENTICATION +" is: "+geonetworkRequestCriteria.isNoAuthOnGeonetwork());
|
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())
|
||||||
|
// newURI+="&"+queryString;
|
||||||
|
|
||||||
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())
|
|
||||||
newURI+="&"+queryString;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the geonetwork request criteria.
|
* Gets the geonetwork request criteria.
|
||||||
* Parses a request like root_vo_vre#filterPublicIds or root_vo_vre
|
|
||||||
|
* Creates a request criteria from input parameter pathWithoutGN
|
||||||
|
* The parameter pathWithoutGN should be an ordered string (like REST request):
|
||||||
|
* MODE/SCOPE/VISIBILITY/OWNER
|
||||||
|
* MODE must be: {@link MODE}
|
||||||
|
* SCOPE must be: ROOT|VO|VRE
|
||||||
|
* VISIBILITY must be: {@link VISIBILITY}
|
||||||
|
* OWNER (is optional): filter by owner
|
||||||
|
* @param pathWithoutGN the path without Geonetwork base URL
|
||||||
*
|
*
|
||||||
* @param request the request
|
|
||||||
* @return the geonetwork request criteria
|
* @return the geonetwork request criteria
|
||||||
|
* @throws ServletException the servlet exception
|
||||||
*/
|
*/
|
||||||
private static GeonetworkRequestCriteria getGeonetworkRequestCriteria(String request){
|
private static GeonetworkRequestCriteria getGeonetworkRequestCriteria(String pathWithoutGN) throws ServletException{
|
||||||
logger.debug("Read request: "+request);
|
|
||||||
int index = request.indexOf(UriResolverRewriteFilter.REQUEST_PARAMETER_SEPARATOR);
|
String[] params = pathWithoutGN.split("/");
|
||||||
String scope = "";
|
MODE mode = null;
|
||||||
boolean filterPublicIds = false;
|
String theScope = null;
|
||||||
boolean authOnGN = false;
|
VISIBILITY visibility = null;
|
||||||
logger.trace("Index of "+UriResolverRewriteFilter.REQUEST_PARAMETER_SEPARATOR+ " is "+index);
|
String owner = null;
|
||||||
if(index!=-1){
|
|
||||||
scope = request.substring(0,index);
|
if(params.length < 3){
|
||||||
filterPublicIds = StringUtils.containsIgnoreCase(request,UriResolverRewriteFilter.PARAMETER_FILTER_PUBLIC_IDS);
|
throw new BadRequestException("Bad request. Read the request "+pathWithoutGN+". You must pass a valid request like [GEONETWORK_BASE_URL]/SCOPE/MODE/VISIBILITY/OWNER");
|
||||||
authOnGN = StringUtils.containsIgnoreCase(request,UriResolverRewriteFilter.PARAMETER_NO_AUTHENTICATION);
|
}
|
||||||
|
|
||||||
|
//SCOPE
|
||||||
|
if(params[0]!=null && !params[0].isEmpty()){
|
||||||
|
theScope = params[0];
|
||||||
|
logger.debug("Read parameter scope: "+theScope);
|
||||||
|
theScope = theScope.replaceAll("\\"+SCOPE_SEPARATOR, "/");
|
||||||
|
if (!theScope.startsWith("/"))
|
||||||
|
theScope="/"+theScope;
|
||||||
|
}else{
|
||||||
|
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");
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
//MODE
|
||||||
|
if(params[1]!=null && !params[1].isEmpty()){
|
||||||
|
String modeTU = params[1].toUpperCase();
|
||||||
|
logger.debug("Read parameter mode (to upper case): "+modeTU);
|
||||||
|
try{
|
||||||
|
mode = MODE.valueOf(modeTU);
|
||||||
|
if(mode==null){
|
||||||
|
logger.error("Mode is null");
|
||||||
|
throw new Exception("Mode is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("MODE IS: "+mode);
|
||||||
|
|
||||||
|
}catch (Exception e) {
|
||||||
|
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");
|
||||||
|
}
|
||||||
}else
|
}else
|
||||||
scope = request;
|
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("/"+scope.replaceAll("\\"+SCOPE_SEPARATOR, "/"), filterPublicIds, authOnGN);
|
//VISIBILITY
|
||||||
|
if(params[2]!=null && !params[2].isEmpty()){
|
||||||
|
String visTU = params[2].toUpperCase();
|
||||||
|
logger.debug("Read parameter mode (to upper case): "+visTU);
|
||||||
|
try{
|
||||||
|
visibility = VISIBILITY.valueOf(visTU);
|
||||||
|
if(visibility==null){
|
||||||
|
logger.error("VISIBILITY is null");
|
||||||
|
throw new Exception("VISIBILITY is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("VISIBILITY IS: "+visibility);
|
||||||
|
|
||||||
|
}catch (Exception e) {
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}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");
|
||||||
|
|
||||||
|
|
||||||
|
//OWNER
|
||||||
|
if(params.length > 3 && params[3]!=null && params[3]!=GeonetworkRequestFilterParameters.REQUEST_DELIMITIER){
|
||||||
|
owner = params[3];
|
||||||
|
logger.debug("Read parameter owner: "+owner);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new GeonetworkRequestCriteria(theScope, mode, owner, visibility);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the new uri.
|
* Gets the geonetwork resolver uri request.
|
||||||
*
|
*
|
||||||
* @return the newURI
|
* @return the geonetwork resolver uri request
|
||||||
*/
|
*/
|
||||||
public String getNewURI() {
|
public String getGeonetworkResolverURIRequest() {
|
||||||
|
|
||||||
return newURI;
|
return gnResolverUriRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the geonetwork request criteria.
|
||||||
|
*
|
||||||
* @return the geonetworkRequestCriteria
|
* @return the geonetworkRequestCriteria
|
||||||
*/
|
*/
|
||||||
public GeonetworkRequestCriteria getGeonetworkRequestCriteria() {
|
public GeonetworkRequestCriteria getGeonetworkRequestCriteria() {
|
||||||
|
@ -128,12 +229,14 @@ public class GeonetworkRequestDecoder {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("GeonetworkRequestDecoder [newURI=");
|
builder.append("GeonetworkRequestDecoder [gnResolverUriRequest=");
|
||||||
builder.append(newURI);
|
builder.append(gnResolverUriRequest);
|
||||||
builder.append(", geonetworkRequestCriteria=");
|
builder.append(", geonetworkRequestCriteria=");
|
||||||
builder.append(geonetworkRequestCriteria);
|
builder.append(geonetworkRequestCriteria);
|
||||||
builder.append("]");
|
builder.append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.datatransfer.resolver;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
* Aug 30, 2017
|
||||||
|
*/
|
||||||
|
public interface GeonetworkRequestFilterParameters {
|
||||||
|
|
||||||
|
public static enum MODE {HARVEST, VRE};
|
||||||
|
public static enum VISIBILITY {PUB, PRV};
|
||||||
|
public static String REQUEST_DELIMITIER = "/$$";
|
||||||
|
|
||||||
|
public static String OWNER_PARAM = "OWNER";
|
||||||
|
}
|
|
@ -14,6 +14,7 @@ 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 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;
|
||||||
|
@ -37,8 +38,6 @@ public class UriResolverRewriteFilter implements Filter{
|
||||||
|
|
||||||
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 PARAMETER_FILTER_PUBLIC_IDS = "filterpublicids";
|
|
||||||
public static final String PARAMETER_NO_AUTHENTICATION = "noauthentication";
|
|
||||||
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";
|
||||||
|
@ -86,108 +85,115 @@ public class UriResolverRewriteFilter implements Filter{
|
||||||
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);
|
||||||
|
|
||||||
//IS A REQUEST FOR GEONETWORK AUTHENTICATION? (CKAN HARVESTING?)
|
try{
|
||||||
if(servletPath.startsWith(SERVLET_GEONETWORK) || servletPath.startsWith(SERVLET_URI_RESOLVER+SERVLET_GEONETWORK)){
|
//IS A REQUEST FOR GEONETWORK AUTHENTICATION? (CKAN HARVESTING?)
|
||||||
logger.debug("It is a request to geonetwork");
|
if(servletPath.startsWith(SERVLET_GEONETWORK) || servletPath.startsWith(SERVLET_URI_RESOLVER+SERVLET_GEONETWORK)){
|
||||||
GeonetworkRequestDecoder grd = new GeonetworkRequestDecoder(servletPath, queryString);
|
logger.debug("It is a request to geonetwork");
|
||||||
logger.debug("forward to: "+grd.getNewURI());
|
GeonetworkRequestDecoder grd = new GeonetworkRequestDecoder(servletPath, queryString);
|
||||||
multiReadRequest.getRequestDispatcher(grd.getNewURI()).forward(multiReadRequest, response);
|
logger.debug("forward to: "+grd.getGeonetworkResolverURIRequest());
|
||||||
|
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]);
|
|
||||||
String gcubeScope = CatalogueRequestParameter.GCUBE_SCOPE.getKey() +"="+splittedServletPath[2];
|
|
||||||
String eC = CatalogueRequestParameter.ENTITY_CONTEXT.getKey() +"="+rcc.getValue();
|
|
||||||
logger.debug("found id code: "+idCodeCatalogue+", resolving it with context name: "+eC);
|
|
||||||
String eN = CatalogueRequestParameter.ENTITY_NAME.getKey() +"="+splittedServletPath[3];
|
|
||||||
logger.debug("found entity name: "+eN);
|
|
||||||
String encodedQuery = UrlEncoderUtil.encodeQuery(gcubeScope,eC,eN);
|
|
||||||
newURI+= "?" + PARAMETER_DIRECT_CATALOGUE_LINK + "=" + encodedQuery;
|
|
||||||
}else
|
|
||||||
if(splittedServletPath.length==5){
|
|
||||||
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() +"="+rcc.getValue();
|
||||||
logger.debug("found context name: "+eC);
|
logger.debug("found id code: "+idCodeCatalogue+", resolving it with context name: "+eC);
|
||||||
String eN = CatalogueRequestParameter.ENTITY_NAME.getKey() +"="+splittedServletPath[4];
|
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){
|
||||||
|
logger.info("resolving a complete URL in clear...");
|
||||||
|
logger.debug("found VRE name: "+splittedServletPath[2]);
|
||||||
|
String gcubeScope = CatalogueRequestParameter.GCUBE_SCOPE.getKey() +"="+splittedServletPath[2];
|
||||||
|
String eC = CatalogueRequestParameter.ENTITY_CONTEXT.getKey() +"="+splittedServletPath[3];
|
||||||
|
logger.debug("found context name: "+eC);
|
||||||
|
String eN = CatalogueRequestParameter.ENTITY_NAME.getKey() +"="+splittedServletPath[4];
|
||||||
|
logger.debug("found entity name: "+eN);
|
||||||
|
String encodedQuery = UrlEncoderUtil.encodeQuery(gcubeScope,eC,eN);
|
||||||
|
newURI+= "?" + PARAMETER_DIRECT_CATALOGUE_LINK + "=" + encodedQuery;
|
||||||
|
}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);
|
||||||
|
multiReadRequest.getRequestDispatcher(newURI).forward(multiReadRequest, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("forward to: " + newURI);
|
//chain.doFilter(multiReadRequest, response);
|
||||||
multiReadRequest.getRequestDispatcher(newURI).forward(multiReadRequest, response);
|
}else{
|
||||||
}
|
logger.debug("It is a request to workspace/storage");
|
||||||
|
//LAST CASE, IS WORKSPACE REQUEST?
|
||||||
//chain.doFilter(multiReadRequest, response);
|
if (queryString == null) { // IS A /XXXXX
|
||||||
}else{
|
logger.debug("QueryString is null, is It a new SMP public uri by ID?");
|
||||||
logger.debug("It is a request to workspace/storage");
|
int lastSlash = requestURI.lastIndexOf(PATH_SEPARATOR);
|
||||||
//LAST CASE, IS WORKSPACE REQUEST?
|
if (lastSlash + 1 == requestURI.length()) {
|
||||||
if (queryString == null) { // IS A /XXXXX
|
logger.debug("'/' is last index, doFilter Request");
|
||||||
logger.debug("QueryString is null, is It a new SMP public uri by ID?");
|
// req.getRequestDispatcher("/").forward(req, res);
|
||||||
int lastSlash = requestURI.lastIndexOf(PATH_SEPARATOR);
|
chain.doFilter(multiReadRequest, response);
|
||||||
if (lastSlash + 1 == requestURI.length()) {
|
}
|
||||||
logger.debug("'/' is last index, doFilter Request");
|
else {
|
||||||
// req.getRequestDispatcher("/").forward(req, res);
|
String toStorageID = requestURI.substring(lastSlash + 1, requestURI.length());
|
||||||
chain.doFilter(multiReadRequest, response);
|
// String newURI = requestURI.replace(toReplace,
|
||||||
|
// SERVLET_RESOLVER_BY_ID+"?"+SMP_ID+"="+toReplace);
|
||||||
|
String newURI = SERVLET_STORAGE_ID + "?" + PARAMETER_SMP_ID + "=" + toStorageID;
|
||||||
|
logger.debug("forward to: " + newURI);
|
||||||
|
multiReadRequest.getRequestDispatcher(newURI).forward(multiReadRequest, response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String toStorageID = requestURI.substring(lastSlash + 1, requestURI.length());
|
logger.debug("It is NOT a SMP public uri by ID, doFilter Request");
|
||||||
// String newURI = requestURI.replace(toReplace,
|
chain.doFilter(multiReadRequest, response);
|
||||||
// SERVLET_RESOLVER_BY_ID+"?"+SMP_ID+"="+toReplace);
|
|
||||||
String newURI = SERVLET_STORAGE_ID + "?" + PARAMETER_SMP_ID + "=" + toStorageID;
|
|
||||||
logger.debug("forward to: " + newURI);
|
|
||||||
multiReadRequest.getRequestDispatcher(newURI).forward(multiReadRequest, response);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
logger.debug("It is NOT a SMP public uri by ID, doFilter Request");
|
|
||||||
chain.doFilter(multiReadRequest, response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}catch(BadRequestException bre){
|
||||||
|
if (response instanceof HttpServletResponse){
|
||||||
|
HttpServletResponse httpResponse = (HttpServletResponse) response;
|
||||||
|
httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, bre.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,10 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.datatransfer.resolver.gis.geonetwork;
|
package org.gcube.datatransfer.resolver.gis.geonetwork;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
|
@ -23,17 +19,14 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
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.UriResolverRewriteFilter;
|
import org.gcube.datatransfer.resolver.GeonetworkRequestFilterParameters;
|
||||||
|
import org.gcube.datatransfer.resolver.GeonetworkRequestFilterParameters.MODE;
|
||||||
|
import org.gcube.datatransfer.resolver.GeonetworkRequestFilterParameters.VISIBILITY;
|
||||||
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.exception.GeonetworkInstanceException;
|
import org.gcube.datatransfer.resolver.gis.exception.GeonetworkInstanceException;
|
||||||
import org.gcube.datatransfer.resolver.gis.exception.IllegalArgumentException;
|
|
||||||
import org.gcube.datatransfer.resolver.gis.geonetwork.HTTPCallsUtils.HttpResponse;
|
import org.gcube.datatransfer.resolver.gis.geonetwork.HTTPCallsUtils.HttpResponse;
|
||||||
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.Type;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -67,12 +60,13 @@ public class GeonetworkResolver extends HttpServlet{
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -61097584153314181L;
|
private static final long serialVersionUID = -61097584153314181L;
|
||||||
public static final String SCOPE = "scope";
|
public static final String SCOPE = "scope";
|
||||||
public static final String REMAIN_PATH = "remainPath";
|
public static final String REMAIN_PATH_PARAM = "remainPath";
|
||||||
public static final String RESET_CACHE = "resetcache";
|
public static final String RESET_CACHE_PARAM = "resetcache";
|
||||||
public static final String RESET_CACHED_SCOPE = "resetcachedscope";
|
public static final String RESET_CACHED_SCOPE_PARAM = "resetcachedscope";
|
||||||
public static final String CSW_SERVER = "srv/en/csw";
|
public static final String CSW_SERVER = "srv/en/csw";
|
||||||
public static final String PARAMETER_FILTER_PUBLIC_IDS = UriResolverRewriteFilter.PARAMETER_FILTER_PUBLIC_IDS;
|
|
||||||
public static final String PARAMETER_NO_AUTHENTICATION = UriResolverRewriteFilter.PARAMETER_NO_AUTHENTICATION;
|
// public static final String PARAMETER_FILTER_PUBLIC_IDS = UriResolverRewriteFilter.PARAMETER_FILTER_PUBLIC_IDS;
|
||||||
|
// public static final String PARAMETER_NO_AUTHENTICATION = UriResolverRewriteFilter.PARAMETER_NO_AUTHENTICATION;
|
||||||
|
|
||||||
/** The logger. */
|
/** The logger. */
|
||||||
private static final Logger logger = LoggerFactory.getLogger(GeonetworkResolver.class);
|
private static final Logger logger = LoggerFactory.getLogger(GeonetworkResolver.class);
|
||||||
|
@ -109,11 +103,14 @@ public class GeonetworkResolver extends HttpServlet{
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
logger.info("doGET running...");
|
logger.info("doGET running... query string: "+req.getQueryString());
|
||||||
String scopeValue = req.getParameter(SCOPE);
|
String scopeValue = req.getParameter(SCOPE);
|
||||||
String remainValue = req.getParameter(REMAIN_PATH);
|
String remainValue = req.getParameter(REMAIN_PATH_PARAM);
|
||||||
String resetCache = req.getParameter(RESET_CACHE);
|
String mode = req.getParameter(GeonetworkRequestFilterParameters.MODE.class.getSimpleName());
|
||||||
String resetScope = req.getParameter(RESET_CACHED_SCOPE);
|
String visibility = req.getParameter(GeonetworkRequestFilterParameters.VISIBILITY.class.getSimpleName());
|
||||||
|
String owner = req.getParameter(GeonetworkRequestFilterParameters.OWNER_PARAM);
|
||||||
|
String resetCache = req.getParameter(RESET_CACHE_PARAM);
|
||||||
|
String resetScope = req.getParameter(RESET_CACHED_SCOPE_PARAM);
|
||||||
|
|
||||||
String originalScope = ScopeProvider.instance.get();
|
String originalScope = ScopeProvider.instance.get();
|
||||||
|
|
||||||
|
@ -123,6 +120,12 @@ public class GeonetworkResolver extends HttpServlet{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MODE theMode;
|
||||||
|
VISIBILITY theVisibility;
|
||||||
|
|
||||||
|
theMode = GeonetworkRequestFilterParameters.MODE.valueOf(mode);
|
||||||
|
theVisibility = GeonetworkRequestFilterParameters.VISIBILITY.valueOf(visibility);
|
||||||
|
|
||||||
if(resetCache!=null && Boolean.parseBoolean(resetCache)){
|
if(resetCache!=null && Boolean.parseBoolean(resetCache)){
|
||||||
purgeCacheGeonetworkInstances();
|
purgeCacheGeonetworkInstances();
|
||||||
}
|
}
|
||||||
|
@ -131,7 +134,11 @@ public class GeonetworkResolver extends HttpServlet{
|
||||||
resetGeonetoworkInstanceCacheForScope(scopeValue);
|
resetGeonetoworkInstanceCacheForScope(scopeValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("SCOPE: " + scopeValue +", Query String: " + req.getQueryString());
|
logger.info("SCOPE: " + scopeValue);
|
||||||
|
logger.info("MODE is: "+theMode);
|
||||||
|
logger.info("VISIBILITY is: "+theVisibility);
|
||||||
|
logger.info(GeonetworkRequestFilterParameters.OWNER_PARAM +" is: "+owner);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scopeValue);
|
GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scopeValue);
|
||||||
|
@ -214,12 +221,12 @@ public class GeonetworkResolver extends HttpServlet{
|
||||||
// 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(REMAIN_PATH+"=");
|
int start = queryString.indexOf(REMAIN_PATH_PARAM+"=");
|
||||||
|
|
||||||
if(start>=0){
|
if(start>=0){
|
||||||
int end = queryString.indexOf("&", start);
|
int end = queryString.indexOf("&", start);
|
||||||
|
|
||||||
if(end==-1 && queryString.length()==(REMAIN_PATH+"="+remain_value).length()){ //SCOPE IS THE UNIQUE PARAMETER INTO QUETY STRING
|
if(end==-1 && queryString.length()==(REMAIN_PATH_PARAM+"="+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())
|
||||||
|
@ -270,31 +277,33 @@ public class GeonetworkResolver extends HttpServlet{
|
||||||
String originalScope = ScopeProvider.instance.get();
|
String originalScope = ScopeProvider.instance.get();
|
||||||
logger.info("doPost running...");
|
logger.info("doPost running...");
|
||||||
String scope = req.getParameter(SCOPE);
|
String scope = req.getParameter(SCOPE);
|
||||||
String remainValue = req.getParameter(REMAIN_PATH);
|
String remainValue = req.getParameter(REMAIN_PATH_PARAM);
|
||||||
String filterPublicIDs = req.getParameter(PARAMETER_FILTER_PUBLIC_IDS);
|
String mode = req.getParameter(GeonetworkRequestFilterParameters.MODE.class.getSimpleName());
|
||||||
String noAuthentication = req.getParameter(PARAMETER_NO_AUTHENTICATION);
|
String visibility = req.getParameter(GeonetworkRequestFilterParameters.VISIBILITY.class.getSimpleName());
|
||||||
|
String owner = req.getParameter(GeonetworkRequestFilterParameters.OWNER_PARAM);
|
||||||
boolean filterPublicMetadataIDsB = false;
|
boolean filterPublicMetadataIDsB = false;
|
||||||
boolean noAuthenticationB = false;
|
boolean noAuthenticationB = false;
|
||||||
|
|
||||||
|
MODE theMode;
|
||||||
|
VISIBILITY theVisibility;
|
||||||
|
|
||||||
if (scope == null || scope.equals("")) {
|
if (scope == null || scope.equals("")) {
|
||||||
logger.debug("Scope not found");
|
logger.debug("Scope not found");
|
||||||
sendError(resp, HttpServletResponse.SC_BAD_REQUEST, SCOPE+" not found or empty");
|
sendError(resp, HttpServletResponse.SC_BAD_REQUEST, SCOPE+" not found or empty");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(filterPublicIDs!=null && Boolean.parseBoolean(filterPublicIDs)){
|
theMode = GeonetworkRequestFilterParameters.MODE.valueOf(mode);
|
||||||
filterPublicMetadataIDsB = true;
|
theVisibility = GeonetworkRequestFilterParameters.VISIBILITY.valueOf(visibility);
|
||||||
}
|
|
||||||
|
|
||||||
if(noAuthentication!=null && Boolean.parseBoolean(noAuthentication)){
|
|
||||||
noAuthenticationB = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("SCOPE is: " + scope);
|
logger.info("SCOPE is: " + scope);
|
||||||
logger.info(PARAMETER_FILTER_PUBLIC_IDS +" is "+filterPublicMetadataIDsB);
|
logger.info("MODE is: "+theMode);
|
||||||
logger.info(PARAMETER_NO_AUTHENTICATION +" is "+noAuthenticationB);
|
logger.info("VISIBILITY is: "+theVisibility);
|
||||||
|
logger.info(GeonetworkRequestFilterParameters.OWNER_PARAM +" is: "+owner);
|
||||||
|
|
||||||
try {
|
return;
|
||||||
|
|
||||||
|
/*try {
|
||||||
|
|
||||||
GeonetworkServiceInterface gntwAccess = new GeonetworkAccessParameter(scope);
|
GeonetworkServiceInterface gntwAccess = new GeonetworkAccessParameter(scope);
|
||||||
GeonetworkInstance gnInstance = gntwAccess.getGeonetworkInstance();
|
GeonetworkInstance gnInstance = gntwAccess.getGeonetworkInstance();
|
||||||
|
@ -407,7 +416,7 @@ public class GeonetworkResolver extends HttpServlet{
|
||||||
ScopeProvider.instance.reset();
|
ScopeProvider.instance.reset();
|
||||||
logger.info("scope provider reset");
|
logger.info("scope provider reset");
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,9 @@ public class GeonetworkQueryTest {
|
||||||
|
|
||||||
//private String[] scopesProd = {"/d4science.research-infrastructures.eu/D4Research"};
|
//private String[] scopesProd = {"/d4science.research-infrastructures.eu/D4Research"};
|
||||||
|
|
||||||
// private String[] scopesProd = {"/d4science.research-infrastructures.eu"};
|
private String[] scopesProd = {"/d4science.research-infrastructures.eu"};
|
||||||
|
|
||||||
private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/FAO_TunaAtlas"};
|
//private String[] scopesProd = {"/d4science.research-infrastructures.eu/gCubeApps/FAO_TunaAtlas"};
|
||||||
|
|
||||||
//private String[] scopesProd = {"/d4science.research-infrastructures.eu/D4Research/Blue-Datathon"};
|
//private String[] scopesProd = {"/d4science.research-infrastructures.eu/D4Research/Blue-Datathon"};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue