Strabon

changeset 204:52a5a4007d33

added logging to Strabon Endpoint
author Babis Nikolaou <charnik@di.uoa.gr>
date Wed May 30 16:08:55 2012 +0300 (2012-05-30)
parents 69aca279a848
children a683d1837836
files endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StoreBean.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/UpdateBean.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java
line diff
     1.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Wed May 30 15:13:08 2012 +0300
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Wed May 30 16:08:55 2012 +0300
     1.3 @@ -2,7 +2,6 @@
     1.4  
     1.5  import java.io.BufferedWriter;
     1.6  import java.io.File;
     1.7 -import java.io.FileInputStream;
     1.8  import java.io.FileOutputStream;
     1.9  import java.io.FileWriter;
    1.10  import java.io.IOException;
    1.11 @@ -13,7 +12,6 @@
    1.12  import java.security.SecureRandom;
    1.13  import java.util.Date;
    1.14  import java.util.HashMap;
    1.15 -import java.util.Hashtable;
    1.16  import java.util.Iterator;
    1.17  import java.util.List;
    1.18  import java.util.Map;
    1.19 @@ -32,6 +30,8 @@
    1.20  import org.openrdf.query.QueryEvaluationException;
    1.21  import org.openrdf.query.TupleQueryResultHandlerException;
    1.22  import org.openrdf.repository.RepositoryException;
    1.23 +import org.slf4j.Logger;
    1.24 +import org.slf4j.LoggerFactory;
    1.25  import org.springframework.web.context.WebApplicationContext;
    1.26  import org.springframework.web.context.support.WebApplicationContextUtils;
    1.27  
    1.28 @@ -42,18 +42,20 @@
    1.29  
    1.30  	private static final long serialVersionUID = -378175118289907707L;
    1.31  
    1.32 +	private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.org.StrabonEndpoint.QueryBean.class);
    1.33 +	
    1.34  	private ServletContext context; 
    1.35  	private StrabonBeanWrapper strabonWrapper;
    1.36  
    1.37  	public void doGet(HttpServletRequest request, HttpServletResponse response)
    1.38 -			throws ServletException, IOException
    1.39 -			{
    1.40 +	throws ServletException, IOException 
    1.41 +	{
    1.42  		doPost(request, response);
    1.43 -			}
    1.44 +	}
    1.45  
    1.46  	public void doPost(HttpServletRequest request, HttpServletResponse response)
    1.47 -			throws ServletException, IOException
    1.48 -			{
    1.49 +	throws ServletException, IOException
    1.50 +	{
    1.51  		final class DataHive{
    1.52  			private String format;
    1.53  			private String SPARQLQuery;
    1.54 @@ -172,7 +174,7 @@
    1.55  		}
    1.56  
    1.57  		PrintWriter out = response.getWriter();
    1.58 -                out.flush();
    1.59 +        out.flush();
    1.60  
    1.61  		if ((hive.getFormat().equalsIgnoreCase("KML")) || (hive.getFormat().equalsIgnoreCase("KMZ"))) {
    1.62  			StringBuilder errorMessage = new StringBuilder ();
    1.63 @@ -265,7 +267,7 @@
    1.64  				//FileUtils.forceDeleteOnExit(new File((String) context.getRealPath("/") + "/../ROOT/tmp/" + temp + ".kml"));
    1.65  
    1.66  			} catch(IOException e) {
    1.67 -				e.printStackTrace();
    1.68 +				logger.error("[StrabonEndpoint.QueryBean] " + e.getStackTrace());
    1.69  			}
    1.70  
    1.71  			//response.setDateHeader("Expires", 0);			
    1.72 @@ -381,7 +383,7 @@
    1.73  			appendHTML5(out);
    1.74  		}
    1.75  		out.flush();
    1.76 -			}
    1.77 +	}
    1.78  
    1.79  	public void init(ServletConfig servletConfig) throws ServletException {
    1.80  		super.init(servletConfig);
    1.81 @@ -403,25 +405,25 @@
    1.82  				answer = (String) strabonWrapper.query(SPARQLQuery, resultFormat);
    1.83  			}
    1.84  		} catch (MalformedQueryException e) {
    1.85 -			e.printStackTrace();
    1.86 +			logger.error("[StrabonEndpoint.QueryBean] ", e.getStackTrace());
    1.87  			errorMessage.append(e.getMessage());
    1.88  		} catch (RepositoryException e) {
    1.89 -			e.printStackTrace();
    1.90 +			logger.error("[StrabonEndpoint.QueryBean] ", e.getStackTrace());
    1.91  			errorMessage.append(e.getMessage());
    1.92  		} catch (QueryEvaluationException e) {
    1.93 -			e.printStackTrace();
    1.94 +			logger.error("[StrabonEndpoint.QueryBean] ", e.getStackTrace());
    1.95  			errorMessage.append(e.getMessage());
    1.96  		} catch (TupleQueryResultHandlerException e) {
    1.97 -			e.printStackTrace();
    1.98 +			logger.error("[StrabonEndpoint.QueryBean] ", e.getStackTrace());
    1.99  			errorMessage.append(e.getMessage());
   1.100  		} catch (IOException e) {
   1.101 -			e.printStackTrace();
   1.102 +			logger.error("[StrabonEndpoint.QueryBean] ", e.getStackTrace());
   1.103  			errorMessage.append(e.getMessage());
   1.104  		} catch (ClassNotFoundException e) {
   1.105 -			e.printStackTrace();
   1.106 +			logger.error("[StrabonEndpoint.QueryBean] ", e.getStackTrace());
   1.107  			errorMessage.append(e.getMessage());
   1.108  		} catch (Exception e) {
   1.109 -			e.printStackTrace();
   1.110 +			logger.error("[StrabonEndpoint.QueryBean] ", e.getStackTrace());
   1.111  			errorMessage.append(e.getMessage());
   1.112  		}
   1.113  
   1.114 @@ -541,7 +543,6 @@
   1.115  			out.println(" value=\"" + key + "\">" + value + "</option>");
   1.116  		}
   1.117  		
   1.118 -		
   1.119  		out.println("</select></center></td>");
   1.120  		out.println("</tr>");
   1.121  		out.println("<tr>");
     2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StoreBean.java	Wed May 30 15:13:08 2012 +0300
     2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StoreBean.java	Wed May 30 16:08:55 2012 +0300
     2.3 @@ -15,6 +15,8 @@
     2.4  
     2.5  import org.openrdf.rio.RDFFormat;
     2.6  import org.openrdf.rio.RDFParseException;
     2.7 +import org.slf4j.Logger;
     2.8 +import org.slf4j.LoggerFactory;
     2.9  import org.springframework.web.context.WebApplicationContext;
    2.10  import org.springframework.web.context.support.WebApplicationContextUtils;
    2.11  
    2.12 @@ -26,6 +28,8 @@
    2.13  	
    2.14  	private static final long serialVersionUID = -7541662133934957148L;
    2.15  	
    2.16 +	private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.org.StrabonEndpoint.StoreBean.class);
    2.17 +	
    2.18  	/**
    2.19  	 * Parameters used in the store.jsp file
    2.20  	 */
    2.21 @@ -145,7 +149,7 @@
    2.22  					response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    2.23  				}
    2.24  			}
    2.25 -			System.err.println(e.getMessage());
    2.26 +			logger.error("[StrabonEndpoint.StoreBean] " + e.getMessage());
    2.27  		}
    2.28  	}
    2.29  	
     3.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Wed May 30 15:13:08 2012 +0300
     3.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Wed May 30 16:08:55 2012 +0300
     3.3 @@ -3,13 +3,11 @@
     3.4  import java.io.IOException;
     3.5  import java.io.StringReader;
     3.6  import java.net.URL;
     3.7 -import java.sql.Array;
     3.8  import java.sql.SQLException;
     3.9  import java.util.ArrayList;
    3.10  import java.util.Iterator;
    3.11  import java.util.List;
    3.12  
    3.13 -import org.hsqldb.lib.Collection;
    3.14  import org.openrdf.model.Resource;
    3.15  import org.openrdf.query.MalformedQueryException;
    3.16  import org.openrdf.query.QueryEvaluationException;
    3.17 @@ -17,10 +15,14 @@
    3.18  import org.openrdf.repository.RepositoryException;
    3.19  import org.openrdf.repository.sail.SailRepositoryConnection;
    3.20  import org.openrdf.rio.RDFFormat;
    3.21 +import org.slf4j.Logger;
    3.22 +import org.slf4j.LoggerFactory;
    3.23  
    3.24  import eu.earthobservatory.runtime.postgis.Strabon;
    3.25  
    3.26  public class StrabonBeanWrapper implements org.springframework.beans.factory.DisposableBean {
    3.27 +	private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.org.StrabonEndpoint.StrabonBeanWrapper.class);
    3.28 +	
    3.29  	public class Entry {
    3.30  		private String label;
    3.31  		private String bean;
    3.32 @@ -168,13 +170,12 @@
    3.33  	private boolean init() {
    3.34  		if (this.strabon == null) {
    3.35  			try {
    3.36 -				System.err.println("Strabon not initialized yet.");
    3.37 -				System.err.println("Initializing strabon.");
    3.38 -				System.out.println(this.getDetails());
    3.39 +				logger.warn("Strabon not initialized yet.");
    3.40 +				logger.warn("Initializing strabon.");
    3.41 +				logger.warn(this.getDetails());
    3.42  				this.strabon = new Strabon(databaseName, user, password, port, serverName, checkForLockTable);
    3.43  			} catch (Exception e) {
    3.44 -				System.err.println("Exception occured while creating Strabon.\n"+this.getDetails());
    3.45 -				e.printStackTrace();
    3.46 +				logger.error("Exception occured while creating Strabon.\n"+this.getDetails(), e.getStackTrace());
    3.47  				return false;
    3.48  			}
    3.49  		}
    3.50 @@ -198,9 +199,9 @@
    3.51  		strabon.close();
    3.52  	}
    3.53  
    3.54 -
    3.55 -
    3.56 -	public Object query(String queryString, String answerFormatStrabon) throws MalformedQueryException, RepositoryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, ClassNotFoundException {
    3.57 +	public Object query(String queryString, String answerFormatStrabon)
    3.58 +	throws MalformedQueryException, RepositoryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, ClassNotFoundException {
    3.59 +		logger.info("[StrabonEndpoint] Received SELECT query.");
    3.60  		if ((this.strabon == null) && (!init())) {
    3.61  			throw new RepositoryException("Could not connect to Strabon.");
    3.62  		} 
    3.63 @@ -208,19 +209,22 @@
    3.64  		return strabon.query(queryString, answerFormatStrabon, strabon.getSailRepoConnection());
    3.65  	}
    3.66  
    3.67 -	public Object update(String updateString, String answerFormatStrabon) throws MalformedQueryException, RepositoryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, ClassNotFoundException {
    3.68 +	public Object update(String updateString, String answerFormatStrabon) 
    3.69 +	throws MalformedQueryException, RepositoryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, ClassNotFoundException {
    3.70 +		logger.info("[StrabonEndpoint] Received UPDATE query.");
    3.71 +		logger.info("[StrabonEndpoint] Answer format: " + answerFormatStrabon);
    3.72 +		
    3.73  		if ((this.strabon == null) && (!init())) {
    3.74  			throw new RepositoryException("Could not connect to Strabon.");
    3.75  		} 
    3.76 -
    3.77 +		
    3.78  		//String newQueryString = TemporalWrapper.rebuildQuery(queryString);
    3.79  
    3.80 -		System.out.println("================================================================");
    3.81 -		System.out.println("Update:");
    3.82 -		System.out.println(updateString);
    3.83 -		System.out.println("================================================================");
    3.84 -		System.out.println("Answer format: " + answerFormatStrabon);
    3.85 -		System.out.println("================================================================");
    3.86 +//		System.out.println("================================================================");
    3.87 +//		System.out.println("Update:");
    3.88 +//		System.out.println(updateString);
    3.89 +//		System.out.println("================================================================");
    3.90 +//		System.out.println("================================================================");
    3.91  		//System.out.println("Rewritten query:");
    3.92  		//System.out.println(newQueryString);
    3.93  		//System.out.println("================================================================");
    3.94 @@ -248,6 +252,8 @@
    3.95  	 * @throws ClassNotFoundException
    3.96  	 */
    3.97  	public boolean store(String source_data, RDFFormat format, boolean url) throws Exception {
    3.98 +		logger.info("[StrabonEndpoint] Received store request.");
    3.99 +		
   3.100  		if ((this.strabon == null) && (!init())) {
   3.101  			throw new RepositoryException("Could not connect to Strabon.");
   3.102  		}
     4.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/UpdateBean.java	Wed May 30 15:13:08 2012 +0300
     4.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/UpdateBean.java	Wed May 30 16:08:55 2012 +0300
     4.3 @@ -13,6 +13,8 @@
     4.4  import javax.servlet.http.HttpServletResponse;
     4.5  
     4.6  import org.openrdf.query.MalformedQueryException;
     4.7 +import org.slf4j.Logger;
     4.8 +import org.slf4j.LoggerFactory;
     4.9  import org.springframework.web.context.WebApplicationContext;
    4.10  import org.springframework.web.context.support.WebApplicationContextUtils;
    4.11  
    4.12 @@ -24,6 +26,8 @@
    4.13  
    4.14  	private static final long serialVersionUID = -633279376188071670L;
    4.15  
    4.16 +	private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.org.StrabonEndpoint.UpdateBean.class);
    4.17 +	
    4.18  	private StrabonBeanWrapper strabonWrapper;
    4.19  	
    4.20  	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    4.21 @@ -50,6 +54,7 @@
    4.22  				throw new MalformedQueryException("No SPARQL Update query specified.");
    4.23  			}
    4.24  			
    4.25 +			logger.info("[StrabonEndpoint.UpdateBean] Received UPDATE query.");
    4.26  			strabonWrapper.getStrabon().update(query, strabonWrapper.getStrabon().getSailRepoConnection());
    4.27  			response.setStatus(HttpServletResponse.SC_OK);
    4.28  			answer = "true";
     5.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Wed May 30 15:13:08 2012 +0300
     5.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Wed May 30 16:08:55 2012 +0300
     5.3 @@ -180,6 +180,7 @@
     5.4  	public Object query(String queryString, String resultsFormat, SailRepositoryConnection con)
     5.5  	throws  MalformedQueryException, QueryEvaluationException, IOException, TupleQueryResultHandlerException 
     5.6  	{
     5.7 +		logger.info("[Strabon.query] Executing query: " + queryString);
     5.8  		TupleQuery tupleQuery = null;
     5.9  		try {
    5.10  			tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);