Strabon

changeset 100:298c806608c2

fixes bug in /Update when SPARQLQuery parameter is not specified, leading to NullPointerException
introduces a new class, ResponseMessages, which currently has only three static methods for constructing the XML response used in /Update and /Query (only for error cases)
author Babis Nikolaou <charnik@di.uoa.gr>
date Thu Apr 05 20:26:47 2012 +0300 (2012-04-05)
parents e0285c06da6a
children 6238e91405a3
files endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/UpdateBean.java
line diff
     1.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Thu Apr 05 20:28:55 2012 +0300
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Thu Apr 05 20:26:47 2012 +0300
     1.3 @@ -226,9 +226,9 @@
     1.4  				response.getWriter().append(answer);
     1.5  				
     1.6  			} else {
     1.7 -				response.getWriter().append(UpdateBean.getUPDATEHeaderResponse());
     1.8 -				response.getWriter().append(UpdateBean.getExceptionError(answer));
     1.9 -				response.getWriter().append(UpdateBean.getUPDATEFooterResponse());
    1.10 +				response.getWriter().append(ResponseMessages.getXMLHeader());
    1.11 +				response.getWriter().append(ResponseMessages.getXMLException(answer));
    1.12 +				response.getWriter().append(ResponseMessages.getXMLFooter());
    1.13  			}
    1.14  			
    1.15  		} else { // HTML
     2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/UpdateBean.java	Thu Apr 05 20:28:55 2012 +0300
     2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/UpdateBean.java	Thu Apr 05 20:26:47 2012 +0300
     2.3 @@ -46,41 +46,22 @@
     2.4  		
     2.5  		String answer = "";
     2.6  		try {
     2.7 +			if (query == null) {
     2.8 +				throw new MalformedQueryException("No SPARQL Update query specified.");
     2.9 +			}
    2.10 +			
    2.11  			strabonWrapper.getStrabon().update(query, strabonWrapper.getStrabon().getSailRepoConnection());
    2.12  			response.setStatus(HttpServletResponse.SC_OK);
    2.13  			answer = "true";
    2.14  			
    2.15  		} catch(MalformedQueryException e) {
    2.16  			response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    2.17 -			answer = getExceptionError(e.getMessage());
    2.18 +			answer = ResponseMessages.getXMLException(e.getMessage());
    2.19  		}
    2.20  		
    2.21  		// write response to client
    2.22 -		response.getWriter().append(UpdateBean.getUPDATEHeaderResponse());
    2.23 +		response.getWriter().append(ResponseMessages.getXMLHeader());
    2.24  		response.getWriter().append(answer);
    2.25 -		response.getWriter().append(UpdateBean.getUPDATEFooterResponse());
    2.26 +		response.getWriter().append(ResponseMessages.getXMLFooter());
    2.27  	}
    2.28 -	
    2.29 -	/**
    2.30 -	 * Used as the template answer for UPDATE queries.
    2.31 -	 * @return
    2.32 -	 */
    2.33 -	public static String getUPDATEHeaderResponse() {
    2.34 -		return "<?xml version='1.0' encoding='UTF-8'?>\n" +
    2.35 -			   "<response>\n" +
    2.36 -			   "\t";
    2.37 -	}
    2.38 -	
    2.39 -	/**
    2.40 -	 * Used as the template answer for UPDATE queries.
    2.41 -	 * @return
    2.42 -	 */
    2.43 -	public static String getUPDATEFooterResponse() {
    2.44 -		return "\n</response>\n";
    2.45 -	}
    2.46 -	
    2.47 -	public static String getExceptionError(String msg) {
    2.48 -		return "<exception>\n"+msg+"\n\t</exception>";
    2.49 -	}
    2.50 -
    2.51  }