From 40cd88462b0fd065bead0b4565a4b551c52e42fe Mon Sep 17 00:00:00 2001 From: Denis Kuniss Date: Thu, 18 Jul 2024 15:12:37 +0200 Subject: [PATCH 1/4] Switched Logging to SLF4J solving GH #9. Allowing every application to be free which logging is used for javapos-config-loader library. --- CHANGELOG.md | 1 + build.gradle | 2 + .../config/DefaultCompositeRegPopulator.java | 50 +-- .../config/simple/AbstractRegPopulator.java | 31 +- .../config/simple/SimpleEntryRegistry.java | 38 +- .../config/simple/SimpleRegPopulator.java | 30 +- .../config/simple/xml/JavaxRegPopulator.java | 52 +-- .../java/jpos/loader/JposServiceLoader.java | 31 +- .../simple/SimpleServiceConnection.java | 18 +- .../loader/simple/SimpleServiceManager.java | 21 +- .../jpos/profile/DefaultProfileFactory.java | 31 +- src/main/java/jpos/util/FileUtil.java | 79 ++-- src/main/java/jpos/util/XmlHelper.java | 29 +- src/main/java/jpos/util/tracing/Tracer.java | 351 ------------------ .../java/jpos/util/tracing/TracerFactory.java | 316 ---------------- .../java/jpos/util/tracing/TracerOutput.java | 64 ---- src/main/java/jpos/util/tracing/Tracing.java | 76 ---- .../util/tracing/TracerFactoryTestCase.java | 107 ------ .../jpos/util/tracing/TracerTestCase.java | 197 ---------- 19 files changed, 185 insertions(+), 1339 deletions(-) delete mode 100644 src/main/java/jpos/util/tracing/Tracer.java delete mode 100644 src/main/java/jpos/util/tracing/TracerFactory.java delete mode 100644 src/main/java/jpos/util/tracing/TracerOutput.java delete mode 100644 src/main/java/jpos/util/tracing/Tracing.java delete mode 100644 src/test/java/jpos/util/tracing/TracerFactoryTestCase.java delete mode 100644 src/test/java/jpos/util/tracing/TracerTestCase.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 6eb268d..65c9a58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ## 4.0.0 +- replaced legacy logging implementation by the logging facade SLF4J, see https://www.slf4j.org/ for details on how to integrate - jpos.config.DefaultCompositeRegPopulator.load() is throwing more specific IllegalArgument exception instead of RuntimeException - added Javax XML parser based XML registry populator implementation (contributed by @mjpcger) - removed Xerces based XML registry populator implementations, mainly diff --git a/build.gradle b/build.gradle index 1233c59..7f519e6 100644 --- a/build.gradle +++ b/build.gradle @@ -65,9 +65,11 @@ def testResourceDir = file("${System.properties['java.io.tmpdir']}/javapos-confi dependencies { api 'org.javapos:javapos-contracts:1.6.0' + implementation 'org.slf4j:slf4j-api:2.0.13' testImplementation("junit:junit:4.13.2") + testRuntimeOnly 'org.slf4j:slf4j-simple:2.0.13' testRuntimeOnly files(testResourceDir) } diff --git a/src/main/java/jpos/config/DefaultCompositeRegPopulator.java b/src/main/java/jpos/config/DefaultCompositeRegPopulator.java index 96096b9..fd331d0 100644 --- a/src/main/java/jpos/config/DefaultCompositeRegPopulator.java +++ b/src/main/java/jpos/config/DefaultCompositeRegPopulator.java @@ -24,8 +24,8 @@ import jpos.loader.*; import jpos.util.*; -import jpos.util.tracing.Tracer; -import jpos.util.tracing.TracerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Default implementation of the CompositeRegPopulator interface @@ -34,6 +34,8 @@ */ public class DefaultCompositeRegPopulator implements CompositeRegPopulator { + private static final Logger log = LoggerFactory.getLogger(DefaultCompositeRegPopulator.class); + //------------------------------------------------------------------------- // Ctor(s) // @@ -91,27 +93,23 @@ private JposRegPopulator createPopulator( String popName, String className ) } catch( ClassNotFoundException cnfe ) { - tracer.println( "Could not find populator class with name: " + - className + " exception message = " + - cnfe.getMessage() ); + log.error( "Could not find populator class with name: {} exception message = {}", + className, cnfe.getMessage() ); } catch( NoSuchMethodException nsme ) { - tracer.println( "Populator by class name: " + - className + - " must define a no-arg ctor or a 1-arg ctor with String param as the unique ID" ); + log.error( "Populator by class name: {} must define a no-arg ctor or a 1-arg ctor with String param as the unique ID", + className ); } catch( InstantiationException ie ) { - tracer.println( "Could not instantiate populator class with name: " + - className + " exception message = " + - ie.getMessage() ); + log.error( "Could not instantiate populator class with name: {} exception message = {}", + className, ie.getMessage() ); } catch( Exception e ) { - tracer.println( "Could not instantiate populator class with name: " + - className + " exception message = " + - e.getMessage() ); + log.error( "Could not instantiate populator class with name: {} exception message = {}", + className, e.getMessage() ); } return populator; @@ -187,9 +185,7 @@ public void save( @SuppressWarnings("rawtypes") Enumeration entries ) throws Exc List entryList = popEntriesMap.get( populator.getUniqueId() ); if( entryList == null ) - tracer.println( "Trying to save entry with logicalName = " + - entry.getLogicalName() + - " and populator with" ); + log.debug( "Trying to save entry with logicalName = {} and populator with entry list null", entry.getLogicalName() ); else entryList.add( entry ); } @@ -214,8 +210,7 @@ public void save( @SuppressWarnings("rawtypes") Enumeration entries ) throws Exc catch( Exception e ) { exception = e; - tracer.println( "Error while saving to populator with unique ID:" + - populator.getUniqueId() ); + log.error( "Error while saving to populator with unique ID: {}", populator.getUniqueId() ); } } @@ -254,7 +249,7 @@ public void load() if( populatorClassMultiProp == null || populatorClassMultiProp.getNumberOfProperties() == 0 ) { - tracer.println( "CompositeRegPopulator.load() w/o any defined multi-property" ); + log.error( "CompositeRegPopulator.load() w/o any defined multi-property" ); throw new IllegalArgumentException( "CompositeRegPopulator.load() w/o any defined multi-property" ); } @@ -281,8 +276,7 @@ public void load() } else { - tracer.println( "Created default populator with name = " + defaultPopName + - " OK but populator file is null" ); + log.debug( "Created default populator with name = {} OK but populator file is null", defaultPopName ); defaultPopulator.load(); lastLoadException = defaultPopulator.getLastLoadException(); } @@ -296,8 +290,7 @@ public void load() setDefaultPopulator( defaultPopulator ); } else - tracer.println( "Did not add default populator by : " + - "<" + defaultPopName + ", " + defaultPopClass + ">" ); + log.debug( "Did not add default populator by : <{}, {}>", defaultPopName, defaultPopClass); while( popClasses.hasNext() ) { String popName = popClasses.next(); @@ -316,8 +309,7 @@ public void load() } else { - tracer.println( "Created populator with name = " + popName + - " OK but populator file is null" ); + log.debug( "Created populator with name = {} OK but populator file is null", popName ); populator.load(); lastLoadException = populator.getLastLoadException(); } @@ -325,8 +317,7 @@ public void load() add( populator ); } else - tracer.println( "Did not add populator by : " + - "<" + popName + ", " + popClass + ">" ); + log.debug( "Did not add populator by : <{}, {}>", popName, popClass ); } } @@ -432,7 +423,4 @@ public JposRegPopulator getPopulator( String uniqueId ) private HashMap popFileMap = new HashMap<>(); private JposRegPopulator defaultPop = null; private Exception lastLoadException = null; - - private Tracer tracer = TracerFactory.getInstance(). - createTracer( "DefaultCompositeRegPopulator" ); } \ No newline at end of file diff --git a/src/main/java/jpos/config/simple/AbstractRegPopulator.java b/src/main/java/jpos/config/simple/AbstractRegPopulator.java index b568977..7c552ed 100644 --- a/src/main/java/jpos/config/simple/AbstractRegPopulator.java +++ b/src/main/java/jpos/config/simple/AbstractRegPopulator.java @@ -27,8 +27,8 @@ import jpos.loader.JposServiceLoader; import jpos.util.JposProperties; import jpos.util.JposPropertiesConst; -import jpos.util.tracing.Tracer; -import jpos.util.tracing.TracerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Common abstract superclass to help in the implementation of the @@ -39,6 +39,8 @@ */ public abstract class AbstractRegPopulator implements JposRegPopulator { + private static final Logger log = LoggerFactory.getLogger(AbstractRegPopulator.class); + //------------------------------------------------------------------------- // Ctor(s) // @@ -115,8 +117,7 @@ protected URL createURLFromFile( File file ) { url = new URL( "file", "", file.getAbsolutePath() ); } catch( Exception e ) { - tracer.println( "Error creating URL: Exception.message=" + - e.getMessage() ); + log.error( "Error creating URL: Exception.message={}", e.getMessage() ); } return url; @@ -138,8 +139,7 @@ protected URL createURLFromFile( ZipFile zipFile ) } catch( Exception e ) { - tracer.println( "Error creating URL: Exception.message=" + - e.getMessage() ); + log.error( "Error creating URL: Exception.message={}", e.getMessage() ); } return url; @@ -213,8 +213,7 @@ protected InputStream getPopulatorFileIS() throws Exception jposProperties.getPropertyString( JposPropertiesConst.JPOS_POPULATOR_FILE_PROP_NAME ); - tracer.println( "getPopulatorFileIS(): populatorFileName=" + - populatorFileName ); + log.debug( "getPopulatorFileIS(): populatorFileName={}", populatorFileName ); populatorIS = new FileInputStream( populatorFileName ); } @@ -229,15 +228,14 @@ protected InputStream getPopulatorFileIS() throws Exception populatorIS = url.openStream(); - tracer.println( "getPopulatorFileIS(): populatorFileURL=" + - populatorFileURL ); + log.debug( "getPopulatorFileIS(): populatorFileURL={}", populatorFileURL ); } else { String msg = "jpos.config.populatorFile OR " + " jpos.config.populatorFileURL properties not defined"; - tracer.println( msg ); + log.error( msg ); throw new Exception( msg ); } @@ -284,7 +282,7 @@ protected OutputStream getPopulatorFileOS() throws Exception String msg = "jpos.config.populatorFile OR " + "jpos.config.populatorFileURL properties not defined"; - tracer.println( msg ); + log.error( msg ); throw new Exception( msg ); } @@ -338,8 +336,7 @@ protected InputStream findFileInClasspath( String fileName ) { is = null; - tracer.println( "findFileInClasspath: IOException.msg=" + - ioe.getMessage() ); + log.error( "findFileInClasspath: IOException.msg={}", ioe.getMessage() ); } return is; @@ -438,8 +435,7 @@ private InputStream findFileInJarZipFiles( String fileName, List jarZipF } catch( Exception e ) { - tracer.println( "findInJarZipFiles: Exception.message=" + - e.getMessage() ); + log.error( "findInJarZipFiles: Exception.message={}", e.getMessage() ); } } @@ -458,7 +454,4 @@ private InputStream findFileInJarZipFiles( String fileName, List jarZipF private String uniqueId = ""; protected Exception lastLoadException = null; - - private Tracer tracer = TracerFactory.getInstance(). - createTracer( "AbstractRegPopulator" ); } diff --git a/src/main/java/jpos/config/simple/SimpleEntryRegistry.java b/src/main/java/jpos/config/simple/SimpleEntryRegistry.java index 5031245..90cc76c 100644 --- a/src/main/java/jpos/config/simple/SimpleEntryRegistry.java +++ b/src/main/java/jpos/config/simple/SimpleEntryRegistry.java @@ -23,8 +23,8 @@ import jpos.config.*; -import jpos.util.tracing.Tracer; -import jpos.util.tracing.TracerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * This is a simple implementation for the JposEntryRegistry using a Hashtable @@ -35,6 +35,8 @@ */ public class SimpleEntryRegistry implements JposEntryRegistry { + private static final Logger log = LoggerFactory.getLogger(SimpleEntryRegistry.class); + /** * One-argument constructor * @param populator the JposRegPopulator used by the registry @@ -89,7 +91,7 @@ public void modifyJposEntry( String logicalName, JposEntry newEntry ) { jposEntries.put( logicalName, newEntry ); - tracer.println( "Modified entry.logicalName = " + logicalName ); + log.debug( "Modified entry.logicalName = {}", logicalName ); fireJposEntryRegistryEventModified( new JposEntryRegistryEvent( this, newEntry ) ); @@ -104,7 +106,7 @@ public void addJposEntry( String logicalName, JposEntry entry ) { jposEntries.put( logicalName, entry ); - tracer.println( "Added entry.logicalName = " + logicalName ); + log.debug( "Added entry.logicalName = {}", logicalName ); fireJposEntryRegistryEventAdded( new JposEntryRegistryEvent( this, entry ) ); @@ -141,8 +143,7 @@ public void removeJposEntry( JposEntry entry ) jposEntries.remove( entry.getPropertyValue( JposEntry. LOGICAL_NAME_PROP_NAME ) ); - tracer.println( "Removed entry.logicalName = " + - entry.getLogicalName() ); + log.debug( "Removed entry.logicalName = {}", entry.getLogicalName() ); fireJposEntryRegistryEventRemoved( new JposEntryRegistryEvent( this, removedEntry ) ); @@ -151,8 +152,7 @@ public void removeJposEntry( JposEntry entry ) } } - tracer.println( "Could not find entry to remove entry.logicalName = " + - entry.getLogicalName() ); + log.debug( "Could not find entry to remove entry.logicalName = {}", entry.getLogicalName() ); } /** @@ -236,7 +236,9 @@ public void load() jposEntries.put( jposEntry.getLogicalName(), jposEntry ); } - catch( Exception e ) { tracer.print( e ); } + catch( Exception e ) { + log.error( e.getMessage() ); + } } loaded = true; @@ -305,9 +307,8 @@ public String toString() */ protected void fireJposEntryRegistryEventAdded( JposEntryRegistryEvent e ) { - tracer.println( "fireJposEntryRegistryEventAdded: " + - "e.getJposEntry().logicalName = " + - e.getJposEntry().getLogicalName() ); + log.debug( "fireJposEntryRegistryEventAdded: e.getJposEntry().logicalName = {}", + e.getJposEntry().getLogicalName() ); @SuppressWarnings("unchecked") Vector listenersClone = (Vector) listeners.clone(); @@ -327,9 +328,8 @@ protected void fireJposEntryRegistryEventAdded( JposEntryRegistryEvent e ) */ protected void fireJposEntryRegistryEventRemoved( JposEntryRegistryEvent e ) { - tracer.println( "fireJposEntryRegistryEventRemoved: " + - "e.getJposEntry().logicalName = " + - e.getJposEntry().getLogicalName() ); + log.debug( "fireJposEntryRegistryEventRemoved: e.getJposEntry().logicalName = {}", + e.getJposEntry().getLogicalName() ); @SuppressWarnings("unchecked") Vector listenersClone = (Vector) listeners.clone(); @@ -348,9 +348,8 @@ protected void fireJposEntryRegistryEventRemoved( JposEntryRegistryEvent e ) */ protected void fireJposEntryRegistryEventModified( JposEntryRegistryEvent e ) { - tracer.println( "fireJposEntryRegistryEventModified: " + - "e.getJposEntry().logicalName = " + - e.getJposEntry().getLogicalName() ); + log.debug( "fireJposEntryRegistryEventModified: e.getJposEntry().logicalName = {}", + e.getJposEntry().getLogicalName() ); @SuppressWarnings("unchecked") Vector listenersClone = (Vector) listeners.clone(); @@ -370,7 +369,4 @@ protected void fireJposEntryRegistryEventModified( JposEntryRegistryEvent e ) private final Vector listeners = new Vector<>(); private JposRegPopulator regPopulator = null; private boolean loaded = false; - - private Tracer tracer = TracerFactory.getInstance(). - createTracer( "SimpleEntryRegistry" ); } diff --git a/src/main/java/jpos/config/simple/SimpleRegPopulator.java b/src/main/java/jpos/config/simple/SimpleRegPopulator.java index 093ad11..85d5502 100644 --- a/src/main/java/jpos/config/simple/SimpleRegPopulator.java +++ b/src/main/java/jpos/config/simple/SimpleRegPopulator.java @@ -23,8 +23,8 @@ import java.util.zip.*; import java.net.URL; -import jpos.util.tracing.Tracer; -import jpos.util.tracing.TracerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import jpos.config.*; /** @@ -41,6 +41,8 @@ */ public class SimpleRegPopulator extends AbstractRegPopulator { + private static final Logger log = LoggerFactory.getLogger(SimpleRegPopulator.class); + //------------------------------------------------------------------------- // Ctor(s) // @@ -124,8 +126,8 @@ public void load() catch( Exception e ) { lastLoadException = e; - tracer.println( "Error loading serialized JposEntry file: " + - "Exception.message= " + e.getMessage() ); + log.error( "Error loading serialized JposEntry file: Exception.message= {}", + e.getMessage() ); } } } @@ -157,8 +159,8 @@ public void load( String fileName ) catch( Exception e ) { lastLoadException = e; - tracer.println( "Error loading serialized JposEntry file: " + - "Exception.message=" + e.getMessage() ); + log.error( "Error loading serialized JposEntry file: Exception.message={}", + e.getMessage() ); } } @@ -420,8 +422,7 @@ protected Enumeration readJposEntries( InputStream is ) in = new ObjectInputStream( is ); if( in == null ) - tracer.println( "Can't find serialized JposEntry file: " + - serFileName ); + log.error( "Can't find serialized JposEntry file: {}", serFileName ); else while( true ) entries.add( (JposEntry) in.readObject() ); @@ -429,16 +430,14 @@ protected Enumeration readJposEntries( InputStream is ) serFileName = absoluteFileName; } catch( EOFException eofe ) { - tracer.println( "ERROR while reading serialized JposEntry file: " + - serFileName + " Exception.message=" + - eofe.getMessage() ); + log.error( "ERROR while reading serialized JposEntry file:{} Exception.message={}", + serFileName, eofe.getMessage() ); } catch( Exception e ) { - tracer.println( "ERROR while reading serialized JposEntry file: " + - serFileName + " Exception.message=" + - e.getMessage() ); + log.error( "ERROR while reading serialized JposEntry file:{} Exception.message={}", + serFileName, e.getMessage() ); } return Collections.enumeration(entries); } @@ -506,9 +505,6 @@ protected void saveJposEntries( Enumeration entries ) throws Exceptio private String absoluteFileName = ""; private String serFileName = DEFAULT_JPOS_SER_FILE_NAME; - private final Tracer tracer = TracerFactory.getInstance(). - createTracer( "SimpleRegPopulator" ); - //-------------------------------------------------------------------------- // Class constants // diff --git a/src/main/java/jpos/config/simple/xml/JavaxRegPopulator.java b/src/main/java/jpos/config/simple/xml/JavaxRegPopulator.java index 059e96c..80003c4 100644 --- a/src/main/java/jpos/config/simple/xml/JavaxRegPopulator.java +++ b/src/main/java/jpos/config/simple/xml/JavaxRegPopulator.java @@ -24,8 +24,8 @@ import jpos.config.simple.SimpleEntry; import jpos.loader.Version; import jpos.util.JposEntryUtility; -import jpos.util.tracing.Tracer; -import jpos.util.tracing.TracerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.w3c.dom.*; import org.xml.sax.*; import org.xml.sax.ext.DefaultHandler2; @@ -62,6 +62,8 @@ public class JavaxRegPopulator extends AbstractRegPopulator implements XmlRegPopulator { + private static final Logger log = LoggerFactory.getLogger(JavaxRegPopulator.class); + /** * Default ctor */ @@ -96,14 +98,14 @@ public URL getEntriesURL() { try { url = new URL(getPopulatorFileURL()); } catch (Exception e) { - tracer.println("getEntriesURL: Exception.message=" + e.getMessage()); + log.error("getEntriesURL: Exception.message={}", e.getMessage()); } } else url = createURLFromFile(new File(getPopulatorFileName())); - tracer.println("getPopulatorFileURL()=" + getPopulatorFileURL()); - tracer.println("getPopulatorFileName()=" + getPopulatorFileName()); + log.debug("getPopulatorFileURL()={}", getPopulatorFileURL()); + log.debug("getPopulatorFileName()={}", getPopulatorFileName()); return url; } @@ -125,7 +127,9 @@ public void save(@SuppressWarnings("rawtypes") Enumeration entries) throws Excep @Override public void save(@SuppressWarnings("rawtypes") Enumeration entries, String fileName) throws Exception { - tracer.println("saving JavaPOS configuration to file " + new File(fileName).getAbsolutePath()); + log.atInfo() + .setMessage("saving JavaPOS configuration to file {}") + .addArgument(() -> new File(fileName).getAbsolutePath()); try (FileOutputStream os = new FileOutputStream(fileName)) { save(entries, os); } @@ -136,22 +140,20 @@ public void load() { try (InputStream is = isPopulatorFileDefined() ? getPopulatorFileIS() : new FileInputStream(DEFAULT_XML_FILE_NAME) ) { load(is); } catch (Exception e) { - tracer.println("Error while loading populator file Exception.message: " + e.getMessage()); + log.error("Error while loading populator file Exception.message: {}", e.getMessage()); lastLoadException = e; } } @Override public void load(String fileName) { - File file = new File(fileName); - if (file.exists()) - tracer.println("trying to load JavaPOS configuration from file " + file.getAbsolutePath()); - else - tracer.println("because JavaPOS configuration file '" + fileName + "' does not exist, trying to load it as classpath resource"); - try (InputStream is = file.exists() ? new FileInputStream(fileName) : findFileInClasspath(fileName)) { + log.atInfo() + .setMessage("loading JavaPOS configuration from file {}") + .addArgument(() -> new File(fileName).getAbsolutePath()); + try (InputStream is = new File(fileName).exists() ? new FileInputStream(fileName) : findFileInClasspath(fileName)) { load(is); } catch (Exception e) { - tracer.println("Error while loading populator file Exception.message: " + e.getMessage()); + log.error("Error while loading populator file Exception.message: {}", e.getMessage()); lastLoadException = e; } } @@ -305,7 +307,7 @@ private void addPropAsAttribute(Prop prop, Element creation, Element jpos, Eleme product.setAttribute(XML_ATTR_URL, attrValue); break; default: - tracer.print("WARN: unexpected XML attribute (will be skipped): " + attrName); + log.warn("unexpected XML attribute (will be skipped): {}", attrName); break; } @@ -335,7 +337,7 @@ private void load(InputStream inputStream) { StreamSource ss = new StreamSource(is == null ? new FileInputStream(XSD_FILE_NAME) : is); Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(ss); parserFactory.setSchema(schema); - tracer.println("XML file will be XSD schema validated against " + XSD_FILE_NAME); + log.info("XML file will be XSD schema validated against {}", XSD_FILE_NAME); } catch (Exception e) { parserFactory.setValidating(true); } @@ -348,13 +350,13 @@ private void load(InputStream inputStream) { parser.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, XML_RESTRICTED_ACCESS_ATTRIBUTE); parser.parse(inputStream, saxHandler); } catch (SAXException e) { - tracer.println("SAX Parser error, msg=" + e.getMessage()); + log.error("SAX Parser error, msg={}", e.getMessage()); lastLoadException = e; } catch (IOException e) { - tracer.println("XML file access error, msg=" + e.getMessage()); + log.error("XML file access error, msg={}", e.getMessage()); lastLoadException = e; } catch (ParserConfigurationException e) { - tracer.println("SAX Parser configuration error, msg=" + e.getMessage()); + log.error("SAX Parser configuration error, msg={}", e.getMessage()); lastLoadException = e; } for (JposEntry jposEntry : jposEntryList) { @@ -377,7 +379,7 @@ private class JavaxSaxHandler @Override public void startElement(String uri, String lname, String qname, Attributes attrs) { if (theException != null) { - tracer.println(": Parse error: " + theException.getMessage()); + log.error(": Parse error: {}", theException.getMessage()); lastLoadException = theException; theException = null; return; @@ -416,7 +418,7 @@ private void addPropElement(Attributes attrs) { currentEntry = null; String msg = "Invalid prop: name=" + attrs.getValue(XML_ATTR_NAME) + ":value=" + attrs.getValue(XML_ATTR_VALUE); - tracer.println(": " + msg); + log.debug(": {}", msg); lastLoadException = new SAXException(msg, e); } } @@ -428,7 +430,7 @@ private void addOptionalProperty(String name, String value) { @Override public void endElement(String uri, String lname, String qname) { if (theException != null) { - tracer.println("Parsing XML element " + qname + " failed with: " + theException.getMessage()); + log.error("Parsing XML element {} failed with: {}", qname, theException.getMessage()); theException = null; } if (qname.equals(XML_TAG_JPOSENTRY)) { @@ -461,7 +463,8 @@ public void fatalError(SAXParseException e) { public InputSource resolveEntity(String name, String publicId, String uri, String systemId) { if (publicId.equals(DTD_DOC_TYPE_VALUE)) { - tracer.println("XML file will be DTD validated against public Id '" + publicId + "' and system Id " + systemId); + log.info("XML file will be DTD validated against public Id '{}' and system Id {}", + publicId, systemId); InputStream is = getClass().getResourceAsStream(DTD_FILE_NAME); @@ -482,9 +485,6 @@ public InputSource resolveEntity(String name, String publicId, String uri, Strin private List jposEntryList = new ArrayList<>(); - private Tracer tracer = - TracerFactory.getInstance().createTracer(this.getClass().getSimpleName()); - //-------------------------------------------------------------------------- // Constants // diff --git a/src/main/java/jpos/loader/JposServiceLoader.java b/src/main/java/jpos/loader/JposServiceLoader.java index e7576f3..d815a73 100644 --- a/src/main/java/jpos/loader/JposServiceLoader.java +++ b/src/main/java/jpos/loader/JposServiceLoader.java @@ -22,8 +22,8 @@ import jpos.JposException; import jpos.util.*; -import jpos.util.tracing.Tracer; -import jpos.util.tracing.TracerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.lang.reflect.*; @@ -38,13 +38,12 @@ */ public final class JposServiceLoader { + private static final Logger log = LoggerFactory.getLogger(JposServiceLoader.class); + //-------------------------------------------------------------------------- // Class variables // - private static Tracer tracer = TracerFactory.getInstance(). - createTracer( "JposServiceLoader" ); - private static JposServiceManager manager = null; /** @@ -88,8 +87,7 @@ public final class JposServiceLoader if( customManagerDefined ) { - tracer.println( "Custom manager is defined: className= " + - customManagerClassName ); + log.debug( "Custom manager is defined: className= {}", customManagerClassName ); try { @@ -107,12 +105,10 @@ public final class JposServiceLoader } catch( Exception e ) { - tracer.println( "Error creating instance of specified " + - "jpos.config.serviceManagerClass class: " + - customManagerClassName ); + log.error( "Error creating instance of specified jpos.config.serviceManagerClass class: {}", + customManagerClassName ); - tracer.println( "Using default manager class: " + - "jpos.loader.simple.SimpleServiceManager" ); + log.info( "Using default manager class: jpos.loader.simple.SimpleServiceManager" ); manager = new jpos.loader.simple. SimpleServiceManager( jposProperties ); @@ -124,7 +120,7 @@ public final class JposServiceLoader manager.getEntryRegistry().load(); - tracer.println( "manager.getEntryRegistry().load() OK" ); + log.debug( "manager.getEntryRegistry().load() OK" ); } /** @@ -138,16 +134,15 @@ public static JposServiceConnection findService( String logicalName ) { if( manager == null ) { - String msg = "Did not find a valid " + - JposPropertiesConst.JPOS_SERVICE_MANAGER_CLASS_PROP_NAME + - " to create"; + String msg = String.format("Did not find a valid %s to create", + JposPropertiesConst.JPOS_SERVICE_MANAGER_CLASS_PROP_NAME); - tracer.println( msg ); + log.error( msg ); throw new JposException( JposConst.JPOS_E_NOSERVICE, msg ); } - tracer.println( "findService: " + logicalName ); + log.info( "findService: {}", logicalName ); return manager.createConnection( logicalName ); } diff --git a/src/main/java/jpos/loader/simple/SimpleServiceConnection.java b/src/main/java/jpos/loader/simple/SimpleServiceConnection.java index 9aa96c0..2f507b6 100644 --- a/src/main/java/jpos/loader/simple/SimpleServiceConnection.java +++ b/src/main/java/jpos/loader/simple/SimpleServiceConnection.java @@ -25,8 +25,8 @@ import jpos.JposException; import jpos.loader.*; import jpos.config.*; -import jpos.util.tracing.Tracer; -import jpos.util.tracing.TracerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * This is a simple implementation of the JposServiceConnection interface @@ -35,6 +35,8 @@ */ public class SimpleServiceConnection implements JposServiceConnection { + private static final Logger log = LoggerFactory.getLogger(SimpleServiceConnection.class); + /** * Creates a new SimpleServiceConnection by passing the logicalName, * the associated JposEntry and JposServiceInstanceFactory @@ -99,10 +101,11 @@ public void connect() throws JposException } catch( Exception e ) { - String msg = "Could not connect to service with logicalName = " + - logicalName + ": Exception.message=" + e.getMessage(); + String msg = String.format( + "Could not connect to service with logicalName = %s: Exception.message= %s", + logicalName, e.getMessage()); - tracer.println( msg ); + log.error( msg ); throw new JposException( JposConst.JPOS_E_NOSERVICE, msg, e ); } @@ -121,7 +124,7 @@ public void disconnect() throws JposException service = null; } - tracer.println( "Disconnected to service OK" ); + log.info( "Disconnected to service OK" ); } /** @@ -146,7 +149,4 @@ public void disconnect() throws JposException private JposEntry entry = null; private String logicalName = null; private String siFactoryClassName = null; - - private Tracer tracer = TracerFactory.getInstance(). - createTracer( "SimpleServiceConnection" ); } \ No newline at end of file diff --git a/src/main/java/jpos/loader/simple/SimpleServiceManager.java b/src/main/java/jpos/loader/simple/SimpleServiceManager.java index 7e22e78..d77d933 100644 --- a/src/main/java/jpos/loader/simple/SimpleServiceManager.java +++ b/src/main/java/jpos/loader/simple/SimpleServiceManager.java @@ -26,8 +26,8 @@ import jpos.config.simple.*; import jpos.profile.*; import jpos.util.*; -import jpos.util.tracing.Tracer; -import jpos.util.tracing.TracerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * This is a simple implementation of the JposServiceManager interface @@ -36,6 +36,8 @@ */ public class SimpleServiceManager implements JposServiceManager { + private static final Logger log = LoggerFactory.getLogger(SimpleServiceManager.class); + //-------------------------------------------------------------------------- // Ctor(s) // @@ -97,9 +99,8 @@ private void initRegPopulator() } catch( Exception e ) { - tracer.println( "Could not create populator by name: " + - regPopulatorClassName + " Exception.message= " + - e.getMessage() ); + log.error( "Could not create populator by name: {} Exception.message= {}", + regPopulatorClassName, e.getMessage() ); regPopulator = new SimpleRegPopulator(); } } @@ -174,14 +175,12 @@ public JposServiceConnection createConnection( String logicalName ) } catch( JposException je ) { - tracer.println( "createConnection: JposException.msg=" + - je.getMessage() ); + log.error( "createConnection: JposException.msg={}", je.getMessage() ); throw je; } catch( Exception e ) { - tracer.println( "createConnection: Exception.msg=" + - e.getMessage() ); + log.error( "createConnection: Exception.msg={}", e.getMessage() ); throw new JposException( JposConst.JPOS_E_NOSERVICE, "Could not find service" ); } @@ -237,7 +236,7 @@ public void reloadEntryRegistry() getEntryRegistry().load(); - tracer.println( "Sucessfully reloaded registry" ); + log.info( "Sucessfully reloaded registry" ); } //-------------------------------------------------------------------------- @@ -252,6 +251,4 @@ public void reloadEntryRegistry() private JposProperties jposProperties = new DefaultProperties(); - private Tracer tracer = TracerFactory.getInstance(). - createTracer( "SimpleServiceManager" ); } \ No newline at end of file diff --git a/src/main/java/jpos/profile/DefaultProfileFactory.java b/src/main/java/jpos/profile/DefaultProfileFactory.java index fc71820..d151a0b 100644 --- a/src/main/java/jpos/profile/DefaultProfileFactory.java +++ b/src/main/java/jpos/profile/DefaultProfileFactory.java @@ -29,8 +29,8 @@ import org.xml.sax.*; import jpos.util.XmlHelper; -import jpos.util.tracing.Tracer; -import jpos.util.tracing.TracerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Default implementation of the ProfileFactory interface using an @@ -39,6 +39,8 @@ */ public class DefaultProfileFactory implements ProfileFactory { + private static final Logger log = LoggerFactory.getLogger(DefaultProfileFactory.class); + //------------------------------------------------------------------------- // Private methods // @@ -123,19 +125,19 @@ Document parse( String xmlFileName ) throws ProfileException catch( IOException ioe ) { String msg = "Error loading XML profile file"; - tracer.println( msg + ": Exception.message = " + ioe.getMessage() ); + log.error( "{}: Exception.message = {}", msg, ioe.getMessage() ); throw new ProfileException( msg, ioe ); } catch( SAXException se ) { String msg = "Error parsing XML profile file"; - tracer.println( msg + ": Exception.message = " + se.getMessage() ); + log.error( "{}: Exception.message = {}", msg, se.getMessage() ); throw new ProfileException( msg, se ); } catch( ParserConfigurationException pce ) { String msg = "Error creating XML parser"; - tracer.println( msg + ": Exception.message = " + pce.getMessage() ); + log.error( "{}: Exception.message = {}", msg, pce.getMessage() ); throw new ProfileException( msg, pce ); } finally @@ -165,20 +167,20 @@ Document parseSchema( String xmlFileName ) throws ProfileException catch( IOException ioe ) { String msg = "Error loading XML profile file"; - tracer.println( msg + ": Excpetion.message = " + ioe.getMessage() ); + log.error( "{}: Excpetion.message = {}", msg, ioe.getMessage() ); throw new ProfileException( msg, ioe ); } catch( SAXException se ) { String msg = "Error parsing XML profile file"; - tracer.println( msg + ": Exception.message = " + se.getMessage() ); + log.error( "{}: Exception.message = {}", msg, se.getMessage() ); throw new ProfileException( msg, se ); } catch( ParserConfigurationException pce ) { String msg = "Error creating XML parser"; - tracer.println( msg + ": Exception.message = " + pce.getMessage() ); + log.error( "{}: Exception.message = {}", msg, pce.getMessage() ); throw new ProfileException( msg, pce ); } } @@ -210,13 +212,6 @@ public Profile createProfile( String xmlProfileFileName ) throws ProfileExceptio return load( xmlProfileFileName ); } - //------------------------------------------------------------------------- - // Instance variables - // - - private Tracer tracer = TracerFactory.getInstance(). - createTracer( this.getClass().getSimpleName() ); - //------------------------------------------------------------------------- // Inner classes // @@ -244,19 +239,19 @@ class DefaultErrorHandler implements org.xml.sax.ErrorHandler public void warning( SAXParseException e ) throws SAXException { - tracer.println( "Line " + e.getLineNumber() + ": WARNING SAXParseException.message = " + e.getMessage() ); + log.warn( "Line {}: WARNING SAXParseException.message = {}", e.getLineNumber(), e.getMessage() ); warningList.add( e ); } public void error( SAXParseException e ) throws SAXException { - tracer.println( "Line " + e.getLineNumber() + ": ERROR SAXParseException.message = " + e.getMessage() ); + log.error( "Line {}: ERROR SAXParseException.message = {}", e.getLineNumber(), e.getMessage() ); errorList.add( e ); } public void fatalError( SAXParseException e ) throws SAXException { - tracer.println( "Line " + e.getLineNumber() + ": FATALERROR SAXParseException.message = " + e.getMessage() ); + log.error( "Line {}: FATALERROR SAXParseException.message = {}", e.getLineNumber(), e.getMessage() ); fatalErrorList.add( e ); } diff --git a/src/main/java/jpos/util/FileUtil.java b/src/main/java/jpos/util/FileUtil.java index b2e0a25..9520c39 100644 --- a/src/main/java/jpos/util/FileUtil.java +++ b/src/main/java/jpos/util/FileUtil.java @@ -32,8 +32,8 @@ import java.util.jar.JarEntry; import java.util.jar.JarFile; -import jpos.util.tracing.Tracer; -import jpos.util.tracing.TracerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Utility class for various File related actions and methods @@ -43,6 +43,9 @@ */ public class FileUtil { + private static final String JAVA_CLASS_PATH_PROP_NAME = "java.class.path"; + private static final Logger log = LoggerFactory.getLogger(FileUtil.class); + //------------------------------------------------------------------------- // Ctor(s) // @@ -56,7 +59,7 @@ protected FileUtil() {} protected static synchronized List getCpDirList() { - String classpath = System.getProperty( "java.class.path" ); + String classpath = System.getProperty( JAVA_CLASS_PATH_PROP_NAME ); List cpDirList = new ArrayList<>(); @@ -79,7 +82,7 @@ protected static synchronized List getCpDirList() protected static synchronized List getJarList() { - String classpath = System.getProperty( "java.class.path" ); + String classpath = System.getProperty( JAVA_CLASS_PATH_PROP_NAME ); List cpJarFilesList = new ArrayList<>(); @@ -98,28 +101,31 @@ protected static synchronized List getJarList() protected static synchronized JarEntry getJarEntry( JarFile jarFile, String fileName ) { - tracer.println( "" ); - - if( jarFile == null ) return null; + log.debug( "", jarFile, fileName ); - Enumeration entries = jarFile.entries(); - while( entries.hasMoreElements() ) - { - JarEntry jarEntry = entries.nextElement(); - - if( jarEntry.getName().equals( fileName ) ) + try { + + if( jarFile == null ) return null; + + Enumeration entries = jarFile.entries(); + while( entries.hasMoreElements() ) { - tracer.println( "jarEntry.getName()=" + jarEntry.getName() ); - return jarEntry; + JarEntry jarEntry = entries.nextElement(); + + if( jarEntry.getName().equals( fileName ) ) + { + log.debug( "jarEntry.getName()={}", jarEntry.getName() ); + return jarEntry; + } } + + log.warn( "Could not find JarEntry with fileName={}", fileName ); + return null; + } + finally { + log.debug( ""); } - - tracer.println( "Could not find JarEntry with fileName=" + - fileName +"" ); - tracer.println( "" ); - return null; } /** @@ -131,11 +137,11 @@ protected static synchronized JarFile lookForFileInJars( String fileName ) { try { - tracer.println( "" ); + log.debug( "", fileName ); - String classpath = System.getProperty( "java.class.path" ); + String classpath = System.getProperty( JAVA_CLASS_PATH_PROP_NAME ); - tracer.println( "classpath="+classpath ); + log.debug( "classpath={}", classpath ); List cpJarFilesList = getJarList(); @@ -143,7 +149,7 @@ protected static synchronized JarFile lookForFileInJars( String fileName ) { String jarFileName = cpJarFilesList.get( i ); - tracer.println( "jarFileName=" + jarFileName ); + log.debug( "jarFileName={}", jarFileName ); JarFile jarFile = new JarFile( new File( jarFileName ) ); @@ -157,7 +163,7 @@ protected static synchronized JarFile lookForFileInJars( String fileName ) catch( Exception ioe ) { return null; } finally { - tracer.println( "" ); + log.debug( "" ); } } @@ -174,7 +180,7 @@ protected static synchronized JarFile lookForFileInJars( String fileName ) * @param searchInJarFile if true the file will be searched in all the JAR * files that are located in CLASSPATH */ - public synchronized static boolean + public static synchronized boolean locateFile( String fileName, boolean searchInClassPath, boolean searchInJarFile ) { @@ -198,7 +204,7 @@ protected static synchronized JarFile lookForFileInJars( String fileName ) * @param searchInClassPath if true the file will be searched in all * directories specified by CLASSPATH */ - public synchronized static File findFile( String fileName, + public static synchronized File findFile( String fileName, boolean searchInClassPath ) { try @@ -237,21 +243,20 @@ public synchronized static File findFile( String fileName, loadFile( String fileName, boolean searchInClassPath, boolean searchInJarFile ) throws IOException { - tracer.println( "" ); + log.debug( "", + fileName, searchInClassPath, searchInJarFile); File locatedFile = findFile( fileName, searchInClassPath ); if( locatedFile != null ) return new FileInputStream( locatedFile ); - if( searchInJarFile == false ) - throw new FileNotFoundException( "Could not find file: " + fileName ); + if( !searchInJarFile ) + throw new FileNotFoundException( "Could not find file classpath resources: " + fileName ); JarFile locatedJarFile = lookForFileInJars( fileName ); if( locatedJarFile == null ) - throw new FileNotFoundException( "Could not find file: " + fileName ); + throw new FileNotFoundException( "Could not find file in JAR files: " + fileName ); JarEntry locatedJarEntry = getJarEntry( locatedJarFile, fileName ); @@ -261,10 +266,4 @@ public synchronized static File findFile( String fileName, throw new FileNotFoundException( "Could not find file: " + fileName ); } - //------------------------------------------------------------------------- - // Class variables - // - - private static Tracer tracer = TracerFactory.getInstance(). - createTracer( "FileUtil" ); } \ No newline at end of file diff --git a/src/main/java/jpos/util/XmlHelper.java b/src/main/java/jpos/util/XmlHelper.java index 350fec3..0e10e65 100644 --- a/src/main/java/jpos/util/XmlHelper.java +++ b/src/main/java/jpos/util/XmlHelper.java @@ -22,8 +22,8 @@ import java.nio.file.Files; import java.util.*; -import jpos.util.tracing.Tracer; -import jpos.util.tracing.TracerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Simple helper class for XML related activities @@ -32,6 +32,8 @@ */ public class XmlHelper { + private static final Logger log = LoggerFactory.getLogger(XmlHelper.class); + //------------------------------------------------------------------------- // Public methods // @@ -85,30 +87,26 @@ public void checkAndCreateTempDtd() createdTempDir = true; - tracer.println( "DTD file PATH does not exist. Created path " + - dtdFilePath ); + log.debug( "DTD file PATH does not exist. Created path {}", dtdFilePath ); } is = getClass().getClassLoader().getResourceAsStream( dtdJarFullFileName ); - tracer.println( "Got DTD InputStream from current ClassLoader" ); + log.debug( "Got DTD InputStream from current ClassLoader" ); if( is != null ) readAndCreateTempDtdFile( is ); } catch( IOException ioe ) { - tracer.println( "Error creating DTD file: Exception.message = " + - ioe.getMessage() ); + log.error( "Error creating DTD file: Exception.message = {}", ioe.getMessage() ); } finally { try{ if( is != null ) is.close(); } catch( IOException ioe ) { - tracer.println( "Error while closing streams:" + - " Exception.message = " + - ioe.getMessage() ); + log.error( "Error while closing streams: Exception.message = {}", ioe.getMessage() ); } } } @@ -126,13 +124,13 @@ public void removeTempDtd() if( createdTempDir ) removeDirs( dtdFilePath ); - tracer.println( "Removed temp directory with DTD OK" ); + log.debug( "Removed temp directory with DTD OK" ); } } catch( Exception e ) { - tracer.println( "Error removing temporary DTD file: " + - "Exception.msg = " + e.getMessage() ); + log.error( "Error removing temporary DTD file: " + + "Exception.msg = {}", e.getMessage() ); } } @@ -165,7 +163,7 @@ private void readAndCreateTempDtdFile( InputStream is ) throws IOException createdTempDTD = true; - tracer.println( "Read and created temp " + dtdFilePath + dtdFileName ); + log.debug( "Read and created temp {}{}", dtdFilePath, dtdFileName ); } } @@ -236,9 +234,6 @@ void removeDirs( String dirName ) throws IOException private boolean createdTempDTD = false; private boolean createdTempDir = false; - private Tracer tracer = TracerFactory.getInstance(). - createTracer( "XmlHelper" ); - //------------------------------------------------------------------------- // Class constants // diff --git a/src/main/java/jpos/util/tracing/Tracer.java b/src/main/java/jpos/util/tracing/Tracer.java deleted file mode 100644 index 2f8b890..0000000 --- a/src/main/java/jpos/util/tracing/Tracer.java +++ /dev/null @@ -1,351 +0,0 @@ -package jpos.util.tracing; - -/////////////////////////////////////////////////////////////////////////////// -// -// This software is provided "AS IS". The JavaPOS working group (including -// each of the Corporate members, contributors and individuals) MAKES NO -// REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, -// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED -// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NON-INFRINGEMENT. The JavaPOS working group shall not be liable for -// any damages suffered as a result of using, modifying or distributing this -// software or its derivatives. Permission to use, copy, modify, and distribute -// the software and its documentation for any purpose is hereby granted. -// -// The JavaPOS Config/Loader (aka JCL) is now under the CPL license, which -// is an OSS Apache-like license. The complete license is located at: -// http://www.ibm.com/developerworks/library/os-cpl.html -// -/////////////////////////////////////////////////////////////////////////////// - -import jpos.util.*; -import java.io.PrintStream; - -/** - * Tracing class to help in the debugging of other package code - *
    - *
  1. - * Note 1: this class is a Singleton (see GoF Design Pattern book) - * ccess the sole instance by doing: Tracer.getInstance() call - *
  2. - *
  3. - * Note 2: Will allow (in the future) the option of defining different - * ouput for the tracer (1.3 version) - *
  4. - *
  5. - * By default Tracer objects are turned OFF but can dynamically or via - * properties file be turned OFF - *
  6. - *
