Strabon

changeset 86:64d3889773a9

made Update queries return an XML response instead of just setting the HTPP code
author Babis Nikolaou <charnik@di.uoa.gr>
date Wed Apr 04 16:02:04 2012 +0300 (2012-04-04)
parents 965d0bb83d84
children e1a54ea341b2
files endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java
line diff
     1.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Wed Apr 04 14:14:09 2012 +0300
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Wed Apr 04 16:02:04 2012 +0300
     1.3 @@ -154,16 +154,21 @@
     1.4  		StrabonBeanWrapper strabonWrapper = (StrabonBeanWrapper)applicationContext.getBean("strabonBean");
     1.5  		
     1.6  		if (isUpdate) {
     1.7 +			String answer = "";
     1.8  			try {
     1.9  				strabonWrapper.getStrabon().update(hive.getSPARQLQuery(), strabonWrapper.getStrabon().getSailRepoConnection());
    1.10  				response.setStatus(HttpServletResponse.SC_OK);
    1.11 +				answer = "true";
    1.12  				
    1.13  			} catch(MalformedQueryException e) {
    1.14  				response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    1.15 -				PrintWriter out = response.getWriter();
    1.16 -				e.printStackTrace(out);
    1.17 +				answer = "<exception>\n"+e.getMessage()+"\n\t</exception>";
    1.18  			}
    1.19  			
    1.20 +			// write response to client
    1.21 +			response.getWriter().append(getHeaderResponse());
    1.22 +			response.getWriter().append(answer);
    1.23 +			response.getWriter().append(getFooterResponse());
    1.24  			return;
    1.25  		}
    1.26  
    1.27 @@ -307,6 +312,16 @@
    1.28  		out.flush();
    1.29  	}
    1.30  
    1.31 +	private String getHeaderResponse() {
    1.32 +		return "<?xml version='1.0' encoding='UTF-8'?>\n" +
    1.33 +			   "<response>\n" +
    1.34 +			   "\t";
    1.35 +	}
    1.36 +	
    1.37 +	private String getFooterResponse() {
    1.38 +		return "\n</response>\n";
    1.39 +	}
    1.40 +
    1.41  	public void init(ServletConfig servletConfig) throws ServletException {
    1.42  		super.init(servletConfig);
    1.43  	}