Strabon

changeset 228:788831ebb99b

removed handler.startRDF() statement, because it is called from the parser
replaced e.getStackTrace() by just "e"
handle exceptions during store in StoreOp by closing the connection of Strabon and logging the respective error.
author Babis Nikolaou <charnik@di.uoa.gr>
date Sat Jun 02 19:11:53 2012 +0300 (2012-06-02)
parents d9d201dcc4c6
children 0077ec91f90b
files endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java runtime/src/main/java/eu/earthobservatory/runtime/postgis/StoreOp.java
line diff
     1.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Sat Jun 02 18:33:58 2012 +0300
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Sat Jun 02 19:11:53 2012 +0300
     1.3 @@ -36,6 +36,7 @@
     1.4  import org.springframework.web.context.support.WebApplicationContextUtils;
     1.5  
     1.6  import eu.earthobservatory.org.StrabonEndpoint.StrabonBeanWrapper.Entry;
     1.7 +import eu.earthobservatory.org.StrabonEndpoint.ResponseMessages;
     1.8  
     1.9  
    1.10  public class QueryBean extends HttpServlet {
     2.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Sat Jun 02 18:33:58 2012 +0300
     2.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Sat Jun 02 19:11:53 2012 +0300
     2.3 @@ -121,7 +121,7 @@
     2.4  		try {
     2.5  			repo1.initialize();
     2.6  		} catch (RepositoryException e) {
     2.7 -			logger.error("[Strabon.init] initialize", e.getStackTrace());
     2.8 +			logger.error("[Strabon.init] initialize", e);
     2.9  		}
    2.10  
    2.11  		logger.info("[Strabon.init] Clearing Successful.");
    2.12 @@ -129,7 +129,7 @@
    2.13  		try {
    2.14  			con1 = repo1.getConnection();
    2.15  		} catch (RepositoryException e) {
    2.16 -			logger.error("[Strabon.init] getConnection", e.getStackTrace());
    2.17 +			logger.error("[Strabon.init] getConnection", e);
    2.18  		}
    2.19  	}
    2.20  
    2.21 @@ -154,7 +154,7 @@
    2.22  			repo1.shutDown();
    2.23  			
    2.24  		} catch (RepositoryException e) {
    2.25 -			logger.error("[Strabon.close]", e.getStackTrace());
    2.26 +			logger.error("[Strabon.close]", e);
    2.27  		}
    2.28  		
    2.29  		logger.info("[Strabon.close] Connection closed.");
    2.30 @@ -364,7 +364,7 @@
    2.31  
    2.32  						} 
    2.33  						catch (ParseException e) {
    2.34 -							logger.error("[Strabon.query] Faults detected in spatial literal representation.", e.getStackTrace());
    2.35 +							logger.error("[Strabon.query] Faults detected in spatial literal representation.", e);
    2.36  						}
    2.37  					}
    2.38  
    2.39 @@ -372,9 +372,9 @@
    2.40  					try {
    2.41  						geomCRS = CRS.decode("EPSG:"+SRID);
    2.42  					} catch (NoSuchAuthorityCodeException e) {
    2.43 -						logger.error("[Strabon.query] Error decoding returned geometry's SRID", e.getStackTrace());
    2.44 +						logger.error("[Strabon.query] Error decoding returned geometry's SRID", e);
    2.45  					} catch (FactoryException e) {
    2.46 -						logger.error("[Strabon.query]", e.getStackTrace());
    2.47 +						logger.error("[Strabon.query]", e);
    2.48  					}
    2.49  
    2.50  					tb[i].setCRS(geomCRS);
    2.51 @@ -575,12 +575,12 @@
    2.52  					//				out.writeChars(bindingSet.toString());
    2.53  				}
    2.54  			} catch (QueryEvaluationException e) {
    2.55 -				logger.error("[Strabon.query]", e.getStackTrace());
    2.56 +				logger.error("[Strabon.query]", e);
    2.57  			}
    2.58  			try {
    2.59  				dos.close();
    2.60  			} catch (IOException e) {
    2.61 -				logger.error("[Strabon.query]", e.getStackTrace());
    2.62 +				logger.error("[Strabon.query]", e);
    2.63  			}
    2.64  
    2.65  			//Finishing the structure of the kml document
    2.66 @@ -682,7 +682,7 @@
    2.67  				}
    2.68  
    2.69  			} catch (IOException e) {
    2.70 -				logger.error("[Strabon.query]", e.getStackTrace());
    2.71 +				logger.error("[Strabon.query]", e);
    2.72  			}
    2.73  		}
    2.74  		else if(resultsFormat.equalsIgnoreCase("HTML")) {
    2.75 @@ -751,7 +751,7 @@
    2.76  			writeOut.flush();
    2.77  			retStream.flush();
    2.78  		} catch (IOException e) {
    2.79 -			logger.error("[Strabon.query]", e.getStackTrace());
    2.80 +			logger.error("[Strabon.query]", e);
    2.81  		}
    2.82  
    2.83  		// Print results.
    2.84 @@ -768,7 +768,7 @@
    2.85  		try {
    2.86  			update = con.prepareUpdate(QueryLanguage.SPARQL, updateString);
    2.87  		} catch (RepositoryException e) {
    2.88 -			logger.error("[Strabon.update]", e.getStackTrace());
    2.89 +			logger.error("[Strabon.update]", e);
    2.90  		}
    2.91  
    2.92  		//System.out.println("Placemark0");
    2.93 @@ -778,7 +778,7 @@
    2.94  		try {
    2.95  			update.execute();
    2.96  		} catch (UpdateExecutionException e) {
    2.97 -			logger.error("[Strabon.update]", e.getStackTrace());
    2.98 +			logger.error("[Strabon.update]", e);
    2.99  		}
   2.100  
   2.101  //		System.out.println("-------------------------------------------");
   2.102 @@ -855,11 +855,14 @@
   2.103  
   2.104  		InputStream in = (InputStream) url.openStream();
   2.105  		InputStreamReader reader = new InputStreamReader(in);
   2.106 +		
   2.107  		RDFParser parser = Rio.createParser(format);
   2.108 +		
   2.109  		GeosparqlRDFHandlerBase handler = new GeosparqlRDFHandlerBase();
   2.110 -		handler.startRDF();
   2.111 +		
   2.112  		parser.setRDFHandler(handler);
   2.113  		parser.parse(reader, "");
   2.114 +		
   2.115  		logger.info("[Strabon.storeURL] Inferred " + handler.getNumberOfTriples() + " triples.");
   2.116  		if (handler.getNumberOfTriples() > 0) {
   2.117  			logger.info("[Strabon.storeURL] Triples inferred:"+ handler.getTriples().toString());
   2.118 @@ -889,12 +892,14 @@
   2.119  		logger.info("[Strabon.storeString] Format   : " + ((format == null) ? "null" : format.toString()));
   2.120  
   2.121  		StringReader reader = new StringReader(text);
   2.122 +		
   2.123  		RDFParser parser = Rio.createParser(format);
   2.124 +		
   2.125  		GeosparqlRDFHandlerBase handler = new GeosparqlRDFHandlerBase();
   2.126 -
   2.127 -		handler.startRDF();
   2.128 +		
   2.129  		parser.setRDFHandler(handler);
   2.130  		parser.parse(reader, "");
   2.131 +		
   2.132  		logger.info("[Strabon.storeString] Inferred " + handler.getNumberOfTriples() + " triples.");
   2.133  		if (handler.getNumberOfTriples() > 0) {
   2.134  			logger.info("[Strabon.storeString] Triples inferred:"+ handler.getTriples().toString());
   2.135 @@ -921,7 +926,7 @@
   2.136  		try {
   2.137  			graphQuery = con.prepareGraphQuery(QueryLanguage.SPARQL, describeString);
   2.138  		} catch (RepositoryException e) {
   2.139 -			logger.error("[Strabon.describe]", e.getStackTrace());
   2.140 +			logger.error("[Strabon.describe]", e);
   2.141  		}
   2.142  
   2.143  //		System.out.println("Placemark0");
   2.144 @@ -935,13 +940,13 @@
   2.145  			out.close();
   2.146  			
   2.147  		} catch (FileNotFoundException e) {
   2.148 -			logger.error("[Strabon.describe]", e.getStackTrace());
   2.149 +			logger.error("[Strabon.describe]", e);
   2.150  		} catch (QueryEvaluationException e) {
   2.151 -			logger.error("[Strabon.describe]", e.getStackTrace());
   2.152 +			logger.error("[Strabon.describe]", e);
   2.153  		} catch (RDFHandlerException e) {
   2.154 -			logger.error("[Strabon.describe]", e.getStackTrace());
   2.155 +			logger.error("[Strabon.describe]", e);
   2.156  		} catch (IOException e) {
   2.157 -			logger.error("[Strabon.describe]", e.getStackTrace());
   2.158 +			logger.error("[Strabon.describe]", e);
   2.159  		}
   2.160  
   2.161  		logger.info("[Strabon.describe] Output: "+outFile);
     3.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/StoreOp.java	Sat Jun 02 18:33:58 2012 +0300
     3.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/StoreOp.java	Sat Jun 02 19:11:53 2012 +0300
     3.3 @@ -1,15 +1,17 @@
     3.4  package eu.earthobservatory.runtime.postgis;
     3.5  
     3.6 -import java.io.File;
     3.7 -
     3.8 +import org.slf4j.Logger;
     3.9 +import org.slf4j.LoggerFactory;
    3.10  
    3.11  public class StoreOp {
    3.12  
    3.13 +	private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.runtime.postgis.StoreOp.class); 
    3.14 +	
    3.15  	/**
    3.16  	 * @param args
    3.17  	 * @throws Exception 
    3.18  	 */
    3.19 -	public static void main(String[] args) throws Exception {
    3.20 +	public static void main(String[] args) {
    3.21  
    3.22  		if (args.length < 6) {
    3.23  			System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <FILE> [<FORMAT>]");
    3.24 @@ -35,12 +37,16 @@
    3.25  			format = args[6];
    3.26  		}
    3.27  
    3.28 -		Strabon strabon = new Strabon(db, user, passwd, port, host, true);
    3.29 -
    3.30 -		strabon.storeInRepo(src, format);
    3.31 -//		strabon.storeInRepo(file, null, null, fileRDFFormat);
    3.32 -
    3.33 -		strabon.close();
    3.34 +		Strabon strabon = null;
    3.35 +		try {
    3.36 +			strabon = new Strabon(db, user, passwd, port, host, true);
    3.37 +			strabon.storeInRepo(src, format);
    3.38 +			strabon.close();
    3.39 +		} catch (Exception e) {
    3.40 +			logger.error("[Strabon.StoreOp] Error during store.", e);
    3.41 +		} finally {
    3.42 +			strabon.close();
    3.43 +		}
    3.44  	}
    3.45  
    3.46  }