- * @see Tracer#getInstance() - * @author E. Michael Maximilien - * @since 2.1.0 - */ -public class Tracer -{ - //------------------------------------------------------------------------- - // Ctor - // - - /** Make ctor private to avoid construction (this is a Singleton class) */ - protected Tracer() { appendName = false; } - - /** - * Creates a Tracer instance with name specified - * @param name the Tracer name - */ - Tracer( String name ) - { - if( name == null || name.equals( "" ) ) - { - appendName = false; - tracerName = ""; - onTracerOutput = new DefaultTracerOutput(); - } - else - { - appendName = true; - onTracerOutput = new DefaultTracerOutput( "[" + name + "]" ); - tracerName = name; - } - } - - //------------------------------------------------------------------------- - // Public class methods - // - - /** @return the sole instance of this class (creating it if necessary) */ - public static Tracer getInstance() - { - if( instance == null ) - { - instance = new Tracer(); - instance.init(); - } - - return instance; - } - - //------------------------------------------------------------------------- - // Public methods - // - - /** - * Prints a string appended with a new line to the tracer output - * @param s the String to print - */ - public void println( String s ) { getTracerOutput().println( s ); } - - /** - * Prints the String representation of the Object passed - * @param obj the Object to println - */ - public void println( Object obj ) { getTracerOutput().println( obj.toString() ); } - - /** - * Prints a string appended without a new line to the tracer output - * @param s the String to print - */ - public void print( String s ) { getTracerOutput().print( s ); } - - /** - * Prints a String representation of the Object passed - * @param obj the Object to print - */ - public void print( Object obj ) { getTracerOutput().print( obj.toString() ); } - - /** - * Prints a StackTrace from an Exception object. - * @param e the Exception to extract StackTrace from - */ - public void print( Exception e ) { getTracerOutput().print( e ); } - - /** Flushes the Tracer */ - public void flush() { getTracerOutput().flush(); } - - /** - * Sets this tracer ON or OFF - * @param b the boolean parameter - */ - public void setOn( boolean b ) { tracerOn = b; } - - /** @return true if the tracer is ON (i.e. enabled) */ - public boolean isOn() { return tracerOn; } - - /** @return this Tracer's name */ - public String getName() { return tracerName; } - - /** - * Tells Tracer instance whether it should append name for each trace - * message or not - * @param b the boolean parameter - */ - public void setAppendName( boolean b ) { appendName = b; } - - /** @return whether the Tracer should append its name to each println method call */ - public boolean isAppendName() { return appendName; } - - //------------------------------------------------------------------------- - // Protected methods - // - - //------------------------------------------------------------------------- - // Private methods - // - - /** Intialize the current instance using the DefaultProperties class */ - private void init() - { - JposProperties props = new DefaultProperties(); - props.loadJposProperties(); - - if( !props.isPropertyDefined( JposProperties.TRACING_PROP_NAME ) ) - setOn( false ); - else - { - String tracingPropValue = props.getPropertyString( JposProperties.TRACING_PROP_NAME ); - - if( tracingPropValue.equalsIgnoreCase( JposProperties.TRACING_ON_PROP_VALUE ) || - tracingPropValue.equalsIgnoreCase( JposProperties.TRACING_TRUE_PROP_VALUE ) ) - setOn( true ); - } - } - - /** @return the tracerOutput object for the Tracer */ - private TracerOutput getTracerOutput() - { - if( customTracerOutput != null ) return customTracerOutput; - - return ( isOn() ? onTracerOutput : offTracerOutput ); - } - - //------------------------------------------------------------------------- - // Package methods - // - - /** - * Sets the TracerOutput object -- for debugging purposes - * @param tracerOutput the TracerOutput object - */ - void setTracerOutput( TracerOutput tracerOutput ) - { - tracerOn = true; - customTracerOutput = tracerOutput; - } - - //------------------------------------------------------------------------- - // Private instance variables - // - - private boolean tracerOn = false; - - private String tracerName = ""; - private boolean appendName = true; - - private TracerOutput customTracerOutput = null; - private TracerOutput onTracerOutput = new DefaultTracerOutput(); - - private TracerOutput offTracerOutput = new TracerOutput() - { - public void close() {} - public String getPrefix() { return ""; } - public void print( Exception e ) {} - public void println( String s ) {} - public void print( String s ) {} - public void flush() {} - }; - - //------------------------------------------------------------------------- - // Private class variables - // - - private static Tracer instance = null; - - //------------------------------------------------------------------------- - // Private static inner classes - // - - /** - * Inner class for a default TracerOutput. Just prints out info to System.err - * @author E. Michael Maximilien - */ - class DefaultTracerOutput implements TracerOutput - { - //--------------------------------------------------------------------- - // Ctor(s) - // - - /** - * Default ctor. No prefix is used and the PrintStream is set - * to the System.err PrintStream - */ - public DefaultTracerOutput() - { - prefix = ""; - appendName = false; - } - - /** - * Default ctor - * @param s the String prefix to use for this TracerOutput - */ - public DefaultTracerOutput( String s ) - { - if( s == null ) prefix = ""; - else - if( s.equals( "" ) ) prefix = ""; - else - { - prefix = s; - appendName = true; - } - } - - /** - * Default ctor - * @param s the String prefix to use for this TracerOutput - * @param pStream the PrintStream object used for this TracerOutput - */ - public DefaultTracerOutput( String s, PrintStream pStream ) - { - this( s ); - printStream = pStream; - } - - //--------------------------------------------------------------------- - // Public methods - // - - /** - * @return any prefix that is to be used with this TracerOutput - *

