Strabon

changeset 485:3a0e2d2bf1a0

Now DescribeBean looks the "accept" parameter to determine the RDF format to use in the answer.
Notice that "format" parameter is favored over "accept", thus if both are present, the second is
simply ignored.
When "format" parameter is not one of the accepted RDF types, an error is returned, wrapped in a
XML document. When "format" parameter is not present and "accept" parameter is not present or it
is of an invalid value (non accepted mime type), an error IS NOT returned and we fall back to
HTML mode (e.g., assume that the request was done from the HTML interface of the endpoint). This
might be something that we would like to change. We are not software house after all.

Better going, cause I am rambling a lot.
author Babis Nikolaou <charnik@di.uoa.gr>
date Sat Jul 21 02:08:39 2012 +0300 (2012-07-21)
parents 119576ba1127
children f227e7725f21 86e5ba1d801a
files endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java
line diff
     1.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.java	Fri Jul 20 19:57:44 2012 +0300
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.java	Sat Jul 21 02:08:39 2012 +0300
     1.3 @@ -29,10 +29,6 @@
     1.4  
     1.5      private static final long serialVersionUID = -7541662133934957148L;
     1.6  
     1.7 -	/**
     1.8 -	* @param args
     1.9 -	* @throws Exception
    1.10 -	*/
    1.11  	private StrabonBeanWrapper strabonWrapper;
    1.12  
    1.13      @Override
    1.14 @@ -51,10 +47,10 @@
    1.15  			query = URLDecoder.decode(request.getParameter("SPARQLQuery"), "UTF-8");	
    1.16  		}
    1.17  		
    1.18 -		String reqFormat = request.getParameter("format");
    1.19 -		//String reqAccept = request.getHeader("accept");
    1.20 +		// get the RDF format (checks the "format" and then the "accept" parameters)
    1.21 +        String reqFormat = getFormat(request);
    1.22  		
    1.23 -		if (reqFormat == null || reqFormat.equals("HTML")) {
    1.24 +		if (reqFormat == null || reqFormat.equals("HTML")) { // browser view
    1.25  			response.setContentType("text/html; charset=UTF-8");
    1.26  		    reqFormat = "HTML";
    1.27  		    
    1.28 @@ -131,6 +127,39 @@
    1.29  	    }
    1.30  	}
    1.31  	
    1.32 +    /**
    1.33 +     * Determines the RDF format to use. If the client has specified
    1.34 +     * the "format" parameter, then it is favored over the "accept"
    1.35 +     * parameter. If "format" is not specified, we determine the RDF 
    1.36 +     * format according to the "accept" parameter. 
    1.37 +     * 
    1.38 +     * @param request
    1.39 +     * @return
    1.40 +     */
    1.41 +    private String getFormat(HttpServletRequest request) {
    1.42 +        
    1.43 +        String reqFormat = request.getParameter("format");
    1.44 +        
    1.45 +        if (reqFormat == null) {
    1.46 +                String reqAccept = request.getHeader("accept");
    1.47 +                
    1.48 +                if (reqAccept != null) {
    1.49 +                        // check whether the "accept" parameter contains any 
    1.50 +                        // of the mime types of any RDF format
    1.51 +                        for (RDFFormat format : RDFFormat.values()) {
    1.52 +                                for (String mimeType : format.getMIMETypes()) {
    1.53 +                                        if (reqAccept.contains(mimeType)) {
    1.54 +                                                reqFormat = format.getName();
    1.55 +                                                break;
    1.56 +                                        }
    1.57 +                                }
    1.58 +                        }
    1.59 +                }
    1.60 +        }
    1.61 +                
    1.62 +                return reqFormat;
    1.63 +    }
    1.64 +
    1.65      @Override
    1.66  	public void init(ServletConfig servletConfig) throws ServletException {
    1.67  		super.init(servletConfig);
     2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Fri Jul 20 19:57:44 2012 +0300
     2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Sat Jul 21 02:08:39 2012 +0300
     2.3 @@ -240,7 +240,6 @@
     2.4  		strabon.describe(queryString, answerFormatStrabon, strabon.getSailRepoConnection(), out);
     2.5  	}
     2.6  
     2.7 -
     2.8  	public Object update(String updateString, String answerFormatStrabon) 
     2.9  	throws MalformedQueryException, RepositoryException, QueryEvaluationException, 
    2.10  	TupleQueryResultHandlerException, IOException, ClassNotFoundException {