Added a fix to getValueParameter

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/spatial-data/geo-utility@128374 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-04-28 09:31:09 +00:00
parent 5449843cd2
commit f68bc80f7c
3 changed files with 38 additions and 21 deletions

10
pom.xml
View File

@ -62,16 +62,16 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
</dependencies>
<build>

View File

@ -6,8 +6,9 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.apache.log4j.Logger;
import org.gcube.spatial.data.geoutility.bean.WmsParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -25,7 +26,7 @@ public class WmsUrlValidator {
private String wmsParameters;
private String wmsNoStandardParameters = "";
private Map<String, String> mapWmsNoStandardParams;
public static Logger logger = Logger.getLogger(WmsUrlValidator.class);
public static Logger logger = LoggerFactory.getLogger(WmsUrlValidator.class);
/**
* Instantiates a new wms url validator.
*
@ -169,7 +170,7 @@ public class WmsUrlValidator {
logger.trace("full wms url builded + wms no standard parameters: "+fullWmsUrlBuilded);
}else{
fullWmsUrlBuilded = parsedWmsRequest.substring(0, parsedWmsRequest.length()-1); //remove last &
logger.trace("full wms url builded: "+fullWmsUrlBuilded);
logger.trace("WmsUrlValidator parseWmsRequest returning, full wms url builded: "+fullWmsUrlBuilded);
}
return fullWmsUrlBuilded;
@ -227,15 +228,17 @@ public class WmsUrlValidator {
* Validate value of parameter.
*
* @param wmsParam the wms param
* @param valueOfParameter the value of parameter
* @param queryStringParameters the value of parameter
* @param fillEmptyParameterAsDefaultValue the fill empty parameter as default value
* @return the string
*/
public static String validateValueOfParameter(WmsParameters wmsParam, String valueOfParameter, boolean fillEmptyParameterAsDefaultValue){
public static String validateValueOfParameter(WmsParameters wmsParam, String queryStringParameters, boolean fillEmptyParameterAsDefaultValue){
try{
String value = getValueOfParameter(wmsParam, valueOfParameter);
logger.trace("validateValueOfParameter wmsParam "+wmsParam+" with queryStringParameters " +queryStringParameters);
String value = getValueOfParameter(wmsParam, queryStringParameters);
logger.trace("validateValueOfParameter wmsParam "+wmsParam+" value " +value);
if(fillEmptyParameterAsDefaultValue && (value==null || value.isEmpty())){
logger.trace("setting empty value for parameter: "+wmsParam.getParameter() +", as default value: "+wmsParam.getValue());
@ -257,7 +260,7 @@ public class WmsUrlValidator {
*/
public static String getValueOfParameter(WmsParameters wmsParam, String wmsRequestParamaters) {
// logger.trace("finding: "+wmsParam +" into "+url);
int index = wmsRequestParamaters.toLowerCase().indexOf(wmsParam.getParameter().toLowerCase());
int index = wmsRequestParamaters.toLowerCase().indexOf(wmsParam.getParameter().toLowerCase()+"="); //ADDING CHAR "=" IN TAIL TO BE SECURE IT IS A PARAMETER
// logger.trace("start index of "+wmsParam+ " is: "+index);
String value = "";
if(index > -1){
@ -288,7 +291,7 @@ public class WmsUrlValidator {
String toLowerWmsUrlParameters = wmsRequestParameters.toLowerCase();
String toLowerWmsParam = wmsParam.getParameter().toLowerCase();
int index = toLowerWmsUrlParameters.indexOf(toLowerWmsParam+"="); //+ "=" SECURE TO BE PARAMETER
int index = toLowerWmsUrlParameters.indexOf(toLowerWmsParam+"="); //END WITH CHAR "=" TO BE SECURE IT IS A PARAMETER
// logger.trace("start index of "+wmsParam+ " is: "+index);
if(index > -1){
int indexStartValue = index + toLowerWmsParam.length()+1; //add +1 for char '='
@ -387,10 +390,22 @@ public class WmsUrlValidator {
// }
// }
//
String fullPath = "http://www.fao.org/figis/geoserver/species/ows?CRS=EPSG:4326&BBOX=-180,-90,180,90&VERSION=1.1.0&FORMAT=image/png&SERVICE=WMS&HEIGHT=230&LAYERS=&REQUEST=GetMap&STYLES=&SRS=EPSG:4326&WIDTH=676";
fullPath = WmsUrlValidator.setValueOfParameter(WmsParameters.LAYERS, fullPath, "123", true);
System.out.println(fullPath);
// String fullPath = "http://www.fao.org/figis/geoserver/species/ows?CRS=EPSG:4326&BBOX=-180,-90,180,90&VERSION=1.1.0&FORMAT=image/png&SERVICE=WMS&HEIGHT=230&LAYERS=&REQUEST=GetMap&STYLES=&SRS=EPSG:4326&WIDTH=676";
// fullPath = WmsUrlValidator.setValueOfParameter(WmsParameters.LAYERS, fullPath, "123", true);
// System.out.println(fullPath);
String wmsRequest = "http://geoserver-dev.d4science-ii.research-infrastructures.eu/geoserver/wms?CRS=EPSG:4326&BBOX=-85.5,-180.0,90.0,180.0&VERSION=1.1.0&FORMAT=application/openlayers&SERVICE=wms&HEIGHT=330&LAYERS=aquamaps:lsoleasolea20130716162322254cest&REQUEST=GetMap&STYLES=Species_prob&SRS=EPSG:4326&WIDTH=676";
// String wmsRequest = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?service=wms&version=1.3.0&request=GetMap&layers=analyzed_field&styles=&width=640&height=480&srs=EPSG:4326&CRS=EPSG:4326&format=image/png&COLORSCALERANGE=auto&bbox=-85.0,-180.0,85.0,180.0";
WmsUrlValidator wms;
try {
wms = new WmsUrlValidator(wmsRequest);
System.out.println("Returned wms: "+wms.toString());
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//
}
}

View File

@ -22,8 +22,9 @@ public class GeoJUnitTest {
@Test
public void testGetStyles() {
// String wmsRequest = "http://repoigg.services.iit.cnr.it:8080/geoserver/IGG/ows?service=wms&version=1.1.0&request=GetMap&layers==IGG:area_temp_1000&width=676&height=330&srs=EPSG:4326&crs=EPSG:4326&format=application/openlayers&bbox=-85.5,-180.0,90.0,180.0";
String wmsRequest = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?service=wms&version=1.3.0&request=GetMap&layers=analyzed_field&styles=&width=640&height=480&srs=EPSG:4326&CRS=EPSG:4326&format=image/png&COLORSCALERANGE=auto&bbox=-85.0,-180.0,85.0,180.0";
// String wmsRequest = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?service=wms&version=1.3.0&request=GetMap&layers=analyzed_field&styles=&width=640&height=480&srs=EPSG:4326&CRS=EPSG:4326&format=image/png&COLORSCALERANGE=auto&bbox=-85.0,-180.0,85.0,180.0";
// String wmsRequest = "http://www.fao.org/figis/geoserver/species?SERVICE=WMS&BBOX=-176.0,-90.0,180.0,90&styles=&layers=layerName&FORMAT=image/gif";
String wmsRequest = "http://geoserver-dev.d4science-ii.research-infrastructures.eu/geoserver/wms?CRS=EPSG:4326&BBOX=-85.5,-180.0,90.0,180.0&VERSION=1.1.0&FORMAT=application/openlayers&SERVICE=wms&HEIGHT=330&LAYERS=aquamaps:lsoleasolea20130716162322254cest&REQUEST=GetMap&STYLES=Species_prob&SRS=EPSG:4326&WIDTH=676";
GeoNcWMSMetadataUtility geo;
try {
geo = new GeoNcWMSMetadataUtility(wmsRequest);
@ -40,7 +41,7 @@ public class GeoJUnitTest {
/**
* Test get styles.
*/
@Test
// @Test
public void testLoadZAxis() {
// String wmsRequest = "http://repoigg.services.iit.cnr.it:8080/geoserver/IGG/ows?service=wms&version=1.1.0&request=GetMap&layers==IGG:area_temp_1000&width=676&height=330&srs=EPSG:4326&crs=EPSG:4326&format=application/openlayers&bbox=-85.5,-180.0,90.0,180.0";
String wmsRequest = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?service=wms&version=1.3.0&request=GetMap&layers=analyzed_field&styles=&width=640&height=480&srs=EPSG:4326&CRS=EPSG:4326&format=image/png&COLORSCALERANGE=auto&bbox=-85.0,-180.0,85.0,180.0";
@ -60,9 +61,10 @@ public class GeoJUnitTest {
/**
* Test wms url validator.
*/
@Test
// @Test
public void testWMSUrlValidator() {
String wmsRequest = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?service=wms&version=1.3.0&request=GetMap&layers=analyzed_field&styles=&width=640&height=480&srs=EPSG:4326&CRS=EPSG:4326&format=image/png&COLORSCALERANGE=auto&bbox=-85.0,-180.0,85.0,180.0";
String wmsRequest = "http://geoserver-dev.d4science-ii.research-infrastructures.eu/geoserver/wms?CRS=EPSG:4326&BBOX=-85.5,-180.0,90.0,180.0&VERSION=1.1.0&FORMAT=application/openlayers&SERVICE=wms&HEIGHT=330&LAYERS=aquamaps:lsoleasolea20130716162322254cest&REQUEST=GetMap&STYLES=Species_prob&SRS=EPSG:4326&WIDTH=676";
// String wmsRequest = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?service=wms&version=1.3.0&request=GetMap&layers=analyzed_field&styles=&width=640&height=480&srs=EPSG:4326&CRS=EPSG:4326&format=image/png&COLORSCALERANGE=auto&bbox=-85.0,-180.0,85.0,180.0";
WmsUrlValidator wms;
try {
wms = new WmsUrlValidator(wmsRequest);