An existing prefix gets appended to every message

- */ - public String getPrefix() { return prefix; } - - /** - * Closes the TracerOutput. If it is a file then closes the file - * Any errors are not propagated up and rather printed to the System.errr - */ - public void close() { getPrintStream().close(); } - - /** - * Prints a string appended with a new line to the tracer output - * @param s the String to print - */ - public void println( String s ) - { - getPrintStream().println( ( appendName ? prefix : "" ) + s ); - } - - /** - * Prints a string appended without a new line to the tracer output - * @param s the String to print - */ - public void print( String s ) - { - getPrintStream().print( ( appendName ? prefix : "" ) + s ); - } - - /** - * Prints a StackTrace from an Exception object. - * @param e the Exception to extract StackTrace from - */ - public void print( Exception e ) - { - if( appendName ) System.err.println( "<" + prefix + ">" ); - - e.printStackTrace( getPrintStream() ); - - if( appendName ) System.err.println( "" ); - } - - /** - * Flushes this TracerOutput - * - * For this TracerOutput does not do anything since output flushes - * automatically - * - */ - public void flush() { getPrintStream().flush(); } - - //------------------------------------------------------------------------- - // Protected methods - // - - /** @return the PrintStream object that is used for this TracerOutput */ - protected PrintStream getPrintStream() { return printStream; } - - /** - * Sets the PrintStream for this TracerOutput - * @param pStream a PrintStream object - */ - protected void setPrintStream( PrintStream pStream ) { printStream = pStream; } - - //------------------------------------------------------------------------- - // Instance variables - // - - protected String prefix = ""; - protected PrintStream printStream = System.err; - } -} \ No newline at end of file diff --git a/src/main/java/jpos/util/tracing/TracerFactory.java b/src/main/java/jpos/util/tracing/TracerFactory.java deleted file mode 100644 index bbf829a..0000000 --- a/src/main/java/jpos/util/tracing/TracerFactory.java +++ /dev/null @@ -1,316 +0,0 @@ -package jpos.util.tracing; - -/////////////////////////////////////////////////////////////////////////////// -// -// This software is provided "AS IS". The JavaPOS working group (including -// each of the Corporate members, contributors and individuals) MAKES NO -// REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, -// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED -// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NON-INFRINGEMENT. The JavaPOS working group shall not be liable for -// any damages suffered as a result of using, modifying or distributing this -// software or its derivatives. Permission to use, copy, modify, and distribute -// the software and its documentation for any purpose is hereby granted. -// -// The JavaPOS Config/Loader (aka JCL) is now under the CPL license, which -// is an OSS Apache-like license. The complete license is located at: -// http://www.ibm.com/developerworks/library/os-cpl.html -// -/////////////////////////////////////////////////////////////////////////////// - -import java.io.File; -import java.io.IOException; -import java.io.PrintStream; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; - -import jpos.util.*; - -/** - * This is a singleton factory used to create Tracer objects and access the - * global tracer. This implementation has the following semantics: - *
    - *
  1. Its a Singleton class but can be subclassed if necessary
  2. - *
  3. It caches the default no-named Tracer. This is the global Tracer
  4. - *
  5. - * It caches the Tracer objects according to name and any access for the - * same named Tracer will return the same Tracer object - *
  6. - *
