Strabon

changeset 675:92b2b31e150d

added Parameters and Parameter classes for hosting the HTTP parameters required from the various beans of the endpoint. Updated also the auto-discovery mechanism of old endpoints (still incomplete)
author Babis Nikolaou <charnik@di.uoa.gr>
date Wed Oct 31 16:56:53 2012 +0200 (2012-10-31)
parents 322e3050c7e1
children 3d517693f948
files endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/AutoDiscoveryCapabilities.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/BrowseBeanCapabilities.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/CapabilitiesBean.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/ConnectionBeanCapabilities.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/Parameter.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/Parameters.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/QueryBeanCapabilities.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/RequestCapabilities.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/StoreBeanCapabilities.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/UpdateBeanCapabilities.java
line diff
     1.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/AutoDiscoveryCapabilities.java	Wed Oct 31 00:26:42 2012 +0200
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/AutoDiscoveryCapabilities.java	Wed Oct 31 16:56:53 2012 +0200
     1.3 @@ -9,6 +9,10 @@
     1.4   */
     1.5  package eu.earthobservatory.org.StrabonEndpoint.capabilities;
     1.6  
     1.7 +import java.io.IOException;
     1.8 +
     1.9 +import org.apache.commons.httpclient.HttpClient;
    1.10 +import org.apache.commons.httpclient.methods.PostMethod;
    1.11  import org.slf4j.Logger;
    1.12  import org.slf4j.LoggerFactory;
    1.13  
    1.14 @@ -34,6 +38,21 @@
    1.15  
    1.16  	private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.org.StrabonEndpoint.capabilities.AutoDiscoveryCapabilities.class);
    1.17  	
    1.18 +	/**
    1.19 +	 * The host of the endpoint to discovery its capabilities
    1.20 +	 */
    1.21 +	private String host;
    1.22 +	
    1.23 +	/**
    1.24 +	 * The port to use
    1.25 +	 */
    1.26 +	private int port;
    1.27 +	
    1.28 +	/**
    1.29 +	 * The name of the web application
    1.30 +	 */
    1.31 +	private String appName;
    1.32 +	
    1.33  	@Override
    1.34  	public boolean supportsLimit() {
    1.35  		@SuppressWarnings("rawtypes")
    1.36 @@ -76,7 +95,66 @@
    1.37  
    1.38  	@Override
    1.39  	public RequestCapabilities getQueryCapabilities() {
    1.40 -		// TODO Auto-generated method stub
    1.41 +		String query = "SELECT * WHERE {?s ?p ?o. FILTER(regex(str(?p), \"geometry\"))} LIMIT 1";
    1.42 +		String[] queryParams = {"sparqlQuery", "query"};
    1.43 +		String[] formatParams = {"format", null};
    1.44 +		String[] formatValues = {"XML", "KML", "KMZ", "GeoJSON", "HTML", "TSV"};
    1.45 +		String[] acceptValues = {null, "application/sparql-results+xml", "text/tab-separated-values", 
    1.46 +				"application/vnd.google-earth.kml+xml", "application/vnd.google-earth.kmz", "text/html", 
    1.47 +				"application/json"};
    1.48 +		
    1.49 +		for (int q = 0; q < queryParams.length; q++) {
    1.50 +			for (int f = 0; f < formatParams.length; f++) {
    1.51 +				for (int v = 0; v < formatValues.length; v++) {
    1.52 +					for (int a = 0; a < acceptValues.length; a++) {
    1.53 +						HttpClient hc = new HttpClient();
    1.54 +						
    1.55 +						// create a post method to execute
    1.56 +						PostMethod method = new PostMethod(getConnectionURL() + "/Query");
    1.57 +						
    1.58 +						// set the query parameter
    1.59 +						method.setParameter(queryParams[q], query);
    1.60 +						if (formatParams[f] != null) {
    1.61 +							method.setParameter(formatParams[f], formatValues[v]);
    1.62 +							
    1.63 +						} else { // check for accept value as well, but only when
    1.64 +								 // we are not using the format parameter 
    1.65 +						
    1.66 +							// set the accept format
    1.67 +							if (acceptValues[a] != null) {
    1.68 +								method.addRequestHeader("Accept", acceptValues[a]);
    1.69 +							}
    1.70 +						}
    1.71 +						
    1.72 +						try {
    1.73 +							// execute the method
    1.74 +							int statusCode = hc.executeMethod(method);
    1.75 +							
    1.76 +							//System.out.println(method.getResponseBodyAsString());
    1.77 +							System.out.println(statusCode);
    1.78 +							
    1.79 +							if (statusCode == 200) {
    1.80 +								if (formatParams[f] != null) {
    1.81 +									System.err.println(queryParams[q] + ", " + formatParams[f] + ", " + formatValues[v]);
    1.82 +									
    1.83 +								} else {
    1.84 +									System.err.println(queryParams[q] + ", " + acceptValues[a]);	
    1.85 +								}
    1.86 +								
    1.87 +							}
    1.88 +	
    1.89 +						} catch (IOException e) {
    1.90 +							e.printStackTrace();
    1.91 +							
    1.92 +						} finally {
    1.93 +							// release the connection.
    1.94 +							method.releaseConnection();
    1.95 +						}
    1.96 +					}
    1.97 +				}
    1.98 +			}
    1.99 +		}
   1.100 +		
   1.101  		return null;
   1.102  	}
   1.103  
   1.104 @@ -138,4 +216,14 @@
   1.105  			return false;
   1.106  		}
   1.107  	}
   1.108 +
   1.109 +	public void setEndpointDetails(String host, int port, String appName) {
   1.110 +		this.host = host;
   1.111 +		this.port = port;
   1.112 +		this.appName = appName;
   1.113 +	}
   1.114 +	
   1.115 +	private String getConnectionURL() {
   1.116 +		return "http://" + host + ":" + port + "/" + appName;
   1.117 +	}
   1.118  }
     2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/BrowseBeanCapabilities.java	Wed Oct 31 00:26:42 2012 +0200
     2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/BrowseBeanCapabilities.java	Wed Oct 31 16:56:53 2012 +0200
     2.3 @@ -9,6 +9,7 @@
     2.4   */
     2.5  package eu.earthobservatory.org.StrabonEndpoint.capabilities;
     2.6  
     2.7 +import java.util.Collection;
     2.8  import java.util.List;
     2.9  
    2.10  
    2.11 @@ -33,7 +34,7 @@
    2.12  	}
    2.13  	
    2.14  	@Override
    2.15 -	public List<String> getParameters() {
    2.16 +	public Collection<Parameter> getParameters() {
    2.17  		// TODO Auto-generated method stub
    2.18  		return null;
    2.19  	}
     3.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/CapabilitiesBean.java	Wed Oct 31 00:26:42 2012 +0200
     3.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/CapabilitiesBean.java	Wed Oct 31 16:56:53 2012 +0200
     3.3 @@ -36,6 +36,11 @@
     3.4  	 * The context of the servlet
     3.5  	 */
     3.6  	private ServletContext context;
     3.7 +
     3.8 +	/**
     3.9 +	 * The name of this web application
    3.10 +	 */
    3.11 +	private String appName;
    3.12  	
    3.13  	/**
    3.14  	 * The capabilities of the endpoint
    3.15 @@ -53,7 +58,10 @@
    3.16  
    3.17  		// the the strabon wrapper
    3.18  		CapabilitiesDelegateBean capsBean = (CapabilitiesDelegateBean) applicationContext.getBean("capsBean");
    3.19 -		
    3.20 +
    3.21 +		// get the name of this web application
    3.22 +		appName = context.getContextPath().replace("/", "");
    3.23 +				
    3.24  		// get capabilities
    3.25  		caps = capsBean.getEndpointCapabilities();
    3.26  	}
    3.27 @@ -106,6 +114,13 @@
    3.28  		out.println("Supports DESCRIBE				: " + getYesNo(caps.supportsDescribing()));
    3.29  		out.println("Supports CONSTRUCT				: " + getYesNo(caps.supportsDescribing()));
    3.30  		out.println("Supports browsing				: "	+ getYesNo(caps.supportsBrowsing()));
    3.31 +		
    3.32 +		if (caps instanceof AutoDiscoveryCapabilities) {
    3.33 +			AutoDiscoveryCapabilities autocaps = (AutoDiscoveryCapabilities) caps;
    3.34 +			autocaps.setEndpointDetails(request.getServerName(), request.getServerPort(), appName);
    3.35 +		}
    3.36 +		
    3.37 +		caps.getQueryCapabilities();
    3.38  	}
    3.39  	
    3.40  	private String getYesNo(boolean val) {
     4.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/ConnectionBeanCapabilities.java	Wed Oct 31 00:26:42 2012 +0200
     4.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/ConnectionBeanCapabilities.java	Wed Oct 31 16:56:53 2012 +0200
     4.3 @@ -9,6 +9,7 @@
     4.4   */
     4.5  package eu.earthobservatory.org.StrabonEndpoint.capabilities;
     4.6  
     4.7 +import java.util.Collection;
     4.8  import java.util.List;
     4.9  
    4.10  
    4.11 @@ -33,7 +34,7 @@
    4.12  	}
    4.13  	
    4.14  	@Override
    4.15 -	public List<String> getParameters() {
    4.16 +	public Collection<Parameter> getParameters() {
    4.17  		// TODO Auto-generated method stub
    4.18  		return null;
    4.19  	}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/Parameter.java	Wed Oct 31 16:56:53 2012 +0200
     5.3 @@ -0,0 +1,48 @@
     5.4 +/**
     5.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     5.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     5.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     5.8 + * 
     5.9 + * Copyright (C) 2012, Pyravlos Team
    5.10 + * 
    5.11 + * http://www.strabon.di.uoa.gr/
    5.12 + */
    5.13 +package eu.earthobservatory.org.StrabonEndpoint.capabilities;
    5.14 +
    5.15 +import java.util.List;
    5.16 +import java.util.Vector;
    5.17 +
    5.18 +/**
    5.19 + * @author Charalampos Nikolaou <charnik@di.uoa.gr>
    5.20 + *
    5.21 + */
    5.22 +public class Parameter {
    5.23 +
    5.24 +	private String name;
    5.25 +	private String value;
    5.26 +	
    5.27 +	private List<String> acceptedValues;
    5.28 +	
    5.29 +	public Parameter(String name, String value) {
    5.30 +		this.name = name;
    5.31 +		this.value = value;
    5.32 +		
    5.33 +		this.acceptedValues = new Vector<String>();
    5.34 +	}
    5.35 +	
    5.36 +	public String getName() {
    5.37 +		return name;
    5.38 +	}
    5.39 +	
    5.40 +	public String getValue() {
    5.41 +		return value;
    5.42 +	}
    5.43 +	
    5.44 +	public void addAcceptedValue(String value) {
    5.45 +		acceptedValues.add(value);
    5.46 +	}
    5.47 +	
    5.48 +	public List<String> getAcceptedValues() {
    5.49 +		return acceptedValues;
    5.50 +	}
    5.51 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/Parameters.java	Wed Oct 31 16:56:53 2012 +0200
     6.3 @@ -0,0 +1,38 @@
     6.4 +/**
     6.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     6.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     6.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6.8 + * 
     6.9 + * Copyright (C) 2012, Pyravlos Team
    6.10 + * 
    6.11 + * http://www.strabon.di.uoa.gr/
    6.12 + */
    6.13 +package eu.earthobservatory.org.StrabonEndpoint.capabilities;
    6.14 +
    6.15 +import java.util.Collection;
    6.16 +import java.util.Hashtable;
    6.17 +
    6.18 +/**
    6.19 + * @author Charalampos Nikolaou <charnik@di.uoa.gr>
    6.20 + *
    6.21 + */
    6.22 +public class Parameters {
    6.23 +
    6.24 +	private Hashtable<String, Parameter> params;
    6.25 +	
    6.26 +	public Parameters() {
    6.27 +		params = new Hashtable<String, Parameter>();
    6.28 +	}
    6.29 +	
    6.30 +	public void addParameter(Parameter param) {
    6.31 +		params.put(param.getName(), param);
    6.32 +	}
    6.33 +	
    6.34 +	public Parameter getParameter(String name) {
    6.35 +		return params.get(name);
    6.36 +	}
    6.37 +	
    6.38 +	public Collection<Parameter> getParameters() {
    6.39 +		return params.values();
    6.40 +	}
    6.41 +}
     7.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/QueryBeanCapabilities.java	Wed Oct 31 00:26:42 2012 +0200
     7.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/QueryBeanCapabilities.java	Wed Oct 31 16:56:53 2012 +0200
     7.3 @@ -9,6 +9,7 @@
     7.4   */
     7.5  package eu.earthobservatory.org.StrabonEndpoint.capabilities;
     7.6  
     7.7 +import java.util.Collection;
     7.8  import java.util.List;
     7.9  
    7.10  
    7.11 @@ -33,20 +34,17 @@
    7.12  	}
    7.13  	
    7.14  	@Override
    7.15 -	public List<String> getParameters() {
    7.16 -		// TODO Auto-generated method stub
    7.17 +	public Collection<Parameter> getParameters() {
    7.18  		return null;
    7.19  	}
    7.20  
    7.21  	@Override
    7.22  	public List<String> getAcceptedValues(String param) {
    7.23 -		// TODO Auto-generated method stub
    7.24  		return null;
    7.25  	}
    7.26  
    7.27  	@Override
    7.28  	public boolean isOptional(String param) {
    7.29 -		// TODO Auto-generated method stub
    7.30  		return false;
    7.31  	}
    7.32  
     8.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/RequestCapabilities.java	Wed Oct 31 00:26:42 2012 +0200
     8.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/RequestCapabilities.java	Wed Oct 31 16:56:53 2012 +0200
     8.3 @@ -9,6 +9,7 @@
     8.4   */
     8.5  package eu.earthobservatory.org.StrabonEndpoint.capabilities;
     8.6  
     8.7 +import java.util.Collection;
     8.8  import java.util.List;
     8.9  
    8.10  /**
    8.11 @@ -26,7 +27,7 @@
    8.12  	 * 
    8.13  	 * @return
    8.14  	 */
    8.15 -	public List<String> getParameters();
    8.16 +	public Collection<Parameter> getParameters();
    8.17  	
    8.18  	/**
    8.19  	 * Get the accepted values of a service parameter.
     9.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/StoreBeanCapabilities.java	Wed Oct 31 00:26:42 2012 +0200
     9.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/StoreBeanCapabilities.java	Wed Oct 31 16:56:53 2012 +0200
     9.3 @@ -9,6 +9,7 @@
     9.4   */
     9.5  package eu.earthobservatory.org.StrabonEndpoint.capabilities;
     9.6  
     9.7 +import java.util.Collection;
     9.8  import java.util.List;
     9.9  
    9.10  
    9.11 @@ -33,7 +34,7 @@
    9.12  	}
    9.13  	
    9.14  	@Override
    9.15 -	public List<String> getParameters() {
    9.16 +	public Collection<Parameter> getParameters() {
    9.17  		// TODO Auto-generated method stub
    9.18  		return null;
    9.19  	}
    10.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/UpdateBeanCapabilities.java	Wed Oct 31 00:26:42 2012 +0200
    10.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/UpdateBeanCapabilities.java	Wed Oct 31 16:56:53 2012 +0200
    10.3 @@ -9,6 +9,7 @@
    10.4   */
    10.5  package eu.earthobservatory.org.StrabonEndpoint.capabilities;
    10.6  
    10.7 +import java.util.Collection;
    10.8  import java.util.List;
    10.9  
   10.10  
   10.11 @@ -33,7 +34,7 @@
   10.12  	}
   10.13  	
   10.14  	@Override
   10.15 -	public List<String> getParameters() {
   10.16 +	public Collection<Parameter> getParameters() {
   10.17  		// TODO Auto-generated method stub
   10.18  		return null;
   10.19  	}