Strabon
changeset 686:706b99be9078
added endpoint-client maven submodule: a Java implementation for Strabon endpoint
author | Babis Nikolaou <charnik@di.uoa.gr> |
---|---|
date | Mon Nov 05 20:40:17 2012 +0200 (2012-11-05) |
parents | 5221af947637 |
children | 9a4bb8e81273 |
files | endpoint-client/pom.xml endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/EndpointResult.java endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpoint.java endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpointImpl.java endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpoint.java endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpointResult.java endpoint-client/src/test/java/eu/earthobservatory/org/StrabonEndpoint/client/TestStrabonEndpoint.java endpoint/pom.xml endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/EndpointResult.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpoint.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpointImpl.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpoint.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpointResult.java endpoint/src/test/java/eu/earthobservatory/org/StrabonEndpoint/client/TestStrabonEndpoint.java pom.xml |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/endpoint-client/pom.xml Mon Nov 05 20:40:17 2012 +0200 1.3 @@ -0,0 +1,182 @@ 1.4 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 1.5 + 1.6 + <modelVersion>4.0.0</modelVersion> 1.7 + 1.8 + <parent> 1.9 + <groupId>eu.earthobservatory</groupId> 1.10 + <artifactId>strabon</artifactId> 1.11 + <version>3.2.5-SNAPSHOT</version> 1.12 + </parent> 1.13 + 1.14 + <artifactId>endpoint-client</artifactId> 1.15 + 1.16 + <name>Strabon: Endpoint client</name> 1.17 + <description>A java client for Strabon endpoint</description> 1.18 + <packaging>jar</packaging> 1.19 + 1.20 + <dependencies> 1.21 + <dependency> 1.22 + <groupId>org.openrdf.sesame</groupId> 1.23 + <artifactId>sesame-queryresultio-spatial</artifactId> 1.24 + </dependency> 1.25 + <!-- 1.26 + <dependency> 1.27 + <groupId>org.openrdf.sesame</groupId> 1.28 + <artifactId>sesame-queryalgebra-evaluation-spatial</artifactId> 1.29 + </dependency> 1.30 + <dependency> 1.31 + <groupId>org.openrdf.sesame</groupId> 1.32 + <artifactId>sesame-queryalgebra-evaluation</artifactId> 1.33 + </dependency> 1.34 + <dependency> 1.35 + <groupId>org.openrdf.sesame</groupId> 1.36 + <artifactId>sesame-rio-rdfxml</artifactId> 1.37 + </dependency> 1.38 + 1.39 + <dependency> 1.40 + <groupId>org.openrdf.sesame</groupId> 1.41 + <artifactId>sesame-rio-ntriples</artifactId> 1.42 + </dependency> 1.43 + 1.44 + <dependency> 1.45 + <groupId>org.openrdf.sesame</groupId> 1.46 + <artifactId>sesame-rio-turtle</artifactId> 1.47 + </dependency> 1.48 + 1.49 + <dependency> 1.50 + <groupId>org.openrdf.sesame</groupId> 1.51 + <artifactId>sesame-rio-trig</artifactId> 1.52 + </dependency> 1.53 + 1.54 + <dependency> 1.55 + <groupId>org.openrdf.sesame</groupId> 1.56 + <artifactId>sesame-rio-trix</artifactId> 1.57 + </dependency> 1.58 + 1.59 + <dependency> 1.60 + <groupId>org.openrdf.sesame</groupId> 1.61 + <artifactId>sesame-rio-n3</artifactId> 1.62 + </dependency> 1.63 + 1.64 + <dependency> 1.65 + <groupId>org.openrdf.sesame</groupId> 1.66 + <artifactId>sesame-rio-binary</artifactId> 1.67 + </dependency> 1.68 +--> 1.69 + 1.70 + <dependency> 1.71 + <groupId>commons-httpclient</groupId> 1.72 + <artifactId>commons-httpclient</artifactId> 1.73 + <exclusions> 1.74 + <exclusion> 1.75 + <groupId>commons-logging</groupId> 1.76 + <artifactId>commons-logging</artifactId> 1.77 + </exclusion> 1.78 + <exclusion> 1.79 + <!-- httpclient includes older codec --> 1.80 + <groupId>commons-codec</groupId> 1.81 + <artifactId>commons-codec</artifactId> 1.82 + </exclusion> 1.83 + </exclusions> 1.84 + </dependency> 1.85 + <dependency> 1.86 + <groupId>commons-codec</groupId> 1.87 + <artifactId>commons-codec</artifactId> 1.88 + <scope>runtime</scope> 1.89 + </dependency> 1.90 + 1.91 + <!-- Testing: JUnit --> 1.92 + <dependency> 1.93 + <groupId>junit</groupId> 1.94 + <artifactId>junit</artifactId> 1.95 + <scope>test</scope> 1.96 + </dependency> 1.97 + </dependencies> 1.98 + 1.99 + <build> 1.100 + <pluginManagement> 1.101 + <plugins> 1.102 + <!-- FIXME: version 2.2-beta-2 causes a lot problems --> 1.103 + <plugin> 1.104 + <groupId>org.apache.maven.plugins</groupId> 1.105 + <artifactId>maven-assembly-plugin</artifactId> 1.106 + <version>2.2-beta-1</version> 1.107 + </plugin> 1.108 + <plugin> 1.109 + <groupId>org.eclipse.m2e</groupId> 1.110 + <artifactId>lifecycle-mapping</artifactId> 1.111 + <version>1.0.0</version> 1.112 + <configuration> 1.113 + <lifecycleMappingMetadata> 1.114 + <pluginExecutions> 1.115 + <pluginExecution> 1.116 + <pluginExecutionFilter> 1.117 + <groupId>org.apache.maven.plugins</groupId> 1.118 + <artifactId>maven-dependency-plugin</artifactId> 1.119 + <versionRange>[2.3,)</versionRange> 1.120 + <goals> 1.121 + <goal>copy-dependencies</goal> 1.122 + </goals> 1.123 + </pluginExecutionFilter> 1.124 + <action> 1.125 + <ignore /> 1.126 + </action> 1.127 + </pluginExecution> 1.128 + </pluginExecutions> 1.129 + </lifecycleMappingMetadata> 1.130 + </configuration> 1.131 + </plugin> 1.132 + </plugins> 1.133 + </pluginManagement> 1.134 + 1.135 + <plugins> 1.136 + <plugin> 1.137 + <groupId>org.apache.maven.plugins</groupId> 1.138 + <artifactId>maven-compiler-plugin</artifactId> 1.139 + <version>2.3.2</version> 1.140 + <configuration> 1.141 + <source>1.6</source> 1.142 + <target>1.6</target> 1.143 + <encoding>utf8</encoding> 1.144 + </configuration> 1.145 + </plugin> 1.146 + <plugin> 1.147 + <groupId>org.apache.maven.plugins</groupId> 1.148 + <artifactId>maven-dependency-plugin</artifactId> 1.149 + <version>2.4</version> 1.150 + <executions> 1.151 + <execution> 1.152 + <id>copy-dependencies</id> 1.153 + <phase>package</phase> 1.154 + <goals> 1.155 + <goal>copy-dependencies</goal> 1.156 + </goals> 1.157 + <configuration> 1.158 + <outputDirectory>${project.build.directory}</outputDirectory> 1.159 + <overWriteReleases>false</overWriteReleases> 1.160 + <overWriteSnapshots>false</overWriteSnapshots> 1.161 + <overWriteIfNewer>true</overWriteIfNewer> 1.162 + </configuration> 1.163 + </execution> 1.164 + </executions> 1.165 + </plugin> 1.166 + 1.167 + <plugin> 1.168 + <groupId>org.apache.maven.plugins</groupId> 1.169 + <artifactId>maven-jar-plugin</artifactId> 1.170 + <version>2.4</version> 1.171 + <configuration> 1.172 + <skipIfEmpty>true</skipIfEmpty> 1.173 + </configuration> 1.174 + <executions> 1.175 + <execution> 1.176 + <goals> 1.177 + <goal>test-jar</goal> 1.178 + </goals> 1.179 + </execution> 1.180 + </executions> 1.181 + </plugin> 1.182 + </plugins> 1.183 + </build> 1.184 +</project> 1.185 +
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/EndpointResult.java Mon Nov 05 20:40:17 2012 +0200 2.3 @@ -0,0 +1,35 @@ 2.4 +/** 2.5 + * This Source Code Form is subject to the terms of the Mozilla Public 2.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 2.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 2.8 + * 2.9 + * Copyright (C) 2012, Pyravlos Team 2.10 + * 2.11 + * http://www.strabon.di.uoa.gr/ 2.12 + */ 2.13 +package eu.earthobservatory.org.StrabonEndpoint.client; 2.14 + 2.15 +/** 2.16 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 2.17 + * 2.18 + */ 2.19 +public interface EndpointResult { 2.20 + 2.21 + /** 2.22 + * Returns the HTTP status code as returned by the endpoint. 2.23 + * @return 2.24 + */ 2.25 + public int getStatusCode(); 2.26 + 2.27 + /** 2.28 + * Returns the status text corresponding to the status code. 2.29 + * @return 2.30 + */ 2.31 + public String getStatusText(); 2.32 + 2.33 + /** 2.34 + * Returns the response of the endpoint. 2.35 + * @return 2.36 + */ 2.37 + public String getResponse(); 2.38 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpoint.java Mon Nov 05 20:40:17 2012 +0200 3.3 @@ -0,0 +1,38 @@ 3.4 +/** 3.5 + * This Source Code Form is subject to the terms of the Mozilla Public 3.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 3.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 3.8 + * 3.9 + * Copyright (C) 2012, Pyravlos Team 3.10 + * 3.11 + * http://www.strabon.di.uoa.gr/ 3.12 + */ 3.13 +package eu.earthobservatory.org.StrabonEndpoint.client; 3.14 + 3.15 +import java.io.IOException; 3.16 +import java.net.URL; 3.17 + 3.18 +import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 3.19 +import org.openrdf.rio.RDFFormat; 3.20 + 3.21 +/** 3.22 + * Every SPARQL endpoint that supports storing and querying of 3.23 + * spatial RDF data should implement the {@link SpatialEndpoint} 3.24 + * interface. 3.25 + * 3.26 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 3.27 + */ 3.28 +public interface SpatialEndpoint { 3.29 + 3.30 + public EndpointResult query(String sparqlQuery, stSPARQLQueryResultFormat format) throws IOException; 3.31 + 3.32 + public boolean store(String data, RDFFormat format); 3.33 + 3.34 + public boolean store(URL data, RDFFormat format); 3.35 + 3.36 + public boolean update(String sparqlUpdate); 3.37 + 3.38 + public EndpointResult describe(String sparqlDescribe); 3.39 + 3.40 + public EndpointResult construct(String sparqlConstruct); 3.41 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpointImpl.java Mon Nov 05 20:40:17 2012 +0200 4.3 @@ -0,0 +1,110 @@ 4.4 +/** 4.5 + * This Source Code Form is subject to the terms of the Mozilla Public 4.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 4.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4.8 + * 4.9 + * Copyright (C) 2012, Pyravlos Team 4.10 + * 4.11 + * http://www.strabon.di.uoa.gr/ 4.12 + */ 4.13 +package eu.earthobservatory.org.StrabonEndpoint.client; 4.14 + 4.15 +import org.apache.commons.httpclient.HttpClient; 4.16 +import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; 4.17 + 4.18 +/** 4.19 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 4.20 + * 4.21 + */ 4.22 +public abstract class SpatialEndpointImpl implements SpatialEndpoint { 4.23 + 4.24 + /** 4.25 + * The host on which the endpoint is located. 4.26 + */ 4.27 + protected String host; 4.28 + 4.29 + /** 4.30 + * The port of the host. 4.31 + */ 4.32 + protected int port; 4.33 + 4.34 + /** 4.35 + * The name of the endpoint. 4.36 + * 4.37 + * This is useful for {@link StrabonEndpoint} instances that are usually 4.38 + * deployed in a tomcat container as web applications. 4.39 + */ 4.40 + protected String endpointName; 4.41 + 4.42 + /** 4.43 + * The username to be used in case the endpoint requires authentication. 4.44 + */ 4.45 + protected String user; 4.46 + 4.47 + /** 4.48 + * The password to be used in case the endpoint requires authentication. 4.49 + */ 4.50 + protected String password; 4.51 + 4.52 + /** 4.53 + * The connection manager that manages sharing of connections to endpoints 4.54 + * among several threads. 4.55 + */ 4.56 + private MultiThreadedHttpConnectionManager connectionManager; 4.57 + 4.58 + /** 4.59 + * The HttpClient to be used for connecting to an endpoint. 4.60 + */ 4.61 + protected HttpClient hc; 4.62 + 4.63 + public SpatialEndpointImpl(String host, int port) { 4.64 + this(host, port, "/"); 4.65 + } 4.66 + 4.67 + public SpatialEndpointImpl(String host, int port, String endpointName) { 4.68 + this.host = host; 4.69 + this.port = port; 4.70 + 4.71 + this.endpointName = (endpointName == null ? "":endpointName); 4.72 + 4.73 + // create a connection manager for allowing the users of this class use threads 4.74 + connectionManager = new MultiThreadedHttpConnectionManager(); 4.75 + 4.76 + // create an HttpClient instance that establishes connections based on the connection manager 4.77 + hc = new HttpClient(connectionManager); 4.78 + } 4.79 + 4.80 + public String getHost() { 4.81 + return host; 4.82 + } 4.83 + 4.84 + public int getPort() { 4.85 + return port; 4.86 + } 4.87 + 4.88 + public void setUser(String user) { 4.89 + this.user = user; 4.90 + } 4.91 + 4.92 + public void setPassword(String pass) { 4.93 + this.password = pass; 4.94 + } 4.95 + 4.96 + public String getUser() { 4.97 + return user; 4.98 + } 4.99 + 4.100 + public String getPassword() { 4.101 + return password; 4.102 + } 4.103 + 4.104 + /** 4.105 + * Returns a URL (actually a {@link String}) for establishing connections 4.106 + * to an endpoint based on the information given to the constructor. 4.107 + * 4.108 + * @return 4.109 + */ 4.110 + protected String getConnectionURL() { 4.111 + return "http://" + host + ":" + port + "/" + endpointName; 4.112 + } 4.113 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpoint.java Mon Nov 05 20:40:17 2012 +0200 5.3 @@ -0,0 +1,89 @@ 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.client; 5.14 + 5.15 +import java.io.IOException; 5.16 +import java.net.URL; 5.17 + 5.18 +import org.apache.commons.httpclient.methods.PostMethod; 5.19 +import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 5.20 +import org.openrdf.rio.RDFFormat; 5.21 + 5.22 +/** 5.23 + * This class is the implementation of a java client for accessing 5.24 + * StrabonEndpoint instances. 5.25 + * 5.26 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 5.27 + */ 5.28 +public class StrabonEndpoint extends SpatialEndpointImpl { 5.29 + 5.30 + public StrabonEndpoint(String host, int port) { 5.31 + super(host, port); 5.32 + } 5.33 + 5.34 + public StrabonEndpoint(String host, int port, String endpointName) { 5.35 + super(host, port, endpointName); 5.36 + } 5.37 + 5.38 + @Override 5.39 + public EndpointResult query(String sparqlQuery, stSPARQLQueryResultFormat format) throws IOException { 5.40 + assert(format != null); 5.41 + 5.42 + // create a post method to execute 5.43 + PostMethod method = new PostMethod(getConnectionURL() + "/Query"); 5.44 + 5.45 + // set the query parameter 5.46 + method.setParameter("query", sparqlQuery); 5.47 + 5.48 + // set the accept format 5.49 + method.addRequestHeader("Accept", format.getDefaultMIMEType()); 5.50 + //System.out.println(method.getRequestHeader("Accept")); 5.51 + 5.52 + try { 5.53 + // execute the method 5.54 + int statusCode = hc.executeMethod(method); 5.55 + 5.56 + return new StrabonEndpointResult(statusCode, method.getStatusText(), method.getResponseBodyAsString()); 5.57 + 5.58 + } catch (IOException e) { 5.59 + throw e; 5.60 + 5.61 + } finally { 5.62 + // release the connection. 5.63 + method.releaseConnection(); 5.64 + } 5.65 + } 5.66 + 5.67 + @Override 5.68 + public boolean store(String data, RDFFormat format) { 5.69 + return false; 5.70 + } 5.71 + 5.72 + @Override 5.73 + public boolean store(URL data, RDFFormat format) { 5.74 + return false; 5.75 + } 5.76 + 5.77 + @Override 5.78 + public boolean update(String sparqlUpdate) { 5.79 + return false; 5.80 + } 5.81 + 5.82 + @Override 5.83 + public EndpointResult describe(String sparqlDescribe) { 5.84 + return null; 5.85 + } 5.86 + 5.87 + @Override 5.88 + public EndpointResult construct(String sparqlConstruct) { 5.89 + return null; 5.90 + } 5.91 + 5.92 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpointResult.java Mon Nov 05 20:40:17 2012 +0200 6.3 @@ -0,0 +1,42 @@ 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.client; 6.14 + 6.15 +/** 6.16 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 6.17 + * 6.18 + */ 6.19 +public class StrabonEndpointResult implements EndpointResult { 6.20 + 6.21 + private int statusCode; 6.22 + private String statusText; 6.23 + private String response; 6.24 + 6.25 + public StrabonEndpointResult(int statusCode, String statusLine, String response) { 6.26 + this.statusCode = statusCode; 6.27 + this.statusText = statusLine; 6.28 + this.response = response; 6.29 + } 6.30 + 6.31 + @Override 6.32 + public int getStatusCode() { 6.33 + return statusCode; 6.34 + } 6.35 + 6.36 + @Override 6.37 + public String getStatusText() { 6.38 + return statusText; 6.39 + } 6.40 + 6.41 + @Override 6.42 + public String getResponse() { 6.43 + return response; 6.44 + } 6.45 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/endpoint-client/src/test/java/eu/earthobservatory/org/StrabonEndpoint/client/TestStrabonEndpoint.java Mon Nov 05 20:40:17 2012 +0200 7.3 @@ -0,0 +1,85 @@ 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.client; 7.14 + 7.15 +import static org.junit.Assert.assertTrue; 7.16 + 7.17 +import java.io.IOException; 7.18 +import java.util.Vector; 7.19 + 7.20 +import org.junit.Before; 7.21 +import org.junit.Test; 7.22 +import org.openrdf.query.resultio.TupleQueryResultFormat; 7.23 +import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 7.24 + 7.25 +/** 7.26 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 7.27 + * 7.28 + */ 7.29 +public class TestStrabonEndpoint { 7.30 + 7.31 + private StrabonEndpoint endpoint; 7.32 + private String query; 7.33 + private Vector<stSPARQLQueryResultFormat> formats = new Vector<stSPARQLQueryResultFormat>(); 7.34 + 7.35 + @Before 7.36 + public void init() { 7.37 + // initialize endpoint 7.38 + endpoint = new StrabonEndpoint("test.strabon.di.uoa.gr", 80, "DLR"); 7.39 + 7.40 + // set query 7.41 + query = "PREFIX teleios:<http://teleios.di.uoa.gr/ontologies/noaOntology.owl#>\n" + 7.42 + "SELECT ?s ?g WHERE {\n" + 7.43 + " ?s teleios:hasGeometry ?g\n" + 7.44 + "}" + 7.45 + "\nLIMIT 1"; 7.46 + 7.47 + // initialized formats 7.48 + for (TupleQueryResultFormat format : stSPARQLQueryResultFormat.values()) { 7.49 + if (format instanceof stSPARQLQueryResultFormat) { 7.50 + formats.add((stSPARQLQueryResultFormat) format); 7.51 + } 7.52 + } 7.53 + 7.54 + } 7.55 + 7.56 + /** 7.57 + * Test method for {@link eu.earthobservatory.org.StrabonEndpoint.client.StrabonEndpoint#query(java.lang.String, org.openrdf.query.resultio.stSPARQLQueryResultFormat)}. 7.58 + */ 7.59 + @Test 7.60 + public void testQuery() { 7.61 + for (stSPARQLQueryResultFormat format : formats) { 7.62 + try { 7.63 + EndpointResult response = endpoint.query(query, format); 7.64 + 7.65 + if (response.getStatusCode() != 200) { 7.66 + System.err.println("Status code ("+response.getStatusCode()+"):" + response.getStatusText()); 7.67 + 7.68 + } 7.69 + 7.70 + assertTrue(response.getStatusCode() == 200); 7.71 + 7.72 + } catch (IOException e) { 7.73 + e.printStackTrace(); 7.74 + } 7.75 + 7.76 + } 7.77 + } 7.78 + 7.79 + /** 7.80 + * Test method for testing that method {@link eu.earthobservatory.org.StrabonEndpoint.client.StrabonEndpoint#query(java.lang.String, org.openrdf.query.resultio.stSPARQLQueryResultFormat)}. 7.81 + * returns an IOException when it should do so. 7.82 + */ 7.83 + @Test(expected= IOException.class) 7.84 + public void testIOException() throws Exception { 7.85 + StrabonEndpoint ep = new StrabonEndpoint("blabla.dgr", 80, "bla"); 7.86 + ep.query(query, formats.get(0)); 7.87 + } 7.88 +}
8.1 --- a/endpoint/pom.xml Fri Nov 02 13:50:36 2012 +0200 8.2 +++ b/endpoint/pom.xml Mon Nov 05 20:40:17 2012 +0200 8.3 @@ -10,7 +10,7 @@ 8.4 <artifactId>strabon-endpoint</artifactId> 8.5 <packaging>war</packaging> 8.6 8.7 - <name>StrabonEndpoint</name> 8.8 + <name>Strabon: Endpoint</name> 8.9 <description>An endpoint for Strabon</description> 8.10 8.11 <properties>
9.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/EndpointResult.java Fri Nov 02 13:50:36 2012 +0200 9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 9.3 @@ -1,35 +0,0 @@ 9.4 -/** 9.5 - * This Source Code Form is subject to the terms of the Mozilla Public 9.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 9.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9.8 - * 9.9 - * Copyright (C) 2012, Pyravlos Team 9.10 - * 9.11 - * http://www.strabon.di.uoa.gr/ 9.12 - */ 9.13 -package eu.earthobservatory.org.StrabonEndpoint.client; 9.14 - 9.15 -/** 9.16 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 9.17 - * 9.18 - */ 9.19 -public interface EndpointResult { 9.20 - 9.21 - /** 9.22 - * Returns the HTTP status code as returned by the endpoint. 9.23 - * @return 9.24 - */ 9.25 - public int getStatusCode(); 9.26 - 9.27 - /** 9.28 - * Returns the status text corresponding to the status code. 9.29 - * @return 9.30 - */ 9.31 - public String getStatusText(); 9.32 - 9.33 - /** 9.34 - * Returns the response of the endpoint. 9.35 - * @return 9.36 - */ 9.37 - public String getResponse(); 9.38 -}
10.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpoint.java Fri Nov 02 13:50:36 2012 +0200 10.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 10.3 @@ -1,38 +0,0 @@ 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.client; 10.14 - 10.15 -import java.io.IOException; 10.16 -import java.net.URL; 10.17 - 10.18 -import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 10.19 -import org.openrdf.rio.RDFFormat; 10.20 - 10.21 -/** 10.22 - * Every SPARQL endpoint that supports storing and querying of 10.23 - * spatial RDF data should implement the {@link SpatialEndpoint} 10.24 - * interface. 10.25 - * 10.26 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 10.27 - */ 10.28 -public interface SpatialEndpoint { 10.29 - 10.30 - public EndpointResult query(String sparqlQuery, stSPARQLQueryResultFormat format) throws IOException; 10.31 - 10.32 - public boolean store(String data, RDFFormat format); 10.33 - 10.34 - public boolean store(URL data, RDFFormat format); 10.35 - 10.36 - public boolean update(String sparqlUpdate); 10.37 - 10.38 - public EndpointResult describe(String sparqlDescribe); 10.39 - 10.40 - public EndpointResult construct(String sparqlConstruct); 10.41 -}
11.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpointImpl.java Fri Nov 02 13:50:36 2012 +0200 11.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 11.3 @@ -1,110 +0,0 @@ 11.4 -/** 11.5 - * This Source Code Form is subject to the terms of the Mozilla Public 11.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 11.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 11.8 - * 11.9 - * Copyright (C) 2012, Pyravlos Team 11.10 - * 11.11 - * http://www.strabon.di.uoa.gr/ 11.12 - */ 11.13 -package eu.earthobservatory.org.StrabonEndpoint.client; 11.14 - 11.15 -import org.apache.commons.httpclient.HttpClient; 11.16 -import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; 11.17 - 11.18 -/** 11.19 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 11.20 - * 11.21 - */ 11.22 -public abstract class SpatialEndpointImpl implements SpatialEndpoint { 11.23 - 11.24 - /** 11.25 - * The host on which the endpoint is located. 11.26 - */ 11.27 - protected String host; 11.28 - 11.29 - /** 11.30 - * The port of the host. 11.31 - */ 11.32 - protected int port; 11.33 - 11.34 - /** 11.35 - * The name of the endpoint. 11.36 - * 11.37 - * This is useful for {@link StrabonEndpoint} instances that are usually 11.38 - * deployed in a tomcat container as web applications. 11.39 - */ 11.40 - protected String endpointName; 11.41 - 11.42 - /** 11.43 - * The username to be used in case the endpoint requires authentication. 11.44 - */ 11.45 - protected String user; 11.46 - 11.47 - /** 11.48 - * The password to be used in case the endpoint requires authentication. 11.49 - */ 11.50 - protected String password; 11.51 - 11.52 - /** 11.53 - * The connection manager that manages sharing of connections to endpoints 11.54 - * among several threads. 11.55 - */ 11.56 - private MultiThreadedHttpConnectionManager connectionManager; 11.57 - 11.58 - /** 11.59 - * The HttpClient to be used for connecting to an endpoint. 11.60 - */ 11.61 - protected HttpClient hc; 11.62 - 11.63 - public SpatialEndpointImpl(String host, int port) { 11.64 - this(host, port, "/"); 11.65 - } 11.66 - 11.67 - public SpatialEndpointImpl(String host, int port, String endpointName) { 11.68 - this.host = host; 11.69 - this.port = port; 11.70 - 11.71 - this.endpointName = (endpointName == null ? "":endpointName); 11.72 - 11.73 - // create a connection manager for allowing the users of this class use threads 11.74 - connectionManager = new MultiThreadedHttpConnectionManager(); 11.75 - 11.76 - // create an HttpClient instance that establishes connections based on the connection manager 11.77 - hc = new HttpClient(connectionManager); 11.78 - } 11.79 - 11.80 - public String getHost() { 11.81 - return host; 11.82 - } 11.83 - 11.84 - public int getPort() { 11.85 - return port; 11.86 - } 11.87 - 11.88 - public void setUser(String user) { 11.89 - this.user = user; 11.90 - } 11.91 - 11.92 - public void setPassword(String pass) { 11.93 - this.password = pass; 11.94 - } 11.95 - 11.96 - public String getUser() { 11.97 - return user; 11.98 - } 11.99 - 11.100 - public String getPassword() { 11.101 - return password; 11.102 - } 11.103 - 11.104 - /** 11.105 - * Returns a URL (actually a {@link String}) for establishing connections 11.106 - * to an endpoint based on the information given to the constructor. 11.107 - * 11.108 - * @return 11.109 - */ 11.110 - protected String getConnectionURL() { 11.111 - return "http://" + host + ":" + port + "/" + endpointName; 11.112 - } 11.113 -}
12.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpoint.java Fri Nov 02 13:50:36 2012 +0200 12.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 12.3 @@ -1,89 +0,0 @@ 12.4 -/** 12.5 - * This Source Code Form is subject to the terms of the Mozilla Public 12.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 12.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 12.8 - * 12.9 - * Copyright (C) 2012, Pyravlos Team 12.10 - * 12.11 - * http://www.strabon.di.uoa.gr/ 12.12 - */ 12.13 -package eu.earthobservatory.org.StrabonEndpoint.client; 12.14 - 12.15 -import java.io.IOException; 12.16 -import java.net.URL; 12.17 - 12.18 -import org.apache.commons.httpclient.methods.PostMethod; 12.19 -import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 12.20 -import org.openrdf.rio.RDFFormat; 12.21 - 12.22 -/** 12.23 - * This class is the implementation of a java client for accessing 12.24 - * StrabonEndpoint instances. 12.25 - * 12.26 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 12.27 - */ 12.28 -public class StrabonEndpoint extends SpatialEndpointImpl { 12.29 - 12.30 - public StrabonEndpoint(String host, int port) { 12.31 - super(host, port); 12.32 - } 12.33 - 12.34 - public StrabonEndpoint(String host, int port, String endpointName) { 12.35 - super(host, port, endpointName); 12.36 - } 12.37 - 12.38 - @Override 12.39 - public EndpointResult query(String sparqlQuery, stSPARQLQueryResultFormat format) throws IOException { 12.40 - assert(format != null); 12.41 - 12.42 - // create a post method to execute 12.43 - PostMethod method = new PostMethod(getConnectionURL() + "/Query"); 12.44 - 12.45 - // set the query parameter 12.46 - method.setParameter("query", sparqlQuery); 12.47 - 12.48 - // set the accept format 12.49 - method.addRequestHeader("Accept", format.getDefaultMIMEType()); 12.50 - //System.out.println(method.getRequestHeader("Accept")); 12.51 - 12.52 - try { 12.53 - // execute the method 12.54 - int statusCode = hc.executeMethod(method); 12.55 - 12.56 - return new StrabonEndpointResult(statusCode, method.getStatusText(), method.getResponseBodyAsString()); 12.57 - 12.58 - } catch (IOException e) { 12.59 - throw e; 12.60 - 12.61 - } finally { 12.62 - // release the connection. 12.63 - method.releaseConnection(); 12.64 - } 12.65 - } 12.66 - 12.67 - @Override 12.68 - public boolean store(String data, RDFFormat format) { 12.69 - return false; 12.70 - } 12.71 - 12.72 - @Override 12.73 - public boolean store(URL data, RDFFormat format) { 12.74 - return false; 12.75 - } 12.76 - 12.77 - @Override 12.78 - public boolean update(String sparqlUpdate) { 12.79 - return false; 12.80 - } 12.81 - 12.82 - @Override 12.83 - public EndpointResult describe(String sparqlDescribe) { 12.84 - return null; 12.85 - } 12.86 - 12.87 - @Override 12.88 - public EndpointResult construct(String sparqlConstruct) { 12.89 - return null; 12.90 - } 12.91 - 12.92 -}
13.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpointResult.java Fri Nov 02 13:50:36 2012 +0200 13.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 13.3 @@ -1,42 +0,0 @@ 13.4 -/** 13.5 - * This Source Code Form is subject to the terms of the Mozilla Public 13.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 13.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13.8 - * 13.9 - * Copyright (C) 2012, Pyravlos Team 13.10 - * 13.11 - * http://www.strabon.di.uoa.gr/ 13.12 - */ 13.13 -package eu.earthobservatory.org.StrabonEndpoint.client; 13.14 - 13.15 -/** 13.16 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 13.17 - * 13.18 - */ 13.19 -public class StrabonEndpointResult implements EndpointResult { 13.20 - 13.21 - private int statusCode; 13.22 - private String statusText; 13.23 - private String response; 13.24 - 13.25 - public StrabonEndpointResult(int statusCode, String statusLine, String response) { 13.26 - this.statusCode = statusCode; 13.27 - this.statusText = statusLine; 13.28 - this.response = response; 13.29 - } 13.30 - 13.31 - @Override 13.32 - public int getStatusCode() { 13.33 - return statusCode; 13.34 - } 13.35 - 13.36 - @Override 13.37 - public String getStatusText() { 13.38 - return statusText; 13.39 - } 13.40 - 13.41 - @Override 13.42 - public String getResponse() { 13.43 - return response; 13.44 - } 13.45 -}
14.1 --- a/endpoint/src/test/java/eu/earthobservatory/org/StrabonEndpoint/client/TestStrabonEndpoint.java Fri Nov 02 13:50:36 2012 +0200 14.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 14.3 @@ -1,85 +0,0 @@ 14.4 -/** 14.5 - * This Source Code Form is subject to the terms of the Mozilla Public 14.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 14.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 14.8 - * 14.9 - * Copyright (C) 2012, Pyravlos Team 14.10 - * 14.11 - * http://www.strabon.di.uoa.gr/ 14.12 - */ 14.13 -package eu.earthobservatory.org.StrabonEndpoint.client; 14.14 - 14.15 -import static org.junit.Assert.assertTrue; 14.16 - 14.17 -import java.io.IOException; 14.18 -import java.util.Vector; 14.19 - 14.20 -import org.junit.Before; 14.21 -import org.junit.Test; 14.22 -import org.openrdf.query.resultio.TupleQueryResultFormat; 14.23 -import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 14.24 - 14.25 -/** 14.26 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 14.27 - * 14.28 - */ 14.29 -public class TestStrabonEndpoint { 14.30 - 14.31 - private StrabonEndpoint endpoint; 14.32 - private String query; 14.33 - private Vector<stSPARQLQueryResultFormat> formats = new Vector<stSPARQLQueryResultFormat>(); 14.34 - 14.35 - @Before 14.36 - public void init() { 14.37 - // initialize endpoint 14.38 - endpoint = new StrabonEndpoint("test.strabon.di.uoa.gr", 80, "DLR"); 14.39 - 14.40 - // set query 14.41 - query = "PREFIX teleios:<http://teleios.di.uoa.gr/ontologies/noaOntology.owl#>\n" + 14.42 - "SELECT ?s ?g WHERE {\n" + 14.43 - " ?s teleios:hasGeometry ?g\n" + 14.44 - "}" + 14.45 - "\nLIMIT 1"; 14.46 - 14.47 - // initialized formats 14.48 - for (TupleQueryResultFormat format : stSPARQLQueryResultFormat.values()) { 14.49 - if (format instanceof stSPARQLQueryResultFormat) { 14.50 - formats.add((stSPARQLQueryResultFormat) format); 14.51 - } 14.52 - } 14.53 - 14.54 - } 14.55 - 14.56 - /** 14.57 - * Test method for {@link eu.earthobservatory.org.StrabonEndpoint.client.StrabonEndpoint#query(java.lang.String, org.openrdf.query.resultio.stSPARQLQueryResultFormat)}. 14.58 - */ 14.59 - @Test 14.60 - public void testQuery() { 14.61 - for (stSPARQLQueryResultFormat format : formats) { 14.62 - try { 14.63 - EndpointResult response = endpoint.query(query, format); 14.64 - 14.65 - if (response.getStatusCode() != 200) { 14.66 - System.err.println("Status code ("+response.getStatusCode()+"):" + response.getStatusText()); 14.67 - 14.68 - } 14.69 - 14.70 - assertTrue(response.getStatusCode() == 200); 14.71 - 14.72 - } catch (IOException e) { 14.73 - e.printStackTrace(); 14.74 - } 14.75 - 14.76 - } 14.77 - } 14.78 - 14.79 - /** 14.80 - * Test method for testing that method {@link eu.earthobservatory.org.StrabonEndpoint.client.StrabonEndpoint#query(java.lang.String, org.openrdf.query.resultio.stSPARQLQueryResultFormat)}. 14.81 - * returns an IOException when it should do so. 14.82 - */ 14.83 - @Test(expected= IOException.class) 14.84 - public void testIOException() throws Exception { 14.85 - StrabonEndpoint ep = new StrabonEndpoint("blabla.dgr", 80, "bla"); 14.86 - ep.query(query, formats.get(0)); 14.87 - } 14.88 -}