- * @see Tracer#getInstance() - * @author E. Michael Maximilien - * @since 2.1.0 - */ -public class TracerFactory -{ - //------------------------------------------------------------------------- - // Ctor - // - - /** Make ctor protected to avoid construction (this is a Singleton class) */ - protected TracerFactory() {} - - //------------------------------------------------------------------------- - // Public class methods - // - - /** @return the sole instance of this class (creating it if necessary) */ - public static TracerFactory getInstance() - { - if( instance == null ) - { - instance = new TracerFactory(); - instance.init(); - } - - return instance; - } - - //------------------------------------------------------------------------- - // Public methods - // - - /** - * Sets the File that all subsequently created Tracer objects will print to - * if these Tracer objects are turned on. Successfully calling this method - * overrides the current setting for TracerOutput to files. - * Note: This is not implemented yet! - * @param file the {@link File} the output should be written to - * @throws java.io.IOException if a PrintStream could not be created from File - */ - public void setOutputFile( File file ) throws IOException - { - // not implemented yet - } - - /** - * @return the global no named Tracer object -- creates it if necessary - * Its state is determined by the jutil.properties value - */ - public Tracer createGlobalTracer() { return globalTracer; } - - /** - * @return the global no named Tracer object -- creates it if necessary - * Its state is determined by the jutil.properties value - * @param b the boolean parameter for the initial state of the tracer - */ - public Tracer createGlobalTracer( boolean b ) - { - globalTracer.setOn( b ); - return globalTracer; - } - - /** - * @return creates (if necessary) and return the Tracer with named specified - * Its state is determined by the jutil.properties value - * @param name the Tracer name - */ - public Tracer createTracer( String name ) - { - if( tracerMap.containsKey( name ) ) - return tracerMap.get( name ); - - Tracer tracer = new Tracer( name ); - - if( namedTracerState.containsKey( name ) ) - tracer.setOn( ( namedTracerState.get( name ) ).booleanValue() ); - else - tracer.setOn( false ); - - if( turnOnAllNamedTracers ) - tracer.setOn( true ); - - tracerMap.put( name, tracer ); - - return tracer; - } - - /** - * @return creates (if necessary) and return the Tracer with named specified - * Its state is determined by the jutil.properties value - * @param name the Tracer name - * @param b the boolean parameter for the initial state of the tracer - */ - public Tracer createTracer( String name, boolean b ) - { - Tracer tracer = createTracer( name ); - tracer.setOn( b ); - - return tracer; - } - - //------------------------------------------------------------------------- - // Protected methods - // - - /** - * Finalizes this Tracer by closing the TracerOutput. This is useful - * if the TracerOutput is printing to a file. This method would then - * close that file - */ - protected void finalize() - { - if( printStream != null ) printStream.close(); - } - - //------------------------------------------------------------------------- - // Private methods - // - - /** - * @return true if the propertyValue passed is valid and is equals (ignoring - * case) to TRUE or YES - * @param propValue the property value to check - */ - private boolean isPropertyTrue( String propValue ) - { - if( propValue == null ) - return false; - - if( propValue.equalsIgnoreCase( JposProperties.TRACING_ON_PROP_VALUE ) || - propValue.equalsIgnoreCase( JposProperties.TRACING_TRUE_PROP_VALUE ) ) - { - return true; - } - - return false; - } - - /** Intialize the current instance using the DefaultProperties class */ - private void init() - { - JposProperties props = new DefaultProperties(); - props.loadJposProperties(); - - initGlobalTracer( props ); - initTurnedOnTracers( props ); - initNamedTracers( props ); - } - - /** - * Initializes the state of the globalTracer -not named - * @param props the JposProperties instance - */ - private void initGlobalTracer( JposProperties props ) - { - if( !props.isPropertyDefined( TRACING_PROP_NAME ) ) - globalTracer.setOn( false ); - else - { - String tracingPropValue = - props.getPropertyString( TRACING_PROP_NAME ); - - if( isPropertyTrue( tracingPropValue ) ) - globalTracer.setOn( true ); - } - } - - /** - * Sets to on all named tracers listed in the value of the... - * TurnOnNamedTracers property - * @param props the JposProperties instance - */ - private void initTurnedOnTracers( JposProperties props ) - { - if( props.isPropertyDefined( TURN_ON_ALL_NAMED_TRACERS_PROP_NAME ) ) - { - String turnOnAllNamedTracersValue = props. - getPropertyString( TURN_ON_ALL_NAMED_TRACERS_PROP_NAME ); - - if( isPropertyTrue( turnOnAllNamedTracersValue ) ) - turnOnAllNamedTracers = true; - else - turnOnAllNamedTracers = false; - } - else - if( props.isPropertyDefined( TURN_ON_NAMED_TRACERS_PROP_NAME ) ) - { - @SuppressWarnings("unchecked") - List turnOnNamedTracersList = - props.getStringListProperty( TURN_ON_NAMED_TRACERS_PROP_NAME ); - - for (String tracerName : turnOnNamedTracersList) { - namedTracerState.put( tracerName.trim(), Boolean.TRUE ); - } - } - } - - /** - * Initializes the state of all named Tracer objects - * @param props the JposProperties instance - */ - private void initNamedTracers( JposProperties props ) - { - @SuppressWarnings("unchecked") - Enumeration propNames = props.getPropertyNames(); - - while( propNames.hasMoreElements() ) - { - String propName = propNames.nextElement(); - - if( propName.startsWith( TRACER_PROP_NAME ) ) - { - String name = propName.substring( ( TRACER_PROP_NAME + "." ).length(), propName.length() ); - - if( props.isPropertyDefined( propName ) ) - { - String propValue = props.getPropertyString( propName ); - - if( propValue.equalsIgnoreCase( JposProperties. - TRACING_ON_PROP_VALUE ) || - propValue.equalsIgnoreCase( JposProperties. - TRACING_TRUE_PROP_VALUE ) ) - namedTracerState.put( name, Boolean.TRUE ); - else - namedTracerState.put( name, Boolean.FALSE ); - } - } - } - } - - //------------------------------------------------------------------------- - // Private instance variables - // - - private final HashMap tracerMap = new HashMap<>(); - private final HashMap namedTracerState = new HashMap<>(); - - private Tracer globalTracer = Tracer.getInstance(); - - private PrintStream printStream = null; - - private boolean turnOnAllNamedTracers = false; - - //------------------------------------------------------------------------- - // Private class variables - // - - private static TracerFactory instance = null; - - //------------------------------------------------------------------------- - // Class constants - // - - public static final String TRACING_PROP_NAME = "jpos.tracing"; - - public static final String TRACER_PROP_NAME = - "jpos.util.tracing.Tracer"; - - public static final String TURN_ON_NAMED_TRACERS_PROP_NAME = - "jpos.util.tracing.TurnOnNamedTracers"; - - public static final String TURN_ON_ALL_NAMED_TRACERS_PROP_NAME = - "jpos.util.tracing.TurnOnAllNamedTracers"; - - public static final String TRACER_OUTPUT_TO_FILE_PROP_NAME = - "jpos.util.tracing.TracerOutputToFile"; - - public static final String TRACER_OUTPUT_FILE_NAME_PROP_NAME = - "jpos.util.tracing.TracerOutputFileName"; - - public static final String TRACER_OUTPUT_FILE_LOCATION = - "jpos.util.tracing.TracerOutputFileLocation"; - - public static final String USER_HOME_LOCATION_VALUE = ""; -} \ No newline at end of file diff --git a/src/main/java/jpos/util/tracing/TracerOutput.java b/src/main/java/jpos/util/tracing/TracerOutput.java deleted file mode 100644 index 8ebd4cc..0000000 --- a/src/main/java/jpos/util/tracing/TracerOutput.java +++ /dev/null @@ -1,64 +0,0 @@ -package jpos.util.tracing; - -/////////////////////////////////////////////////////////////////////////////// -// -// This software is provided "AS IS". The JavaPOS working group (including -// each of the Corporate members, contributors and individuals) MAKES NO -// REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, -// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED -// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NON-INFRINGEMENT. The JavaPOS working group shall not be liable for -// any damages suffered as a result of using, modifying or distributing this -// software or its derivatives. Permission to use, copy, modify, and distribute -// the software and its documentation for any purpose is hereby granted. -// -// The JavaPOS Config/Loader (aka JCL) is now under the CPL license, which -// is an OSS Apache-like license. The complete license is located at: -// http://www.ibm.com/developerworks/library/os-cpl.html -// -/////////////////////////////////////////////////////////////////////////////// - -/** - * Defines an interface for outputing tracing info - * @author E. Michael Maximilien - * @since 2.1.0 - */ -public interface TracerOutput -{ - //------------------------------------------------------------------------- - // Public methods - // - - /** - * @return any suffix that is to be used with this TracerOutput - *

