Strabon

changeset 1428:c3c98bd8540d

fixed bugs #49 and #65; we do not do any decode on the query that is sent through the forms of the strabon endpoint beans; this is already handlded by the container
author Babis Nikolaou <charnik@di.uoa.gr>
date Thu Sep 25 20:02:41 2014 +0300 (2014-09-25)
parents 014379fdddf2
children 6c9d1293752a
files endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/BrowseBean.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StoreBean.java resultio-spatial/sparqlhtml/src/main/java/org/openrdf/query/resultio/sparqlhtml/stSPARQLResultsHTMLWriter.java
line diff
     1.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/BrowseBean.java	Wed Sep 24 17:43:53 2014 +0300
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/BrowseBean.java	Thu Sep 25 20:02:41 2014 +0300
     1.3 @@ -11,7 +11,6 @@
     1.4  
     1.5  import java.io.ByteArrayOutputStream;
     1.6  import java.io.IOException;
     1.7 -import java.net.URLDecoder;
     1.8  
     1.9  import javax.servlet.RequestDispatcher;
    1.10  import javax.servlet.ServletConfig;
    1.11 @@ -77,8 +76,7 @@
    1.12  				.getWebApplicationContext(context);
    1.13  
    1.14  		// the the strabon wrapper
    1.15 -		strabonWrapper = (StrabonBeanWrapper) applicationContext
    1.16 -				.getBean("strabonBean");
    1.17 +		strabonWrapper = (StrabonBeanWrapper) applicationContext.getBean("strabonBean");
    1.18  
    1.19  	}
    1.20  
    1.21 @@ -146,7 +144,9 @@
    1.22  
    1.23  		} else {
    1.24  			// decode the query
    1.25 -			query = URLDecoder.decode(request.getParameter("query"), "UTF-8");
    1.26 +			// do not decode the SPARQL query (see bugs #65 and #49)
    1.27 +			//query = URLDecoder.decode(request.getParameter("query"), "UTF-8");
    1.28 +			query = request.getParameter("query");
    1.29  
    1.30  			response.setContentType(format.getDefaultMIMEType());
    1.31  			try {
    1.32 @@ -176,7 +176,9 @@
    1.33  	private void processVIEWRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    1.34  		RequestDispatcher dispatcher;
    1.35  
    1.36 -		String query = URLDecoder.decode(request.getParameter("query"), "UTF-8");
    1.37 +		// do not decode the SPARQL query (see bugs #65 and #49)
    1.38 +		//String query = URLDecoder.decode(request.getParameter("query"), "UTF-8");
    1.39 +		String query = request.getParameter("query");
    1.40  		String format = request.getParameter("format");
    1.41  		
    1.42  		// get stSPARQLQueryResultFormat from given format name
     2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.java	Wed Sep 24 17:43:53 2014 +0300
     2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.java	Thu Sep 25 20:02:41 2014 +0300
     2.3 @@ -11,7 +11,6 @@
     2.4  
     2.5  import java.io.ByteArrayOutputStream;
     2.6  import java.io.IOException;
     2.7 -import java.net.URLDecoder;
     2.8  
     2.9  import javax.servlet.RequestDispatcher;
    2.10  import javax.servlet.ServletConfig;
    2.11 @@ -109,7 +108,10 @@
    2.12  		// get the dispatcher for forwarding the rendering of the response
    2.13  		RequestDispatcher dispatcher = request.getRequestDispatcher("describe.jsp");
    2.14  		
    2.15 -		String query = URLDecoder.decode(request.getParameter("query"), "UTF-8");
    2.16 +		// do not decode the SPARQL query (see bugs #65 and #49)
    2.17 +		//String query = URLDecoder.decode(request.getParameter("query"), "UTF-8");
    2.18 +		String query = request.getParameter("query");
    2.19 +		
    2.20  		String format = request.getParameter("format");
    2.21  		String handle = request.getParameter("handle");
    2.22  		RDFFormat rdfFormat = RDFFormat.valueOf(format);
    2.23 @@ -188,8 +190,8 @@
    2.24  			out.print(ResponseMessages.getXMLFooter());
    2.25      		
    2.26      	} else {
    2.27 -    		// decode the query
    2.28 -    		query = URLDecoder.decode(request.getParameter("query"), "UTF-8");
    2.29 +    		// do not decode the SPARQL query (see bugs #65 and #49)
    2.30 +    		//query = URLDecoder.decode(request.getParameter("query"), "UTF-8");
    2.31      		
    2.32  	    	response.setContentType(format.getDefaultMIMEType());
    2.33  		    response.setHeader("Content-Disposition", 
     3.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Wed Sep 24 17:43:53 2014 +0300
     3.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Thu Sep 25 20:02:41 2014 +0300
     3.3 @@ -3,7 +3,7 @@
     3.4   * License, v. 2.0. If a copy of the MPL was not distributed with this
     3.5   * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     3.6   * 
     3.7 - * Copyright (C) 2010, 2011, 2012, Pyravlos Team
     3.8 + * Copyright (C) 2010, 2011, 2012, 2013, 2014 Pyravlos Team
     3.9   * 
    3.10   * http://www.strabon.di.uoa.gr/
    3.11   */
    3.12 @@ -14,7 +14,6 @@
    3.13  import java.io.FileOutputStream;
    3.14  import java.io.IOException;
    3.15  import java.math.BigInteger;
    3.16 -import java.net.URLDecoder;
    3.17  import java.security.SecureRandom;
    3.18  import java.util.ArrayList;
    3.19  import java.util.Date;
    3.20 @@ -189,8 +188,9 @@
    3.21  			// just use the first specified format
    3.22  			stSPARQLQueryResultFormat format = formats.get(0);
    3.23  		
    3.24 -			// decode the query
    3.25 -			query = URLDecoder.decode(request.getParameter("query"), "UTF-8");
    3.26 +			// do not decode the SPARQL query (see bugs #65 and #49)
    3.27 +			//query = URLDecoder.decode(request.getParameter("query"), "UTF-8");
    3.28 +			query = request.getParameter("query");
    3.29  			
    3.30  	    	response.setContentType(format.getDefaultMIMEType());
    3.31  	    	
    3.32 @@ -231,7 +231,10 @@
    3.33  			dispatcher.forward(request, response);
    3.34  			
    3.35  		} else {
    3.36 -			String query = URLDecoder.decode(request.getParameter("query"), "UTF-8");
    3.37 +			// do not decode the SPARQL query (see bugs #65 and #49)
    3.38 +			//String query = URLDecoder.decode(request.getParameter("query"), "UTF-8");
    3.39 +			
    3.40 +			String query = request.getParameter("query");
    3.41  			String format = request.getParameter("format");
    3.42  			String handle = request.getParameter("handle");
    3.43  			String maxLimit = request.getParameter("maxLimit");
     4.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StoreBean.java	Wed Sep 24 17:43:53 2014 +0300
     4.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StoreBean.java	Thu Sep 25 20:02:41 2014 +0300
     4.3 @@ -13,8 +13,6 @@
     4.4  import java.io.UnsupportedEncodingException;
     4.5  import java.net.InetAddress;
     4.6  import java.net.MalformedURLException;
     4.7 -import java.net.URLDecoder;
     4.8 -import java.util.Map;
     4.9  
    4.10  import javax.servlet.RequestDispatcher;
    4.11  import javax.servlet.ServletConfig;
    4.12 @@ -31,7 +29,6 @@
    4.13  import org.springframework.web.context.WebApplicationContext;
    4.14  import org.springframework.web.context.support.WebApplicationContextUtils;
    4.15  
    4.16 -
    4.17  /**
    4.18   * 
    4.19   * @author Charalampos Nikolaou <charnik@di.uoa.gr>
    4.20 @@ -95,7 +92,6 @@
    4.21  	
    4.22  	@Override
    4.23  	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    4.24 -   	         	
    4.25  		doPost(request, response);	
    4.26  	}
    4.27  	
    4.28 @@ -103,13 +99,15 @@
    4.29  		// check whether we read from INPUT or URL
    4.30  		boolean input = (request.getParameter(Common.SUBMIT_URL) != null) ? false:true;
    4.31  		
    4.32 -		// return "data" value accordingly
    4.33 -		return input ? URLDecoder.decode(request.getParameter(Common.PARAM_DATA), "UTF-8"):request.getParameter(Common.PARAM_DATA_URL);
    4.34 +		// return "data" value accordingly, but do not decode the RDF input data (see bugs #65 and #49)
    4.35 +		//return input ? URLDecoder.decode(request.getParameter(Common.PARAM_DATA), "UTF-8"):request.getParameter(Common.PARAM_DATA_URL);
    4.36 +		return input ? request.getParameter(Common.PARAM_DATA):request.getParameter(Common.PARAM_DATA_URL);
    4.37  	}
    4.38  	
    4.39  	@Override
    4.40  	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    4.41 -						 
    4.42 +		request.setCharacterEncoding("UTF-8");
    4.43 +		
    4.44  		boolean authorized;
    4.45  		
    4.46  		if(!isLocalClient(request)) {
    4.47 @@ -117,9 +115,10 @@
    4.48  			String authorization = request.getHeader("Authorization");
    4.49  	   		
    4.50  			authorized = authenticate.authenticateUser(authorization, context);
    4.51 +			
    4.52 +		} else {
    4.53 +			authorized = true;
    4.54  		}
    4.55 -		else
    4.56 -			authorized = true;
    4.57  				
    4.58  	   	 if (!authorized) {	   		 
    4.59  	   		 // not allowed, so report he's unauthorized
    4.60 @@ -129,7 +128,8 @@
    4.61  	   	 else {	 		
    4.62  			// check whether the request was from store.jsp
    4.63  			if (Common.VIEW_TYPE.equals(request.getParameter(Common.VIEW))) {
    4.64 -				processVIEWRequest(request, response);				
    4.65 +				processVIEWRequest(request, response);
    4.66 +				
    4.67  			} else {
    4.68  				processRequest(request, response);
    4.69  			}
    4.70 @@ -154,6 +154,7 @@
    4.71      			
    4.72      	// RDF data to store
    4.73      	String data = getData(request);
    4.74 +    	System.out.println(data);
    4.75      			
    4.76      	// the format of the data
    4.77      	RDFFormat format = (request.getParameter(Common.PARAM_FORMAT) != null) ? RDFFormat.valueOf(request.getParameter(Common.PARAM_FORMAT)):null;
     5.1 --- a/resultio-spatial/sparqlhtml/src/main/java/org/openrdf/query/resultio/sparqlhtml/stSPARQLResultsHTMLWriter.java	Wed Sep 24 17:43:53 2014 +0300
     5.2 +++ b/resultio-spatial/sparqlhtml/src/main/java/org/openrdf/query/resultio/sparqlhtml/stSPARQLResultsHTMLWriter.java	Thu Sep 25 20:02:41 2014 +0300
     5.3 @@ -145,7 +145,12 @@
     5.4  								         "(?predicate = <"+ boundValue.toString()+ ">)  || "+
     5.5  								         "(?object = <"+ boundValue.toString()+ ">)) " +  
     5.6  								"}";
     5.7 -							href = "Browse?view=HTML&query="+URLEncoder.encode(query, "UTF-8")+"&format=HTML&resource="+URLEncoder.encode(boundValue.toString(), "UTF-8");						
     5.8 +							
     5.9 +							// FIXME maybe using URLEncoder.encode() for encoding the query and the "boundValue" 
    5.10 +							// is not the proper way to encode the final URL (see related bugs #65 and #49), but
    5.11 +							// I am not 100% sure
    5.12 +							href = "Browse?view=HTML&query="+URLEncoder.encode(query, "UTF-8")+"&format=HTML&resource="+URLEncoder.encode(boundValue.toString(), "UTF-8");
    5.13 +							
    5.14  						}
    5.15  						else{							
    5.16  							href = boundValue.toString();