From 6fe7cfc182e537222dc1ba98e4e7e51e15e0c12d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr> Date: Sat, 9 Mar 2013 18:20:23 +0000 Subject: [PATCH] - Adopted slf4j in server --- .../exmo/align/service/AlignmentService.java | 67 +++++++------------ .../exmo/align/service/HTMLAServProfile.java | 23 ++++--- .../exmo/align/service/WSAServProfile.java | 21 +++--- .../exmo/align/service/WSAlignment.java | 10 ++- .../service/msg/CannotRenderAlignment.java | 2 +- .../exmo/align/service/msg/ErrorMsg.java | 10 ++- 6 files changed, 69 insertions(+), 64 deletions(-) diff --git a/src/fr/inrialpes/exmo/align/service/AlignmentService.java b/src/fr/inrialpes/exmo/align/service/AlignmentService.java index 0bbbccc3..773d6a79 100644 --- a/src/fr/inrialpes/exmo/align/service/AlignmentService.java +++ b/src/fr/inrialpes/exmo/align/service/AlignmentService.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2006-2009, 2010 + * Copyright (C) INRIA, 2006-2009, 2010, 2013 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -26,6 +26,9 @@ import fr.inrialpes.exmo.queryprocessor.Type; import fr.inrialpes.exmo.align.util.NullStream; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import gnu.getopt.LongOpt; import gnu.getopt.Getopt; @@ -50,7 +53,6 @@ import java.lang.reflect.InvocationTargetException; <pre> --load=filename -l filename Load previous image --params=filename -p filename Read the parameters in file - --debug[=n] -d [n] Report debug info at level n, --help -h Print this message </pre> @@ -58,9 +60,10 @@ import java.lang.reflect.InvocationTargetException; $Id$ </pre> - * @author J�r�me Euzenat + * @author Jérôme Euzenat */ public class AlignmentService { + final static Logger logger = LoggerFactory.getLogger( AlignmentService.class ); public String //DBMS Parameters DBHOST = "localhost", @@ -79,7 +82,6 @@ public class AlignmentService { public static final String //IP Strings HOST = "localhost"; - private int debug = 0; private String filename = null; private String outfile = null; private String paramfile = null; @@ -102,11 +104,8 @@ public class AlignmentService { if ( outfile != null ) { // This redirects error outout to log file given by -o System.setErr( new PrintStream( outfile ) ); - } else if ( debug <= 0 ){ - // This cancels all writing on the error output (default) - System.setErr( new PrintStream( new NullStream() ) ); - } - if ( debug > 0 ) System.err.println("Parameter parsed"); + } + logger.debug("Parameter parsed"); // Shut down hook Runtime.getRuntime().addShutdownHook(new Thread(){ @@ -114,45 +113,45 @@ public class AlignmentService { // Connect database if( DBMS.equals("postgres") ) { - if ( debug > 0 ) System.err.println("postgres driver"); + logger.debug("postgres driver"); DBPORT = "5432"; connection = new DBServiceImpl( "org.postgresql.Driver" , "jdbc:postgresql", DBPORT ); } else { - if ( debug > 0 ) System.err.println("mysql driver"); + logger.debug("mysql driver"); DBPORT = "3306"; connection = new DBServiceImpl( "com.mysql.jdbc.Driver" , "jdbc:mysql", DBPORT ); } connection.init(); connection.connect( DBHOST, DBPORT, DBUSER, DBPASS, DBBASE ); - if ( debug > 0 ) System.err.println("Database connected"); + logger.debug("Database connected"); // Create a AServProtocolManager manager = new AServProtocolManager( directories ); manager.init( connection, params ); - if ( debug > 0 ) System.err.println("Manager created"); + logger.debug("Manager created"); // Launch services for ( AlignmentServiceProfile serv : services.values() ) { try { serv.init( params, manager ); - if ( debug > 0 ) System.err.println(serv+" launched on http://"+params.getProperty( "host" )+":"+params.getProperty( "http" )+"/html/"); + Object[] mm = {serv, params.getProperty( "host" ), params.getProperty( "http" ) }; + logger.info("{} launched on http://{}:{}/html/", mm); } catch ( AServException ex ) { - System.err.println( "Couldn't start "+serv+" server on http://"+params.getProperty( "host" )+":"+params.getProperty( "http" )+"/html/:\n"); - // Ideally remove the service - ex.printStackTrace(); + Object[] mm = {serv, params.getProperty( "host" ), params.getProperty( "http" ) }; + logger.warn("Cannot start {} server on http://{}:{}/html/", mm); } } // Register to directories for ( Directory dir : directories.values() ) { try { dir.open( params ); - if ( debug > 0 ) System.err.println(dir+" connected."); + logger.debug("{} connected.", dir); } catch ( AServException ex ) { - System.err.println( "Couldn't connect to "+dir+" directory"); + logger.warn( "Cannot connect to {} directory", dir ); + logger.debug( "IGNORED Connection exception", ex ); // JE: this has to be done //directories.remove( name, dir ); - ex.printStackTrace(); } } @@ -164,13 +163,13 @@ public class AlignmentService { } protected void close(){ - if (debug > 0 ) System.err.println("Shuting down server"); + logger.debug("Shuting down server"); // [Directory]: unregister to directories for ( Directory dir : directories.values() ) { try { dir.close(); } catch ( AServException ex ) { - System.err.println("Cannot unregister to "+dir); - ex.printStackTrace(); + logger.warn("Cannot unregister from {}", dir); + logger.debug("IGNORED", ex); } } // Close services @@ -185,7 +184,7 @@ public class AlignmentService { // Shut down database connection manager.close(); connection.close(); - if ( debug > 0 ) System.err.println("Database connection closed"); + logger.debug("Database connection closed"); System.err.close(); } @@ -252,10 +251,10 @@ public class AlignmentService { filename = g.getOptarg(); break; case 'd' : - /* Debug level */ + /* DEPRECATED: Debug level */ arg = g.getOptarg(); - if ( arg != null ) debug = Integer.parseInt( arg.trim() ); - else debug = 4; + System.err.println( "WARNING: debug argument is deprecated, use logging" ); + System.err.println( "See http://alignapi.gforge.inria.fr/logging.html" ); break; case 'i' : /* external service */ @@ -402,19 +401,6 @@ public class AlignmentService { } } - if (debug > 0) { - params.setProperty( "debug", Integer.toString( debug ) ); - } else if ( params.getProperty( "debug" ) != null ) { - debug = Integer.parseInt( params.getProperty( "debug" ) ); - } - - // We add (for debugging purposes) the command lines as arguments - String argline = ""; - for ( int i = args.length - 1; i >= 0; i-- ) { - argline = args[i]+" "+argline; - } - params.setProperty( "argline", argline ); - return params; } @@ -441,7 +427,6 @@ public class AlignmentService { System.err.println("\t--dbmspass=pwd -p pwd\t\t\tUse DBMS password"); System.err.println("\t--dbmsbase=name -b name\t\t\tUse Database name"); System.err.println("\t--dbms=name -B name\t\t\tUse Database Management System"); - System.err.println("\t--debug[=n] -d[n]\t\tReport debug info at level n"); System.err.println("\t-Dparam=value\t\t\tSet parameter"); System.err.println("\t--help -h\t\t\tPrint this message"); diff --git a/src/fr/inrialpes/exmo/align/service/HTMLAServProfile.java b/src/fr/inrialpes/exmo/align/service/HTMLAServProfile.java index 001ce720..f0d8478c 100644 --- a/src/fr/inrialpes/exmo/align/service/HTMLAServProfile.java +++ b/src/fr/inrialpes/exmo/align/service/HTMLAServProfile.java @@ -77,16 +77,19 @@ import org.mortbay.jetty.Server; import org.mortbay.jetty.Request; import org.mortbay.servlet.MultiPartFilter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * HTMLAServProfile: an HTML provile for the Alignment server * It embeds an HTTP server. */ public class HTMLAServProfile implements AlignmentServiceProfile { + final static Logger logger = LoggerFactory.getLogger( HTMLAServProfile.class ); private int tcpPort; private String tcpHost; - private int debug = 0; private Server server; private AServProtocolManager manager; private WSAServProfile wsmanager; @@ -140,7 +143,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { Thread t = new Thread( new Runnable() { public void run() { try { while( true ) new HTTPSession( ss.accept()); - } catch ( IOException ioe ) { ioe.printStackTrace(); } + } catch ( IOException ioe ) { logger.debug( "IGNORED Exception", ioe ); } } }); t.setDaemon( true ); @@ -207,8 +210,8 @@ public class HTMLAServProfile implements AlignmentServiceProfile { char [] mess = new char[length+1]; try { new BufferedReader(new InputStreamReader(request.getInputStream())).read( mess, 0, length); - } catch (Exception e) { - e.printStackTrace(); // To clean up + } catch ( Exception e ) { + logger.debug( "IGNORED Exception", e ); } params.setProperty( "content", new String( mess ) ); } @@ -271,7 +274,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { if ( wsmanager != null ) wsmanager.close(); if ( server != null ) { try { server.stop(); } - catch (Exception e) { e.printStackTrace(); } + catch (Exception e) { logger.debug( "IGNORED Exception on close", e ); } } } @@ -291,7 +294,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { * @return HTTP response, see class Response for details */ public Response serve( String uri, String method, Properties header, Properties parms ) { - if ( debug >= 1 ) System.err.println( method + " '" + uri + "' " ); + logger.debug( "{} '{}'", method, uri ); Enumeration en = header.propertyNames(); while ( en.hasMoreElements()) { String value = (String)en.nextElement(); @@ -300,7 +303,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { // Convert parms to parameters Properties params = new Properties(); for ( String key : parms.stringPropertyNames() ) { - if ( debug > 1 ) System.err.println( " PRM: '" + key + "' = '" +parms.getProperty( key ) + "'" ); + //logger.trace( " PRM: '{}' = '{}'", key, parms.getProperty( key ) ); if ( key.startsWith( "paramn" ) ){ params.setProperty( parms.getProperty( key ), parms.getProperty( "paramv"+key.substring( 6 ) ) ); @@ -385,7 +388,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { * Allows some limited administration of the server through HTTP */ public Response adminAnswer( String uri, String perf, Properties header, Properties params ) { - if ( debug > 0 ) System.err.println("ADMIN["+perf+"]"); + logger.debug( "ADMIN[{}]", perf); String msg = ""; if ( perf.equals("listmethods") ){ msg = "<h1>Embedded classes</h1>\n<h2>Methods</h2><ul compact=\"1\">"; @@ -487,7 +490,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { * uses the protocol but offers user-targeted interaction */ public Response htmlAnswer( String uri, String perf, Properties header, Properties params ) { - //System.err.println("HTML["+perf+"]"); + //logger.trace("HTML[{}]", perf ); // REST get String msg = ""; if ( perf.equals("listalignments") ) { @@ -746,7 +749,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { else params.setProperty("method", "fr.inrialpes.exmo.align.impl.renderer.XMLMetadataRendererVisitor"); Message answer = manager.render( new Message(newId(),(Message)null,myId,serverId,"", params) ); - //System.err.println("Content: "+answer.getContent()); + //logger.trace( "Content: {}", answer.getContent() ); if ( answer instanceof ErrorMsg ) { msg = testErrorMessages( answer, params ); } else { diff --git a/src/fr/inrialpes/exmo/align/service/WSAServProfile.java b/src/fr/inrialpes/exmo/align/service/WSAServProfile.java index 3bc3acab..8043f555 100644 --- a/src/fr/inrialpes/exmo/align/service/WSAServProfile.java +++ b/src/fr/inrialpes/exmo/align/service/WSAServProfile.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2007-2012 + * Copyright (C) INRIA, 2007-2013 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -68,6 +68,9 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * WSAServProfile: a SOAP and REST over HTTP provile for the Alignment server * It uses the HTTP server of HTTPAServProfile @@ -80,10 +83,10 @@ import org.xml.sax.SAXException; */ public class WSAServProfile implements AlignmentServiceProfile { + final static Logger logger = LoggerFactory.getLogger( WSAServProfile.class ); private int tcpPort; private String tcpHost; - private int debug = 0; private AServProtocolManager manager; private static String wsdlSpec = ""; @@ -159,7 +162,7 @@ public class WSAServProfile implements AlignmentServiceProfile { // in particular it does not deal with section'ed MANISFESTs Attributes mainAttributes = jar.getManifest().getMainAttributes(); String path = mainAttributes.getValue( Name.CLASS_PATH ); - if ( debug > 0 ) System.err.println(" >CP> "+path); + logger.debug(" >CP> "+path); if ( path != null && !path.equals("") ) { // JE: Not sure where to find the other Jars: // in the path or at the local place? @@ -167,7 +170,7 @@ public class WSAServProfile implements AlignmentServiceProfile { } } } catch (NullPointerException nullexp) { //Raised by JarFile - System.err.println("Warning "+file+" unavailable"); + logger.warn( "IGNORED Warning {} unavailable", file ); } } } @@ -177,7 +180,7 @@ public class WSAServProfile implements AlignmentServiceProfile { } } } catch (IOException ioex) { - ioex.printStackTrace(); + logger.debug( "IGNORED Exception", ioex ); } } @@ -224,10 +227,10 @@ public class WSAServProfile implements AlignmentServiceProfile { try { domMessage = BUILDER.parse( new ByteArrayInputStream( message.getBytes()) ); } catch ( IOException ioex ) { - ioex.printStackTrace(); + logger.debug( "IGNORED Exception", ioex ); answer = new NonConformParameters(0,(Message)null,myId,"Cannot Parse SOAP message",message,(Properties)null); } catch ( SAXException saxex ) { - saxex.printStackTrace(); + logger.debug( "IGNORED Exception", saxex ); answer = new NonConformParameters(0,(Message)null,myId,"Cannot Parse SOAP message",message,(Properties)null); } newparameters = getParameters( domMessage ); @@ -442,9 +445,9 @@ public class WSAServProfile implements AlignmentServiceProfile { } } } catch (XPathExpressionException e) { - System.err.println( "[getParameters] XPath exception: should not occur"); + logger.warn( "[getParameters] XPath exception: should not occur"); } catch (NullPointerException e) { - System.err.println( "[getParameters] NullPointerException: should not occur"); + logger.warn( "[getParameters] NullPointerException: should not occur"); } return params; } diff --git a/src/fr/inrialpes/exmo/align/service/WSAlignment.java b/src/fr/inrialpes/exmo/align/service/WSAlignment.java index 382f4575..abe3e634 100644 --- a/src/fr/inrialpes/exmo/align/service/WSAlignment.java +++ b/src/fr/inrialpes/exmo/align/service/WSAlignment.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2008-2011 + * Copyright (C) INRIA, 2008-2011, 2013 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -63,6 +63,9 @@ import fr.inrialpes.exmo.align.impl.Annotations; import fr.inrialpes.exmo.align.impl.Namespace; import fr.inrialpes.exmo.align.parser.AlignmentParser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * This is an AlignmentProcess which perform matching by connecting * to an AlignmentServer and retrieving or computing an alignment. @@ -74,6 +77,7 @@ import fr.inrialpes.exmo.align.parser.AlignmentParser; */ public class WSAlignment extends URIAlignment implements AlignmentProcess { + final static Logger logger = LoggerFactory.getLogger( WSAlignment.class ); private URL SOAPUrl = null; /** @@ -209,7 +213,9 @@ public class WSAlignment extends URIAlignment implements AlignmentProcess { align.setExtension( Namespace.ALIGNMENT.uri, "method", "http://exmo.inrialpes.fr/align/impl/URIAlignment#clone" ); try { align.ingest( this ); - } catch (AlignmentException ex) { ex.printStackTrace(); } + } catch (AlignmentException ex) { + logger.debug( "IGNORED Exception", ex ); + } return align; } diff --git a/src/fr/inrialpes/exmo/align/service/msg/CannotRenderAlignment.java b/src/fr/inrialpes/exmo/align/service/msg/CannotRenderAlignment.java index 6aead977..51783e03 100644 --- a/src/fr/inrialpes/exmo/align/service/msg/CannotRenderAlignment.java +++ b/src/fr/inrialpes/exmo/align/service/msg/CannotRenderAlignment.java @@ -31,7 +31,7 @@ public class CannotRenderAlignment extends ErrorMsg { super( surr, rep, from, to, cont, param ); } public String HTMLString(){ - return "Cannot render alignment "+content+": turn it to an ObjectAlignment with ObjectAlignement.toOkbjectAlignement( al )"; + return "Cannot render alignment "+content; } public String RESTString(){ return "<CannotRenderAlignment>"+content+"</CannotRenderAlignment>"; diff --git a/src/fr/inrialpes/exmo/align/service/msg/ErrorMsg.java b/src/fr/inrialpes/exmo/align/service/msg/ErrorMsg.java index 219a8262..a7f35bde 100644 --- a/src/fr/inrialpes/exmo/align/service/msg/ErrorMsg.java +++ b/src/fr/inrialpes/exmo/align/service/msg/ErrorMsg.java @@ -32,7 +32,15 @@ public class ErrorMsg extends Message { super( surr, rep, from, to, cont, param ); } public String HTMLString(){ - return "Generic error: "+content; + String message = "Generic error: "+content; + if ( parameters != null ) { + message += "<ul>"; + for ( String key : parameters.stringPropertyNames()) { + message += "<li>"+key+" = "+parameters.getProperty( key )+"</li>"; + } + message += "/<ul>"; + } + return message; } public String RESTString(){ return "<error>" + content + "</error>"; -- GitLab