An existing suffix gets appended to every message

- */ - public String getPrefix(); - - /** - * Closes the TracerOutput. If it is a file then closes the file - * Any errors are not propagated up and rather printed to the System.errr - */ - void close(); - - /** - * Prints a string appended with a new line to the tracer output - * @param s the String to print - */ - public void println( String s ); - - /** - * Prints a string appended without a new line to the tracer output - * @param s the String to print - */ - public void print( String s ); - - /** - * Prints a StackTrace from an Exception object. - * @param e the Exception to extract StackTrace from - */ - public void print( Exception e ); - - /** Flushes the output */ - public void flush(); -} \ No newline at end of file diff --git a/src/main/java/jpos/util/tracing/Tracing.java b/src/main/java/jpos/util/tracing/Tracing.java deleted file mode 100644 index 6e32f25..0000000 --- a/src/main/java/jpos/util/tracing/Tracing.java +++ /dev/null @@ -1,76 +0,0 @@ -package jpos.util.tracing; - -/////////////////////////////////////////////////////////////////////////////// -// -// This software is provided "AS IS". The JavaPOS working group (including -// each of the Corporate members, contributors and individuals) MAKES NO -// REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, -// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED -// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NON-INFRINGEMENT. The JavaPOS working group shall not be liable for -// any damages suffered as a result of using, modifying or distributing this -// software or its derivatives. Permission to use, copy, modify, and distribute -// the software and its documentation for any purpose is hereby granted. -// -// The JavaPOS Config/Loader (aka JCL) is now under the CPL license, which -// is an OSS Apache-like license. The complete license is located at: -// http://www.ibm.com/developerworks/library/os-cpl.html -// -/////////////////////////////////////////////////////////////////////////////// - -/** - * Tracing class to help in the debugging of other package code - * This class uses the Tracer class for all its static methods implementations - * its a convinient class to avoid having to cache the Tracer object or having - * to do Tracer.getInstance() everytime you need to access the Tracer. - * @author E. Michael Maximilien - */ -public class Tracing -{ - //------------------------------------------------------------------------- - // Ctor - // - - /** Make ctor private to avoid construction */ - private Tracing() {} - - //------------------------------------------------------------------------- - // Public class methods - // - - /** - * Class method that facilitate usage of Tracer.println() method - * @param obj the Object to print -- obj.toString() - */ - public static void println( Object obj ) { tracer.println( obj.toString() ); } - - /** - * Class print method that facilitate usage Tracer.print() method - * @param obj the Object to print -- obj.toString() - */ - public static void print( Object obj ) { tracer.print( obj.toString() ); } - - /** - * Prints a StackTrace from an Exception object. - * @param e the Exception to extract StackTrace from - */ - public static void print( Exception e ) { tracer.print( e ); } - - /** Flushes the TracerOutput */ - public static void flush() { tracer.flush(); } - - /** - * Sets this tracer ON or OFF - * @param b the boolean parameter - */ - public static void setOn( boolean b ) { tracer.setOn( b ); } - - /** @return true if the tracer is ON (i.e. enabled) */ - public static boolean isOn() { return tracer.isOn(); } - - //--------------------------------------------------------------------------- - // Class variables - // - - private static Tracer tracer = TracerFactory.getInstance().createGlobalTracer(); -} diff --git a/src/test/java/jpos/util/tracing/TracerFactoryTestCase.java b/src/test/java/jpos/util/tracing/TracerFactoryTestCase.java deleted file mode 100644 index 8d7cca2..0000000 --- a/src/test/java/jpos/util/tracing/TracerFactoryTestCase.java +++ /dev/null @@ -1,107 +0,0 @@ -package jpos.util.tracing; - -/* - */ - -import junit.framework.*; - -/** - * Tests the TracerFactory class - * @author E. Michael Maximilien - * @since 2.1.0 - */ -public class TracerFactoryTestCase extends TestCase -{ - //------------------------------------------------------------------------- - // Ctor(s) - // - - public TracerFactoryTestCase( String name ) { super( name ); } - - //------------------------------------------------------------------------- - // Protected methods - // - - protected void setUp() - { - tracerFactory = TracerFactory.getInstance(); - - globalTracer = tracerFactory.createGlobalTracer(); - tracer1 = tracerFactory.createTracer( NAMEDTRACER1_NAME ); - tracer2 = tracerFactory.createTracer( NAMEDTRACER2_NAME ); - } - - protected void tearDown() - { - tracerFactory = null; - - globalTracer = null; - tracer1 = null; - tracer2 = null; - } - - //--------------------------------------------------------------------- - // Public test methods - // - - public void testGetInstance() - { - assertTrue( "TracerFactory.getInstance() return different instances", - tracerFactory == TracerFactory.getInstance() ); - } - - public void testCreateGlobalTracer() - { - assertTrue( "Got different GlobalTracer objects", - globalTracer == TracerFactory.getInstance().createGlobalTracer() ); - - assertTrue( "Got a GlobalTracer with incorrect state", - TracerFactory.getInstance().createGlobalTracer( true ).isOn() == true ); - } - - public void testCreateTracer1() - { - assertTrue( "Got different Tracer1 objects", - tracer1 == TracerFactory.getInstance(). - createTracer( NAMEDTRACER1_NAME ) ); - - assertTrue( "Got different Tracer2 objects", - tracer2 == TracerFactory.getInstance(). - createTracer( NAMEDTRACER2_NAME ) ); - - assertTrue( "Got a Tracer with incorrect state", - TracerFactory.getInstance(). - createTracer( NAMEDTRACER1_NAME, true ).isOn() == true ); - - assertTrue( "Got a Tracer with incorrect state", - TracerFactory.getInstance(). - createTracer( NAMEDTRACER1_NAME, false ).isOn() == false ); - } - - public void testCreateTracer2() - { - //verify Tracer created ON/OFF accoring to jutil.properties file - } - - public void testSetPrintStream() - { - //verify that file gets created with data and messages correct - } - - //----------------------------------------------------------------------- - // Instance variables - // - - private TracerFactory tracerFactory = null; - - private Tracer globalTracer = null; - private Tracer tracer1 = null; - private Tracer tracer2 = null; - - //----------------------------------------------------------------------- - // Class constants - // - - public static final String NAMEDTRACER1_NAME = "NamedTracer1"; - public static final String NAMEDTRACER2_NAME = "NamedTracer2"; -} \ No newline at end of file diff --git a/src/test/java/jpos/util/tracing/TracerTestCase.java b/src/test/java/jpos/util/tracing/TracerTestCase.java deleted file mode 100644 index 7666a62..0000000 --- a/src/test/java/jpos/util/tracing/TracerTestCase.java +++ /dev/null @@ -1,197 +0,0 @@ -package jpos.util.tracing; - -/* - */ - -import junit.framework.*; - -/** - * Tests the Tracer class - * @author E. Michael Maximilien - * @since 2.1.0 - */ -public class TracerTestCase extends TestCase -{ - //------------------------------------------------------------------------- - // Ctor(s) - // - - public TracerTestCase( String name ) - { - super( name ); - } - - protected void setUp() - { - tracer = Tracer.getInstance(); - testTracerOutput = this.new TestTracerOutput(); - tracer.setTracerOutput( testTracerOutput ); - - namedTracer = new Tracer( NAMED_TRACER_NAME ); - } - - protected void tearDown() - { - tracer = null; - testTracerOutput = null; - - namedTracer = null; - } - - //--------------------------------------------------------------------- - // Public test methods - // - - public void testGetInstance() - { - Tracer tracer1 = Tracer.getInstance(); - assertTrue( "Did not get same instance from calls to Tracer.getInstance()", - tracer1 == Tracer.getInstance() ); - } - - public void testStringPrintln() - { - String testString = "testString"; - tracer.println( testString ); - - assertTrue( "TracerOutput did not get testString", - testTracerOutput.getPrintlnString().equals( testString ) ); - } - - public void testStringPrint() - { - String testString = "testString"; - tracer.print( testString ); - - assertTrue( "TracerOutput did not get testString", - testTracerOutput.getPrintString().equals( testString ) ); - } - - public void testObjectPrintln() - { - Object testObj = new Integer( 10 ); - tracer.println( testObj ); - - assertTrue( "TracerOutput did not get testObj", - testTracerOutput.getPrintlnString().equals( testObj.toString() ) ); - } - - public void testObjectPrint() - { - Object testObj = new Boolean( false ); - tracer.print( testObj ); - - assertTrue( "TracerOutput did not get testObj", - testTracerOutput.getPrintString().equals( testObj.toString() ) ); - } - - public void testFlush() - { - Object testObj = "testString"; - tracer.print( testObj ); - tracer.flush(); - - assertTrue( "TracerOutput did not get flush call", - testTracerOutput.isFlush() ); - } - - public void testExceptionPrint() - { - Exception e = new IllegalArgumentException(); - tracer.print(e); - - assertTrue( "Exception not equal to printed exception", - testTracerOutput.getException().equals(e)); - } - - public void testIsAppendName() - { - assertTrue( "Default Tracer should have no name and isAppendName() == false", - tracer.isAppendName() == false ); - - assertTrue( "Named Tracer should default to isAppendName() == true", - namedTracer.isAppendName() ); - } - - public void testSetAppendName() - { - assertTrue( "Named Tracer should default to isAppendName() == true", - namedTracer.isAppendName() ); - - namedTracer.setAppendName( false ); - - assertTrue( "Named Tracer should default to isAppendName() == true", - namedTracer.isAppendName() == false ); - } - - public void testCreateTracerWithName() - { - Tracer newNamedTracer = new Tracer( "newNamedTracer" ); - - assertTrue( "newNamedTracer should default to isAppenName() == true", - newNamedTracer.isAppendName() ); - - assertTrue( "newNamedTracer.getName().equals( \"newNamedTracer\"", - newNamedTracer.getName().equals( "newNamedTracer" ) ); - } - - //----------------------------------------------------------------------- - // Instance variables - // - - private Tracer namedTracer = null; - private Tracer tracer = null; - private TestTracerOutput testTracerOutput = null; - - //----------------------------------------------------------------------- - // Class constants - // - - public static final String NAMED_TRACER_NAME = "NamedTracer"; - - - //----------------------------------------------------------------------- - // Inner classes - // - - protected class TestTracerOutput extends Object implements TracerOutput - { - //--------------------------------------------------------------------- - // Ctor(s) - // - - //--------------------------------------------------------------------- - // Public methods - // - - public void close() {} - - public String getPrefix() { return suffix; } - - public void print( Exception e ) { exception = e; } - - public void println( String s ) { printlnString = s; } - - public void print( String s ) { printString = s; } - - public void flush() { flushed = true; } - - boolean isFlush() { return flushed; } - - String getPrintString() { return printString; } - - String getPrintlnString() { return printlnString; } - - Exception getException() { return exception; } - - //--------------------------------------------------------------------- - // Instance variables - // - - private String suffix = ""; - private boolean flushed = false; - private String printlnString = ""; - private String printString = ""; - private Exception exception = null; - } -} \ No newline at end of file From d0b22595cdb69b9c73a77ba0a699dec79c46b0f9 Mon Sep 17 00:00:00 2001 From: Denis Kuniss Date: Mon, 22 Jul 2024 17:47:20 +0200 Subject: [PATCH 2/4] Corrected a SLF4J API mis-usage which avoids an important message to be logged. --- src/main/java/jpos/config/simple/xml/JavaxRegPopulator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/jpos/config/simple/xml/JavaxRegPopulator.java b/src/main/java/jpos/config/simple/xml/JavaxRegPopulator.java index 80003c4..8c6115a 100644 --- a/src/main/java/jpos/config/simple/xml/JavaxRegPopulator.java +++ b/src/main/java/jpos/config/simple/xml/JavaxRegPopulator.java @@ -129,7 +129,7 @@ public void save(@SuppressWarnings("rawtypes") Enumeration entries, String fileN { log.atInfo() .setMessage("saving JavaPOS configuration to file {}") - .addArgument(() -> new File(fileName).getAbsolutePath()); + .addArgument(() -> new File(fileName).getAbsolutePath()).log(); try (FileOutputStream os = new FileOutputStream(fileName)) { save(entries, os); } @@ -149,7 +149,7 @@ public void load() { public void load(String fileName) { log.atInfo() .setMessage("loading JavaPOS configuration from file {}") - .addArgument(() -> new File(fileName).getAbsolutePath()); + .addArgument(() -> new File(fileName).getAbsolutePath()).log(); try (InputStream is = new File(fileName).exists() ? new FileInputStream(fileName) : findFileInClasspath(fileName)) { load(is); } catch (Exception e) { From 1dc2126ff1387af7a10c4d3a63b7e72ab32795a4 Mon Sep 17 00:00:00 2001 From: Denis Kuniss Date: Fri, 13 Sep 2024 15:43:20 +0200 Subject: [PATCH 3/4] Switched back to SLF4J version 1 by eliminating version 2 API calls and replacing them accordingly by calls from version 1. This is for extending the range of applications compatible with the new javapos-config-loader version as SLF4J version 2 can be used with version 1 implementations too. --- .../jpos/config/simple/xml/JavaxRegPopulator.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/jpos/config/simple/xml/JavaxRegPopulator.java b/src/main/java/jpos/config/simple/xml/JavaxRegPopulator.java index 8c6115a..17e030b 100644 --- a/src/main/java/jpos/config/simple/xml/JavaxRegPopulator.java +++ b/src/main/java/jpos/config/simple/xml/JavaxRegPopulator.java @@ -127,9 +127,7 @@ public void save(@SuppressWarnings("rawtypes") Enumeration entries) throws Excep @Override public void save(@SuppressWarnings("rawtypes") Enumeration entries, String fileName) throws Exception { - log.atInfo() - .setMessage("saving JavaPOS configuration to file {}") - .addArgument(() -> new File(fileName).getAbsolutePath()).log(); + log.info("saving JavaPOS configuration to file '{}'", new File(fileName).getAbsolutePath()); try (FileOutputStream os = new FileOutputStream(fileName)) { save(entries, os); } @@ -147,10 +145,12 @@ public void load() { @Override public void load(String fileName) { - log.atInfo() - .setMessage("loading JavaPOS configuration from file {}") - .addArgument(() -> new File(fileName).getAbsolutePath()).log(); - try (InputStream is = new File(fileName).exists() ? new FileInputStream(fileName) : findFileInClasspath(fileName)) { + File file = new File(fileName); + if (file.exists()) + log.info("loading JavaPOS configuration from file '{}'", file.getAbsolutePath()); + else + log.info("loading JavaPOS configuration from file '{}' from Classpath", fileName); + try (InputStream is = file.exists() ? new FileInputStream(fileName) : findFileInClasspath(fileName)) { load(is); } catch (Exception e) { log.error("Error while loading populator file Exception.message: {}", e.getMessage()); From 8fec9a8447798775b0d06f67922c2f3a22b89a42 Mon Sep 17 00:00:00 2001 From: Denis Kuniss Date: Fri, 13 Sep 2024 15:46:38 +0200 Subject: [PATCH 4/4] Prepared new major version 5 containing switch to SLF4J logging. This introduces dependency to slf4j-api version 1.7.36. --- CHANGELOG.md | 5 ++++- build.gradle | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65c9a58..76920db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log for javapos-config-loader +## 5.0.0 + +- replaced legacy logging implementation by the logging facade SLF4J version 1, see https://www.slf4j.org/ for details on how to integrate + ## 4.0.2 - fixed resource loading from JAR file on the class-path (contributed by @art-and-co through [PR #13](https://github.com/JavaPOSWorkingGroup/javapos-config-loader/issues/13)) @@ -11,7 +15,6 @@ ## 4.0.0 -- replaced legacy logging implementation by the logging facade SLF4J, see https://www.slf4j.org/ for details on how to integrate - jpos.config.DefaultCompositeRegPopulator.load() is throwing more specific IllegalArgument exception instead of RuntimeException - added Javax XML parser based XML registry populator implementation (contributed by @mjpcger) - removed Xerces based XML registry populator implementations, mainly diff --git a/build.gradle b/build.gradle index 7f519e6..1e3aa5f 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ wrapper { def artifactName = 'javapos-config-loader' group='org.javapos' -version='4.0.2-SNAPSHOT' // if version is going to be changed, first add "-SNAPSHOT" to test publishing to MavenCentral's Snapshot repo +version='5.0.0-SNAPSHOT' // if version is going to be changed, first add "-SNAPSHOT" to test publishing to MavenCentral's Snapshot repo /////////////////////////////////////////////////////////////////////////////// @@ -65,11 +65,11 @@ def testResourceDir = file("${System.properties['java.io.tmpdir']}/javapos-confi dependencies { api 'org.javapos:javapos-contracts:1.6.0' - implementation 'org.slf4j:slf4j-api:2.0.13' + implementation 'org.slf4j:slf4j-api:1.7.36' testImplementation("junit:junit:4.13.2") - testRuntimeOnly 'org.slf4j:slf4j-simple:2.0.13' + testRuntimeOnly 'org.slf4j:slf4j-simple:1.7.36' testRuntimeOnly files(testResourceDir) }