Strabon
changeset 671:24a6e7d423eb
added interface (EndpointResult) for the return type of the answer of an endpoint. Added a prototypical implementation for StrabonEndpoint
author | Babis Nikolaou <charnik@di.uoa.gr> |
---|---|
date | Tue Oct 30 22:38:05 2012 +0200 (2012-10-30) |
parents | f443dfe30f78 |
children | 50c80c0f01a2 |
files | 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/StrabonEndpoint.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpointResult.java |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/EndpointResult.java Tue Oct 30 22:38:05 2012 +0200 1.3 @@ -0,0 +1,35 @@ 1.4 +/** 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.8 + * 1.9 + * Copyright (C) 2012, Pyravlos Team 1.10 + * 1.11 + * http://www.strabon.di.uoa.gr/ 1.12 + */ 1.13 +package eu.earthobservatory.org.StrabonEndpoint.client; 1.14 + 1.15 +/** 1.16 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 1.17 + * 1.18 + */ 1.19 +public interface EndpointResult { 1.20 + 1.21 + /** 1.22 + * Returns the HTTP status code as returned by the endpoint. 1.23 + * @return 1.24 + */ 1.25 + public int getStatusCode(); 1.26 + 1.27 + /** 1.28 + * Returns the status text corresponding to the status code. 1.29 + * @return 1.30 + */ 1.31 + public String getStatusText(); 1.32 + 1.33 + /** 1.34 + * Returns the response of the endpoint. 1.35 + * @return 1.36 + */ 1.37 + public String getResponse(); 1.38 +}
2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpoint.java Tue Oct 30 21:37:56 2012 +0200 2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpoint.java Tue Oct 30 22:38:05 2012 +0200 2.3 @@ -24,7 +24,7 @@ 2.4 */ 2.5 public interface SpatialEndpoint { 2.6 2.7 - public String query(String sparqlQuery, stSPARQLQueryResultFormat format) throws IOException; 2.8 + public EndpointResult query(String sparqlQuery, stSPARQLQueryResultFormat format) throws IOException; 2.9 2.10 public boolean store(String data, RDFFormat format); 2.11 2.12 @@ -32,7 +32,7 @@ 2.13 2.14 public boolean update(String sparqlUpdate); 2.15 2.16 - public boolean describe(String sparqlDescribe); 2.17 + public EndpointResult describe(String sparqlDescribe); 2.18 2.19 - public boolean construct(String sparqlConstruct); 2.20 + public EndpointResult construct(String sparqlConstruct); 2.21 }
3.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpoint.java Tue Oct 30 21:37:56 2012 +0200 3.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpoint.java Tue Oct 30 22:38:05 2012 +0200 3.3 @@ -13,7 +13,6 @@ 3.4 import java.net.URL; 3.5 3.6 import org.apache.commons.httpclient.HttpMethod; 3.7 -import org.apache.commons.httpclient.HttpStatus; 3.8 import org.apache.commons.httpclient.methods.PostMethod; 3.9 import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 3.10 import org.openrdf.rio.RDFFormat; 3.11 @@ -31,7 +30,7 @@ 3.12 } 3.13 3.14 @Override 3.15 - public String query(String sparqlQuery, stSPARQLQueryResultFormat format) throws IOException { 3.16 + public EndpointResult query(String sparqlQuery, stSPARQLQueryResultFormat format) throws IOException { 3.17 // create a post method to execute 3.18 HttpMethod method = new PostMethod(getConnectionURL()); 3.19 3.20 @@ -45,18 +44,15 @@ 3.21 // execute the method 3.22 int statusCode = hc.executeMethod(method); 3.23 3.24 - // check the status code 3.25 - if (statusCode != HttpStatus.SC_OK) { 3.26 - System.err.println("Method failed: " + method.getStatusLine()); 3.27 - } 3.28 - 3.29 // Read the response body. 3.30 byte[] responseBody = method.getResponseBody(); 3.31 3.32 // Deal with the response. 3.33 // Use caution: ensure correct character encoding and is not binary 3.34 // data 3.35 - return new String(responseBody); 3.36 + String response = new String(responseBody); 3.37 + 3.38 + return new StrabonEndpointResult(statusCode, method.getStatusText(), response); 3.39 3.40 } catch (IOException e) { 3.41 throw e; 3.42 @@ -83,13 +79,13 @@ 3.43 } 3.44 3.45 @Override 3.46 - public boolean describe(String sparqlDescribe) { 3.47 - return false; 3.48 + public EndpointResult describe(String sparqlDescribe) { 3.49 + return null; 3.50 } 3.51 3.52 @Override 3.53 - public boolean construct(String sparqlConstruct) { 3.54 - return false; 3.55 + public EndpointResult construct(String sparqlConstruct) { 3.56 + return null; 3.57 } 3.58 3.59 }
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpointResult.java Tue Oct 30 22:38:05 2012 +0200 4.3 @@ -0,0 +1,42 @@ 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 +/** 4.16 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 4.17 + * 4.18 + */ 4.19 +public class StrabonEndpointResult implements EndpointResult { 4.20 + 4.21 + private int statusCode; 4.22 + private String statusText; 4.23 + private String response; 4.24 + 4.25 + public StrabonEndpointResult(int statusCode, String statusLine, String response) { 4.26 + this.statusCode = statusCode; 4.27 + this.statusText = statusLine; 4.28 + this.response = response; 4.29 + } 4.30 + 4.31 + @Override 4.32 + public int getStatusCode() { 4.33 + return statusCode; 4.34 + } 4.35 + 4.36 + @Override 4.37 + public String getStatusText() { 4.38 + return statusText; 4.39 + } 4.40 + 4.41 + @Override 4.42 + public String getResponse() { 4.43 + return response; 4.44 + } 4.45 +}