Strabon
changeset 681:bc88ed7620bc
merge
author | George Garbis <ggarbis@di.uoa.gr> |
---|---|
date | Thu Nov 01 12:57:13 2012 +0200 (2012-11-01) |
parents | 35a64d3bbfe3 caee6223be94 |
children | a49d35fba425 |
files |
line diff
1.1 --- a/endpoint/WebContent/WEB-INF/web.xml Thu Nov 01 12:56:55 2012 +0200 1.2 +++ b/endpoint/WebContent/WEB-INF/web.xml Thu Nov 01 12:57:13 2012 +0200 1.3 @@ -4,6 +4,22 @@ 1.4 xmlns:base="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 1.5 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 1.6 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 1.7 + 1.8 + <!-- Uncomment the following lines to enable ip filtering--> 1.9 + <!-- 1.10 + <filter> 1.11 + <filter-name>Remote Address Filter</filter-name> 1.12 + <filter-class>org.apache.catalina.filters.RemoteAddrFilter</filter-class> 1.13 + <init-param> 1.14 + <param-name>allow</param-name> 1.15 + <param-value>(195\.134\.(67|71)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|(88\.197\.4[4-7]\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|(195\.134\.105\.([01]?[0-9][0-9]?))</param-value> 1.16 + </init-param> 1.17 + </filter> 1.18 + <filter-mapping> 1.19 + <filter-name>Remote Address Filter</filter-name> 1.20 + <url-pattern>/*</url-pattern> 1.21 + </filter-mapping> 1.22 + --> 1.23 1.24 <display-name>StrabonEndpoint</display-name> 1.25 <context-param>
2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/AutoDiscoveryCapabilities.java Thu Nov 01 12:56:55 2012 +0200 2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/AutoDiscoveryCapabilities.java Thu Nov 01 12:57:13 2012 +0200 2.3 @@ -9,6 +9,10 @@ 2.4 */ 2.5 package eu.earthobservatory.org.StrabonEndpoint.capabilities; 2.6 2.7 +import java.io.IOException; 2.8 + 2.9 +import org.apache.commons.httpclient.HttpClient; 2.10 +import org.apache.commons.httpclient.methods.PostMethod; 2.11 import org.slf4j.Logger; 2.12 import org.slf4j.LoggerFactory; 2.13 2.14 @@ -34,6 +38,21 @@ 2.15 2.16 private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.org.StrabonEndpoint.capabilities.AutoDiscoveryCapabilities.class); 2.17 2.18 + /** 2.19 + * The host of the endpoint to discovery its capabilities 2.20 + */ 2.21 + private String host; 2.22 + 2.23 + /** 2.24 + * The port to use 2.25 + */ 2.26 + private int port; 2.27 + 2.28 + /** 2.29 + * The name of the web application 2.30 + */ 2.31 + private String appName; 2.32 + 2.33 @Override 2.34 public boolean supportsLimit() { 2.35 @SuppressWarnings("rawtypes") 2.36 @@ -76,31 +95,109 @@ 2.37 2.38 @Override 2.39 public RequestCapabilities getQueryCapabilities() { 2.40 - // TODO Auto-generated method stub 2.41 - return null; 2.42 + RequestCapabilities request = new RequestCapabilitiesImpl(); 2.43 + 2.44 + String query = "SELECT * WHERE {?s ?p ?o. FILTER(regex(str(?p), \"geometry\"))} LIMIT 1"; 2.45 + 2.46 + String[] queryParams = {"SPARQLQuery", "query"}; 2.47 + 2.48 + String[] formatValues = {"XML", "KML", "KMZ", "GeoJSON", "HTML", "TSV"}; 2.49 + 2.50 + String[] acceptValues = {"application/sparql-results+xml", "text/tab-separated-values", 2.51 + "application/vnd.google-earth.kml+xml", "application/vnd.google-earth.kmz", "text/html", 2.52 + "application/json"}; 2.53 + 2.54 + // check query parameter and format parameter 2.55 + for (int q = 0; q < queryParams.length; q++) { 2.56 + for (int v = 0; v < formatValues.length; v++) { 2.57 + HttpClient hc = new HttpClient(); 2.58 + 2.59 + // create a post method to execute 2.60 + PostMethod method = new PostMethod(getConnectionURL() + "/Query"); 2.61 + 2.62 + // set the query parameter 2.63 + method.setParameter(queryParams[q], query); 2.64 + 2.65 + // set the format parameter 2.66 + method.setParameter("format", formatValues[v]); 2.67 + 2.68 + try { 2.69 + // execute the method 2.70 + int statusCode = hc.executeMethod(method); 2.71 + 2.72 + if (statusCode == 301 || statusCode == 200) { 2.73 + //System.out.println(queryParams[q] + ", " + formatValues[v]); 2.74 + request.getParametersObject().addParameter(new Parameter(queryParams[q], null)); 2.75 + request.getParametersObject().addParameter(new Parameter("format", null)); 2.76 + request.getParametersObject().getParameter("format").addAcceptedValue(formatValues[v]); 2.77 + } 2.78 + 2.79 + } catch (IOException e) { 2.80 + e.printStackTrace(); 2.81 + 2.82 + } finally { 2.83 + // release the connection. 2.84 + method.releaseConnection(); 2.85 + } 2.86 + } 2.87 + } 2.88 + 2.89 + // check query parameter and accept header 2.90 + for (int q = 0; q < queryParams.length; q++) { 2.91 + for (int a = 0; a < acceptValues.length; a++) { 2.92 + HttpClient hc = new HttpClient(); 2.93 + 2.94 + // create a post method to execute 2.95 + PostMethod method = new PostMethod(getConnectionURL() + "/Query"); 2.96 + 2.97 + // set the query parameter 2.98 + method.setParameter(queryParams[q], query); 2.99 + 2.100 + // check for accept value as well 2.101 + // set the accept format 2.102 + method.addRequestHeader("Accept", acceptValues[a]); 2.103 + 2.104 + try { 2.105 + // execute the method 2.106 + int statusCode = hc.executeMethod(method); 2.107 + 2.108 + if (statusCode == 301 || statusCode == 200) { 2.109 + //System.out.println(queryParams[q] + ", " + acceptValues[a]); 2.110 + request.getParametersObject().addParameter(new Parameter(queryParams[q], null)); 2.111 + request.getParametersObject().addParameter(new Parameter("Accept", null)); 2.112 + request.getParametersObject().getParameter("Accept").addAcceptedValue(acceptValues[a]); 2.113 + } 2.114 + 2.115 + } catch (IOException e) { 2.116 + e.printStackTrace(); 2.117 + 2.118 + } finally { 2.119 + // release the connection. 2.120 + method.releaseConnection(); 2.121 + } 2.122 + } 2.123 + } 2.124 + 2.125 + return request; 2.126 } 2.127 2.128 @Override 2.129 public RequestCapabilities getUpdateCapabilities() { 2.130 - // TODO Auto-generated method stub 2.131 return null; 2.132 } 2.133 2.134 @Override 2.135 public RequestCapabilities getStoreCapabilities() { 2.136 - // TODO Auto-generated method stub 2.137 return null; 2.138 } 2.139 2.140 @Override 2.141 public RequestCapabilities getBrowseCapabilities() { 2.142 - // TODO Auto-generated method stub 2.143 return null; 2.144 } 2.145 2.146 @Override 2.147 public RequestCapabilities getConnectionCapabilities() { 2.148 - // TODO Auto-generated method stub 2.149 return null; 2.150 } 2.151 2.152 @@ -138,4 +235,14 @@ 2.153 return false; 2.154 } 2.155 } 2.156 + 2.157 + public void setEndpointDetails(String host, int port, String appName) { 2.158 + this.host = host; 2.159 + this.port = port; 2.160 + this.appName = appName; 2.161 + } 2.162 + 2.163 + private String getConnectionURL() { 2.164 + return "http://" + host + ":" + port + "/" + appName; 2.165 + } 2.166 }
3.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/BrowseBeanCapabilities.java Thu Nov 01 12:56:55 2012 +0200 3.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/BrowseBeanCapabilities.java Thu Nov 01 12:57:13 2012 +0200 3.3 @@ -33,20 +33,17 @@ 3.4 } 3.5 3.6 @Override 3.7 - public List<String> getParameters() { 3.8 - // TODO Auto-generated method stub 3.9 + public Parameters getParametersObject() { 3.10 return null; 3.11 } 3.12 3.13 @Override 3.14 public List<String> getAcceptedValues(String param) { 3.15 - // TODO Auto-generated method stub 3.16 return null; 3.17 } 3.18 3.19 @Override 3.20 public boolean isOptional(String param) { 3.21 - // TODO Auto-generated method stub 3.22 return false; 3.23 } 3.24
4.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/CapabilitiesBean.java Thu Nov 01 12:56:55 2012 +0200 4.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/CapabilitiesBean.java Thu Nov 01 12:57:13 2012 +0200 4.3 @@ -36,6 +36,11 @@ 4.4 * The context of the servlet 4.5 */ 4.6 private ServletContext context; 4.7 + 4.8 + /** 4.9 + * The name of this web application 4.10 + */ 4.11 + private String appName; 4.12 4.13 /** 4.14 * The capabilities of the endpoint 4.15 @@ -53,7 +58,10 @@ 4.16 4.17 // the the strabon wrapper 4.18 CapabilitiesDelegateBean capsBean = (CapabilitiesDelegateBean) applicationContext.getBean("capsBean"); 4.19 - 4.20 + 4.21 + // get the name of this web application 4.22 + appName = context.getContextPath().replace("/", ""); 4.23 + 4.24 // get capabilities 4.25 caps = capsBean.getEndpointCapabilities(); 4.26 } 4.27 @@ -106,6 +114,26 @@ 4.28 out.println("Supports DESCRIBE : " + getYesNo(caps.supportsDescribing())); 4.29 out.println("Supports CONSTRUCT : " + getYesNo(caps.supportsDescribing())); 4.30 out.println("Supports browsing : " + getYesNo(caps.supportsBrowsing())); 4.31 + out.println(); 4.32 + 4.33 + if (caps instanceof AutoDiscoveryCapabilities) { 4.34 + AutoDiscoveryCapabilities autocaps = (AutoDiscoveryCapabilities) caps; 4.35 + autocaps.setEndpointDetails(request.getServerName(), request.getServerPort(), appName); 4.36 + //autocaps.setEndpointDetails("localhost", 8080, "NOA"); 4.37 + } 4.38 + 4.39 + RequestCapabilities reCap = caps.getQueryCapabilities(); 4.40 + 4.41 + for (Parameter param : reCap.getParametersObject().getParameters()) { 4.42 + out.println("Supports parameter : " + param.getName()); 4.43 + 4.44 + if (param.getAcceptedValues().size() > 0) { 4.45 + out.println(" Accepted values : "); 4.46 + for (String acceptedValue : param.getAcceptedValues()) { 4.47 + out.println("\t\t " + acceptedValue); 4.48 + } 4.49 + } 4.50 + } 4.51 } 4.52 4.53 private String getYesNo(boolean val) {
5.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/ConnectionBeanCapabilities.java Thu Nov 01 12:56:55 2012 +0200 5.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/ConnectionBeanCapabilities.java Thu Nov 01 12:57:13 2012 +0200 5.3 @@ -33,20 +33,17 @@ 5.4 } 5.5 5.6 @Override 5.7 - public List<String> getParameters() { 5.8 - // TODO Auto-generated method stub 5.9 + public Parameters getParametersObject() { 5.10 return null; 5.11 } 5.12 5.13 @Override 5.14 public List<String> getAcceptedValues(String param) { 5.15 - // TODO Auto-generated method stub 5.16 return null; 5.17 } 5.18 5.19 @Override 5.20 public boolean isOptional(String param) { 5.21 - // TODO Auto-generated method stub 5.22 return false; 5.23 } 5.24
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/Parameter.java Thu Nov 01 12:57:13 2012 +0200 6.3 @@ -0,0 +1,48 @@ 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.HashSet; 6.16 +import java.util.Set; 6.17 + 6.18 +/** 6.19 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 6.20 + * 6.21 + */ 6.22 +public class Parameter { 6.23 + 6.24 + private String name; 6.25 + private String value; 6.26 + 6.27 + private Set<String> acceptedValues; 6.28 + 6.29 + public Parameter(String name, String value) { 6.30 + this.name = name; 6.31 + this.value = value; 6.32 + 6.33 + this.acceptedValues = new HashSet<String>(); 6.34 + } 6.35 + 6.36 + public String getName() { 6.37 + return name; 6.38 + } 6.39 + 6.40 + public String getValue() { 6.41 + return value; 6.42 + } 6.43 + 6.44 + public void addAcceptedValue(String value) { 6.45 + acceptedValues.add(value); 6.46 + } 6.47 + 6.48 + public Set<String> getAcceptedValues() { 6.49 + return acceptedValues; 6.50 + } 6.51 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/Parameters.java Thu Nov 01 12:57:13 2012 +0200 7.3 @@ -0,0 +1,46 @@ 7.4 +/** 7.5 + * This Source Code Form is subject to the terms of the Mozilla Public 7.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 7.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7.8 + * 7.9 + * Copyright (C) 2012, Pyravlos Team 7.10 + * 7.11 + * http://www.strabon.di.uoa.gr/ 7.12 + */ 7.13 +package eu.earthobservatory.org.StrabonEndpoint.capabilities; 7.14 + 7.15 +import java.util.Collection; 7.16 +import java.util.Hashtable; 7.17 + 7.18 +/** 7.19 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 7.20 + * 7.21 + */ 7.22 +public class Parameters { 7.23 + 7.24 + private Hashtable<String, Parameter> params; 7.25 + 7.26 + public Parameters() { 7.27 + params = new Hashtable<String, Parameter>(); 7.28 + } 7.29 + 7.30 + /** 7.31 + * Adds a new parameter. If the parameter already exists, 7.32 + * the operation does nothing. 7.33 + * 7.34 + * @param param 7.35 + */ 7.36 + public void addParameter(Parameter param) { 7.37 + if (params.get(param.getName()) == null) { 7.38 + params.put(param.getName(), param); 7.39 + } 7.40 + } 7.41 + 7.42 + public Parameter getParameter(String name) { 7.43 + return params.get(name); 7.44 + } 7.45 + 7.46 + public Collection<Parameter> getParameters() { 7.47 + return params.values(); 7.48 + } 7.49 +}
8.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/QueryBeanCapabilities.java Thu Nov 01 12:56:55 2012 +0200 8.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/QueryBeanCapabilities.java Thu Nov 01 12:57:13 2012 +0200 8.3 @@ -33,20 +33,17 @@ 8.4 } 8.5 8.6 @Override 8.7 - public List<String> getParameters() { 8.8 - // TODO Auto-generated method stub 8.9 + public Parameters getParametersObject() { 8.10 return null; 8.11 } 8.12 8.13 @Override 8.14 public List<String> getAcceptedValues(String param) { 8.15 - // TODO Auto-generated method stub 8.16 return null; 8.17 } 8.18 8.19 @Override 8.20 public boolean isOptional(String param) { 8.21 - // TODO Auto-generated method stub 8.22 return false; 8.23 } 8.24
9.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/RequestCapabilities.java Thu Nov 01 12:56:55 2012 +0200 9.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/RequestCapabilities.java Thu Nov 01 12:57:13 2012 +0200 9.3 @@ -26,7 +26,7 @@ 9.4 * 9.5 * @return 9.6 */ 9.7 - public List<String> getParameters(); 9.8 + public Parameters getParametersObject(); 9.9 9.10 /** 9.11 * Get the accepted values of a service parameter.
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/RequestCapabilitiesImpl.java Thu Nov 01 12:57:13 2012 +0200 10.3 @@ -0,0 +1,40 @@ 10.4 +/** 10.5 + * This Source Code Form is subject to the terms of the Mozilla Public 10.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 10.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 10.8 + * 10.9 + * Copyright (C) 2012, Pyravlos Team 10.10 + * 10.11 + * http://www.strabon.di.uoa.gr/ 10.12 + */ 10.13 +package eu.earthobservatory.org.StrabonEndpoint.capabilities; 10.14 + 10.15 +import java.util.List; 10.16 + 10.17 +/** 10.18 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 10.19 + */ 10.20 +public class RequestCapabilitiesImpl implements RequestCapabilities { 10.21 + 10.22 + private Parameters params; 10.23 + 10.24 + public RequestCapabilitiesImpl() { 10.25 + params = new Parameters(); 10.26 + } 10.27 + 10.28 + @Override 10.29 + public Parameters getParametersObject() { 10.30 + return params; 10.31 + } 10.32 + 10.33 + @Override 10.34 + public List<String> getAcceptedValues(String param) { 10.35 + return null; 10.36 + } 10.37 + 10.38 + @Override 10.39 + public boolean isOptional(String param) { 10.40 + return false; 10.41 + } 10.42 + 10.43 +}
11.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/StoreBeanCapabilities.java Thu Nov 01 12:56:55 2012 +0200 11.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/StoreBeanCapabilities.java Thu Nov 01 12:57:13 2012 +0200 11.3 @@ -33,20 +33,17 @@ 11.4 } 11.5 11.6 @Override 11.7 - public List<String> getParameters() { 11.8 - // TODO Auto-generated method stub 11.9 + public Parameters getParametersObject() { 11.10 return null; 11.11 } 11.12 11.13 @Override 11.14 public List<String> getAcceptedValues(String param) { 11.15 - // TODO Auto-generated method stub 11.16 return null; 11.17 } 11.18 11.19 @Override 11.20 public boolean isOptional(String param) { 11.21 - // TODO Auto-generated method stub 11.22 return false; 11.23 } 11.24
12.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/UpdateBeanCapabilities.java Thu Nov 01 12:56:55 2012 +0200 12.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/capabilities/UpdateBeanCapabilities.java Thu Nov 01 12:57:13 2012 +0200 12.3 @@ -33,20 +33,17 @@ 12.4 } 12.5 12.6 @Override 12.7 - public List<String> getParameters() { 12.8 - // TODO Auto-generated method stub 12.9 + public Parameters getParametersObject() { 12.10 return null; 12.11 } 12.12 12.13 @Override 12.14 public List<String> getAcceptedValues(String param) { 12.15 - // TODO Auto-generated method stub 12.16 return null; 12.17 } 12.18 12.19 @Override 12.20 public boolean isOptional(String param) { 12.21 - // TODO Auto-generated method stub 12.22 return false; 12.23 } 12.24 }