Added connectionTimeout to perform GetStyles and GetMedatada
git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/spatial-data/geo-utility@122637 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
d8e1a3c24c
commit
2a464a4c62
|
@ -32,38 +32,65 @@ public class GeoGetStylesUtility {
|
||||||
private List<String> geoStyles;
|
private List<String> geoStyles;
|
||||||
private Map<String, String> mapNcWmsStyles;
|
private Map<String, String> mapNcWmsStyles;
|
||||||
private WmsUrlValidator validator;
|
private WmsUrlValidator validator;
|
||||||
|
/** The Constant CONNECTION_TIMEOUT. */
|
||||||
/**
|
public static final int CONNECTION_TIMEOUT = 1000; //DEFAULT CONNECTION TIMEOUT
|
||||||
* Instantiates a new geo get styles.
|
|
||||||
*
|
|
||||||
* @param wmsRequest the wms request
|
|
||||||
* @throws Exception the exception
|
|
||||||
*/
|
|
||||||
public GeoGetStylesUtility(String wmsRequest) throws Exception{
|
|
||||||
this.wmsRequest = wmsRequest;
|
|
||||||
this.validator = new WmsUrlValidator(wmsRequest);
|
|
||||||
validator.parseWmsRequest(true, false);
|
|
||||||
loadStyles();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new geo get styles utility.
|
* Instantiates a new geo get styles utility.
|
||||||
*
|
*
|
||||||
* @param wmsRequest the wms request
|
* @param wmsRequest the wms request
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
public GeoGetStylesUtility(String wmsRequest) throws Exception{
|
||||||
|
this(wmsRequest, CONNECTION_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new geo get styles utility.
|
||||||
|
*
|
||||||
|
* @param wmsRequest the wms request
|
||||||
|
* @param connectionTimeout the connection timeout sets a specified timeout value, in milliseconds, to be used when opening URLConnection.
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
public GeoGetStylesUtility(String wmsRequest, int connectionTimeout) throws Exception{
|
||||||
|
this.wmsRequest = wmsRequest;
|
||||||
|
this.validator = new WmsUrlValidator(wmsRequest);
|
||||||
|
validator.parseWmsRequest(true, false);
|
||||||
|
loadStyles(connectionTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new geo get styles utility.
|
||||||
|
*
|
||||||
* @param validator the validator
|
* @param validator the validator
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public GeoGetStylesUtility(String wmsRequest, WmsUrlValidator validator) throws Exception{
|
public GeoGetStylesUtility(WmsUrlValidator validator) throws Exception{
|
||||||
|
this(validator, CONNECTION_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new geo get styles utility.
|
||||||
|
*
|
||||||
|
* @param validator the validator
|
||||||
|
* @param connectionTimeout the connection timeout sets a specified timeout value, in milliseconds, to be used when opening URLConnection.
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
public GeoGetStylesUtility(WmsUrlValidator validator, int connectionTimeout) throws Exception{
|
||||||
|
this.wmsRequest = validator.getWmsRequest();
|
||||||
this.validator = validator;
|
this.validator = validator;
|
||||||
loadStyles();
|
loadStyles(connectionTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load styles.
|
* Load styles.
|
||||||
|
* @param connectionTimeout the connection timeout sets a specified timeout value, in milliseconds, to be used when opening URLConnection.
|
||||||
*/
|
*/
|
||||||
private void loadStyles(){
|
private void loadStyles(int connectionTimeout){
|
||||||
|
|
||||||
String uriWMSService = validator.getBaseWmsServiceUrl();
|
String uriWMSService = validator.getBaseWmsServiceUrl();
|
||||||
String layerName = validator.getValueOfParsedWMSParameter(WmsParameters.LAYERS);
|
String layerName = validator.getValueOfParsedWMSParameter(WmsParameters.LAYERS);
|
||||||
|
@ -137,7 +164,7 @@ public class GeoGetStylesUtility {
|
||||||
if(stylesRead==null || stylesRead.isEmpty()){
|
if(stylesRead==null || stylesRead.isEmpty()){
|
||||||
|
|
||||||
logger.trace("styles are empty or null - Trying to get styles by 'WMS Get Style'");
|
logger.trace("styles are empty or null - Trying to get styles by 'WMS Get Style'");
|
||||||
WmsGetStyles wmsGetStyles = new WmsGetStyles();
|
WmsGetStyles wmsGetStyles = new WmsGetStyles(connectionTimeout);
|
||||||
styles = wmsGetStyles.getStylesFromWms(uriWMSService, layerName);
|
styles = wmsGetStyles.getStylesFromWms(uriWMSService, layerName);
|
||||||
|
|
||||||
if(wmsGetStyles.getResponseCode()==200){
|
if(wmsGetStyles.getResponseCode()==200){
|
||||||
|
@ -146,7 +173,7 @@ public class GeoGetStylesUtility {
|
||||||
logger.debug("Wms GetStyles not found, Trying to get styles by 'NcWmsGetMetadata'");
|
logger.debug("Wms GetStyles not found, Trying to get styles by 'NcWmsGetMetadata'");
|
||||||
isNcWms = true;
|
isNcWms = true;
|
||||||
try{
|
try{
|
||||||
NcWmsLayerMetadata ncMetadata = NcWmsGetMetadata.getMetadata(uriWMSService, layerName);
|
NcWmsLayerMetadata ncMetadata = NcWmsGetMetadata.getMetadata(uriWMSService, layerName, connectionTimeout);
|
||||||
|
|
||||||
if(ncMetadata!=null && ncMetadata.getResponseCode()==200){
|
if(ncMetadata!=null && ncMetadata.getResponseCode()==200){
|
||||||
if(ncMetadata.getSupportedStyles().size()>0){
|
if(ncMetadata.getSupportedStyles().size()>0){
|
||||||
|
@ -224,6 +251,7 @@ public class GeoGetStylesUtility {
|
||||||
return mapNcWmsStyles == null?new HashMap<String, String>(1):mapNcWmsStyles;
|
return mapNcWmsStyles == null?new HashMap<String, String>(1):mapNcWmsStyles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -31,10 +31,10 @@ import org.json.JSONObject;
|
||||||
*/
|
*/
|
||||||
public class NcWmsGetMetadata {
|
public class NcWmsGetMetadata {
|
||||||
|
|
||||||
protected static final int CONNECTION_TIMEOUT = 1000;
|
/** The Constant CONNECTION_TIMEOUT. */
|
||||||
|
protected static final int CONNECTION_TIMEOUT = 1000; //DEFAULT CONNECTION TIMEOUT
|
||||||
public static Logger logger = Logger.getLogger(NcWmsGetMetadata.class);
|
public static Logger logger = Logger.getLogger(NcWmsGetMetadata.class);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the metadata.
|
* Gets the metadata.
|
||||||
*
|
*
|
||||||
|
@ -44,6 +44,19 @@ public class NcWmsGetMetadata {
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public static NcWmsLayerMetadata getMetadata(String wmsServerUri, String layerName) throws Exception {
|
public static NcWmsLayerMetadata getMetadata(String wmsServerUri, String layerName) throws Exception {
|
||||||
|
return getMetadata(wmsServerUri, layerName, CONNECTION_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the metadata.
|
||||||
|
*
|
||||||
|
* @param wmsServerUri the wms server uri
|
||||||
|
* @param layerName the layer name
|
||||||
|
* @param connectionTimeout the connection timeout sets a specified timeout value, in milliseconds, to be used when opening URLConnection.
|
||||||
|
* @return the metadata
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
public static NcWmsLayerMetadata getMetadata(String wmsServerUri, String layerName, int connectionTimeout) throws Exception {
|
||||||
|
|
||||||
if(wmsServerUri==null || wmsServerUri.isEmpty())
|
if(wmsServerUri==null || wmsServerUri.isEmpty())
|
||||||
throw new Exception("Invalid wms server uri");
|
throw new Exception("Invalid wms server uri");
|
||||||
|
@ -57,7 +70,7 @@ public class NcWmsGetMetadata {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String query = UrlEncoderUtil.encodeQuery(parameters);
|
String query = UrlEncoderUtil.encodeQuery(parameters);
|
||||||
return openConnectionGetMetadata(wmsServerUri, query);
|
return openConnectionGetMetadata(wmsServerUri, query, connectionTimeout);
|
||||||
|
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
logger.error("Error Exception with url " + wmsServerUri);
|
logger.error("Error Exception with url " + wmsServerUri);
|
||||||
|
@ -65,14 +78,17 @@ public class NcWmsGetMetadata {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open connection get metadata.
|
* Open connection get metadata.
|
||||||
*
|
*
|
||||||
* @param urlConn the url conn
|
* @param urlConn the url conn
|
||||||
* @param query the query
|
* @param query the query
|
||||||
|
* @param connectionTimeout the connection timeout sets a specified timeout value, in milliseconds, to be used when opening URLConnection.
|
||||||
* @return the nc wms layer metadata
|
* @return the nc wms layer metadata
|
||||||
*/
|
*/
|
||||||
private static NcWmsLayerMetadata openConnectionGetMetadata(String urlConn, String query) {
|
private static NcWmsLayerMetadata openConnectionGetMetadata(String urlConn, String query, int connectionTimeout) {
|
||||||
|
|
||||||
URL url;
|
URL url;
|
||||||
NcWmsLayerMetadata metadata = null;
|
NcWmsLayerMetadata metadata = null;
|
||||||
|
@ -81,8 +97,11 @@ public class NcWmsGetMetadata {
|
||||||
url = new URL(urlConn + "?" + query);
|
url = new URL(urlConn + "?" + query);
|
||||||
URLConnection connection = url.openConnection();
|
URLConnection connection = url.openConnection();
|
||||||
|
|
||||||
connection.setConnectTimeout(CONNECTION_TIMEOUT);
|
if(connectionTimeout<0)
|
||||||
connection.setReadTimeout(CONNECTION_TIMEOUT + CONNECTION_TIMEOUT);
|
connectionTimeout = CONNECTION_TIMEOUT;
|
||||||
|
|
||||||
|
connection.setConnectTimeout(connectionTimeout);
|
||||||
|
connection.setReadTimeout(connectionTimeout + connectionTimeout);
|
||||||
|
|
||||||
logger.trace("openConnectionGetMetadata on: " + url);
|
logger.trace("openConnectionGetMetadata on: " + url);
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ import org.gcube.spatial.data.geoutility.util.XpathParserUtil;
|
||||||
*/
|
*/
|
||||||
public class WmsGetStyles {
|
public class WmsGetStyles {
|
||||||
|
|
||||||
protected static final int CONNECTION_TIMEOUT = 1000;
|
private int CONNECTION_TIMEOUT = 1000; //DEFAULT CONNECTION TIMEOUT
|
||||||
public static Logger logger = Logger.getLogger(WmsGetStyles.class);
|
public static Logger logger = Logger.getLogger(WmsGetStyles.class);
|
||||||
protected HashMap<String, String> mappings;
|
protected HashMap<String, String> mappings;
|
||||||
protected NamespaceContextMap context;
|
protected NamespaceContextMap context;
|
||||||
|
@ -58,6 +58,17 @@ public class WmsGetStyles {
|
||||||
context = new NamespaceContextMap(mappings);
|
context = new NamespaceContextMap(mappings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new wms get styles.
|
||||||
|
*
|
||||||
|
* @param connectionTimeout the connection timeout sets a specified timeout value, in milliseconds, to be used when opening WMS GetStyles request.
|
||||||
|
*/
|
||||||
|
public WmsGetStyles(int connectionTimeout) {
|
||||||
|
this();
|
||||||
|
if(connectionTimeout>0)
|
||||||
|
CONNECTION_TIMEOUT = connectionTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the styles from wms.
|
* Gets the styles from wms.
|
||||||
*
|
*
|
||||||
|
@ -97,25 +108,6 @@ public class WmsGetStyles {
|
||||||
logger.info("WMS GetStyles returning : "+styles.toString());
|
logger.info("WMS GetStyles returning : "+styles.toString());
|
||||||
return styles;
|
return styles;
|
||||||
|
|
||||||
|
|
||||||
/*if(geosever.getScope()!=null && !geosever.getScope().isEmpty()){
|
|
||||||
logger.trace("tentative get styles with scope " + geosever.getScope());
|
|
||||||
styles = openConnectionGetStyles(urlConn, query);
|
|
||||||
|
|
||||||
if(styles.size()==0){
|
|
||||||
|
|
||||||
logger.trace("tentative get styles with scope: "+geosever.getScope()+", has returned empty styles");
|
|
||||||
String newUrlConn = urlConn.replace("/"+geosever.getScope(), "");
|
|
||||||
logger.trace("new tentative get styles as base url without scope");
|
|
||||||
return openConnectionGetStyles(newUrlConn, query);
|
|
||||||
|
|
||||||
}else
|
|
||||||
return styles;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return styles;*/
|
|
||||||
// return openConnectionGetStyles(urlConn, query);
|
|
||||||
|
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
logger.error("Error Exception with url " + urlConn);
|
logger.error("Error Exception with url " + urlConn);
|
||||||
return styles;
|
return styles;
|
||||||
|
|
Loading…
Reference in New Issue