Strabon

changeset 673:7fda2cf3acef

made StrabonEndpoint.query() more robust by using httpclient.setParameter() to do the job for setting the query parameters
author Babis Nikolaou <charnik@di.uoa.gr>
date Wed Oct 31 00:06:47 2012 +0200 (2012-10-31)
parents 50c80c0f01a2
children 322e3050c7e1
files endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpoint.java endpoint/src/test/java/eu/earthobservatory/org/StrabonEndpoint/client/TestStrabonEndpoint.java
line diff
     1.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpoint.java	Tue Oct 30 23:58:41 2012 +0200
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpoint.java	Wed Oct 31 00:06:47 2012 +0200
     1.3 @@ -11,9 +11,7 @@
     1.4  
     1.5  import java.io.IOException;
     1.6  import java.net.URL;
     1.7 -import java.net.URLEncoder;
     1.8  
     1.9 -import org.apache.commons.httpclient.HttpMethod;
    1.10  import org.apache.commons.httpclient.methods.PostMethod;
    1.11  import org.openrdf.query.resultio.stSPARQLQueryResultFormat;
    1.12  import org.openrdf.rio.RDFFormat;
    1.13 @@ -37,21 +35,15 @@
    1.14  	@Override
    1.15  	public EndpointResult query(String sparqlQuery, stSPARQLQueryResultFormat format) throws IOException {
    1.16  		// create a post method to execute
    1.17 -		HttpMethod method = new PostMethod(getConnectionURL() + "/Query");
    1.18 +		PostMethod method = new PostMethod(getConnectionURL() + "/Query");
    1.19  		
    1.20  		// set the query parameter
    1.21 -		method.setQueryString("query="+ URLEncoder.encode(sparqlQuery, "UTF-8"));
    1.22 -		
    1.23 -		// set the content type
    1.24 -		method.setRequestHeader("Content-Type", PostMethod.FORM_URL_ENCODED_CONTENT_TYPE);
    1.25 -		//System.out.println(method.getRequestHeader("Content-type"));
    1.26 +		method.setParameter("query", sparqlQuery);
    1.27  		
    1.28  		// set the accept format
    1.29  		method.addRequestHeader("Accept", format.getDefaultMIMEType());
    1.30  		//System.out.println(method.getRequestHeader("Accept"));
    1.31  		
    1.32 -		//System.out.println(method.getURI());
    1.33 -
    1.34  		try {
    1.35  			// execute the method
    1.36  			int statusCode = hc.executeMethod(method);
     2.1 --- a/endpoint/src/test/java/eu/earthobservatory/org/StrabonEndpoint/client/TestStrabonEndpoint.java	Tue Oct 30 23:58:41 2012 +0200
     2.2 +++ b/endpoint/src/test/java/eu/earthobservatory/org/StrabonEndpoint/client/TestStrabonEndpoint.java	Wed Oct 31 00:06:47 2012 +0200
     2.3 @@ -55,6 +55,7 @@
     2.4  						System.err.println("Status code ("+response.getStatusCode()+"):" + response.getStatusText());
     2.5  						
     2.6  					}
     2.7 +					
     2.8  					assertTrue(response.getStatusCode() == 200);
     2.9  					
    2.10  				}