From 733d2dc1e005d9aeb0be8f9cb6513237bbd81e21 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 10 Feb 2016 17:47:43 +0000 Subject: [PATCH] Added connection timeout to loadStyles git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/spatial-data/geo-utility@124091 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../geoutility/GeoNcWMSMetadataUtility.java | 4 ++-- .../geoutility/wms/NcWmsGetMetadataRequest.java | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/gcube/spatial/data/geoutility/GeoNcWMSMetadataUtility.java b/src/main/java/org/gcube/spatial/data/geoutility/GeoNcWMSMetadataUtility.java index d5e8691..eb49451 100644 --- a/src/main/java/org/gcube/spatial/data/geoutility/GeoNcWMSMetadataUtility.java +++ b/src/main/java/org/gcube/spatial/data/geoutility/GeoNcWMSMetadataUtility.java @@ -150,7 +150,7 @@ public class GeoNcWMSMetadataUtility { layerName, crs, validator.getValueOfParsedWMSParameter(WmsParameters.WIDTH), - validator.getValueOfParsedWMSParameter(WmsParameters.HEIGHT)); + validator.getValueOfParsedWMSParameter(WmsParameters.HEIGHT),connectionTimeout); if(minmax!=null && minmax.length==2 && minmax[0]!=null && minmax[1]!=null){ String valueMinMax = minmax[0]+","+minmax[1]; @@ -169,7 +169,7 @@ public class GeoNcWMSMetadataUtility { layerName, crs, validator.getValueOfParsedWMSParameter(WmsParameters.WIDTH), - validator.getValueOfParsedWMSParameter(WmsParameters.HEIGHT)); + validator.getValueOfParsedWMSParameter(WmsParameters.HEIGHT),connectionTimeout); if(minmax!=null && minmax.length==2 && minmax[0]!=null && minmax[1]!=null){ isNcWms = true; diff --git a/src/main/java/org/gcube/spatial/data/geoutility/wms/NcWmsGetMetadataRequest.java b/src/main/java/org/gcube/spatial/data/geoutility/wms/NcWmsGetMetadataRequest.java index a9ef3da..f93f878 100644 --- a/src/main/java/org/gcube/spatial/data/geoutility/wms/NcWmsGetMetadataRequest.java +++ b/src/main/java/org/gcube/spatial/data/geoutility/wms/NcWmsGetMetadataRequest.java @@ -51,10 +51,11 @@ public class NcWmsGetMetadataRequest { * @param crs the crs * @param width the width * @param height the height + * @param connectionTimeout the connection timeout * @return the color scale range - an array of 2 elements that contains min and max value for the COLORSCALERANGE * @throws Exception the exception */ - public static String[] getColorScaleRange(String wmsServerUri, String wmsVersion, String bbox, String layerName, String crs, String width, String height) throws Exception { + public static String[] getColorScaleRange(String wmsServerUri, String wmsVersion, String bbox, String layerName, String crs, String width, String height, int connectionTimeout) throws Exception { logger.trace(NcWmsGetMetadataRequest.class.getName()+".getColorScaleRange working..."); String[] colorScaleMinMax = null; // http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?item=minmax&layers=analyzed_field&bbox=-180.0,-85.0,180.0,85.0&crs=EPSG%3A4326&request=GetMetadata&width=640&height=480 @@ -83,7 +84,7 @@ public class NcWmsGetMetadataRequest { try { String query = UrlEncoderUtil.encodeQuery(parameters); - colorScaleMinMax = openConnectionGetColorScaleRange(wmsServerUri, query); + colorScaleMinMax = openConnectionGetColorScaleRange(wmsServerUri, query, connectionTimeout); return colorScaleMinMax; }catch (Exception e) { @@ -97,9 +98,10 @@ public class NcWmsGetMetadataRequest { * * @param urlConn the url conn * @param query the query + * @param connectionTimeout the connection timeout * @return the string[] an array with 2 elements witch contains min, max value for the COLORSCALERANGE */ - private static String[] openConnectionGetColorScaleRange(String urlConn, String query) { + private static String[] openConnectionGetColorScaleRange(String urlConn, String query, int connectionTimeout) { URL url; String[] colorScaleRange = null; @@ -108,8 +110,11 @@ public class NcWmsGetMetadataRequest { url = new URL(urlConn + "?" + query); URLConnection connection = url.openConnection(); - connection.setConnectTimeout(CONNECTION_TIMEOUT); - connection.setReadTimeout(CONNECTION_TIMEOUT + CONNECTION_TIMEOUT); + if(connectionTimeout<0) + connectionTimeout = CONNECTION_TIMEOUT; + + connection.setConnectTimeout(connectionTimeout); + connection.setReadTimeout(connectionTimeout*2); logger.trace("openConnectionGetColorScaleRange on: " + url); @@ -207,7 +212,7 @@ public class NcWmsGetMetadataRequest { // http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?item=minmax&layers=analyzed_field&bbox=-180.0,-85.0,180.0,85.0&crs=EPSG%3A4326&request=GetMetadata&width=640&height=480 try { - NcWmsGetMetadataRequest.getColorScaleRange("http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc", "1.1.1", "-85.0,-180.0,85.0,180.0", "analyzed_field", "EPSG:4326", "640", "480"); + NcWmsGetMetadataRequest.getColorScaleRange("http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc", "1.1.1", "-85.0,-180.0,85.0,180.0", "analyzed_field", "EPSG:4326", "640", "480", 2000); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace();