diff --git a/source/org/jivesoftware/smack/AccountManager.java b/source/org/jivesoftware/smack/AccountManager.java index aa71c07ec..b90391c4b 100644 --- a/source/org/jivesoftware/smack/AccountManager.java +++ b/source/org/jivesoftware/smack/AccountManager.java @@ -32,6 +32,8 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Allows creation and management of accounts on an XMPP server. @@ -40,7 +42,8 @@ import java.util.Map; * @author Matt Tucker */ public class AccountManager { - + private static Logger logger = Logger.getLogger(AccountManager.class.getName()); + private Connection connection; private Registration info = null; @@ -134,7 +137,7 @@ public class AccountManager { } } catch (XMPPException xe) { - xe.printStackTrace(); + logger.log(Level.SEVERE, "Error retrieving account attributes from server", xe); } return Collections.emptySet(); } @@ -155,7 +158,7 @@ public class AccountManager { return info.getAttributes().get(name); } catch (XMPPException xe) { - xe.printStackTrace(); + logger.log(Level.SEVERE, "Error retrieving account attribute " + name + " info from server", xe); } return null; } @@ -175,6 +178,7 @@ public class AccountManager { return info.getInstructions(); } catch (XMPPException xe) { + logger.log(Level.SEVERE, "Error retrieving account instructions from server", xe); return null; } } diff --git a/source/org/jivesoftware/smack/Connection.java b/source/org/jivesoftware/smack/Connection.java index 925c26ef0..bd289e34a 100644 --- a/source/org/jivesoftware/smack/Connection.java +++ b/source/org/jivesoftware/smack/Connection.java @@ -34,6 +34,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.atomic.AtomicInteger; +import java.util.logging.Logger; import org.jivesoftware.smack.compression.JzlibInputOutputStream; import org.jivesoftware.smack.compression.XMPPInputOutputStream; @@ -83,7 +84,8 @@ import org.jivesoftware.smack.packet.Presence; * @author Guenther Niess */ public abstract class Connection { - + private static Logger log = Logger.getLogger(Connection.class.getName()); + /** * Counter to uniquely identify connections that are created. */ @@ -764,7 +766,7 @@ public abstract class Connection { debuggerClass = Class.forName(className); } catch (Exception e) { - e.printStackTrace(); + log.warning("Unabled to instantiate debugger class " + className); } } if (debuggerClass == null) { @@ -778,7 +780,7 @@ public abstract class Connection { Class.forName("org.jivesoftware.smack.debugger.LiteDebugger"); } catch (Exception ex2) { - ex2.printStackTrace(); + log.warning("Unabled to instantiate either Smack debugger class"); } } } diff --git a/source/org/jivesoftware/smack/PacketReader.java b/source/org/jivesoftware/smack/PacketReader.java index 3aaad38c6..a00f53c5a 100644 --- a/source/org/jivesoftware/smack/PacketReader.java +++ b/source/org/jivesoftware/smack/PacketReader.java @@ -34,6 +34,8 @@ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.util.concurrent.*; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Listens for XML traffic from the XMPP server and parses it into packet objects. @@ -45,6 +47,8 @@ import java.util.concurrent.*; */ class PacketReader { + private static Logger log = Logger.getLogger(PacketReader.class.getName()); + private Thread readerThread; private ExecutorService listenerExecutor; @@ -134,7 +138,7 @@ class PacketReader { catch (Exception e) { // Catch and print any exception so we can recover // from a faulty listener and finish the shutdown process - e.printStackTrace(); + log.log(Level.SEVERE, "Error in listener while closing connection", e); } } } @@ -156,7 +160,7 @@ class PacketReader { parser.setInput(connection.reader); } catch (XmlPullParserException xppe) { - xppe.printStackTrace(); + log.log(Level.WARNING, "Error while resetting parser", xppe); } } @@ -451,8 +455,7 @@ class PacketReader { try { listenerWrapper.notifyListener(packet); } catch (Exception e) { - System.err.println("Exception in packet listener: " + e); - e.printStackTrace(); + log.log(Level.SEVERE, "Exception in packet listener", e); } } } diff --git a/source/org/jivesoftware/smack/PacketWriter.java b/source/org/jivesoftware/smack/PacketWriter.java index 7e347cb7d..6529ce330 100644 --- a/source/org/jivesoftware/smack/PacketWriter.java +++ b/source/org/jivesoftware/smack/PacketWriter.java @@ -26,6 +26,8 @@ import java.io.IOException; import java.io.Writer; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Writes packets to a XMPP server. Packets are sent using a dedicated thread. Packet @@ -38,7 +40,8 @@ import java.util.concurrent.BlockingQueue; * @author Matt Tucker */ class PacketWriter { - + private static Logger log = Logger.getLogger(PacketWriter.class.getName()); + private Thread writerThread; private Writer writer; private XMPPConnection connection; @@ -88,7 +91,7 @@ class PacketWriter { queue.put(packet); } catch (InterruptedException ie) { - ie.printStackTrace(); + log.log(Level.SEVERE, "Failed to queue packet to send to server: " + packet.toString(), ie); return; } synchronized (queue) { @@ -165,14 +168,14 @@ class PacketWriter { // we won't have time to entirely flush it before the socket is forced closed // by the shutdown process. try { - while (!queue.isEmpty()) { - Packet packet = queue.remove(); + while (!queue.isEmpty()) { + Packet packet = queue.remove(); writer.write(packet.toXML()); } writer.flush(); } catch (Exception e) { - e.printStackTrace(); + log.warning("Error flushing queue during shutdown, ignore and continue"); } // Delete the queue contents (hopefully nothing is left). diff --git a/source/org/jivesoftware/smack/ReconnectionManager.java b/source/org/jivesoftware/smack/ReconnectionManager.java index cc3e3af19..0f539b508 100644 --- a/source/org/jivesoftware/smack/ReconnectionManager.java +++ b/source/org/jivesoftware/smack/ReconnectionManager.java @@ -19,6 +19,7 @@ package org.jivesoftware.smack; import org.jivesoftware.smack.packet.StreamError; import java.util.Random; +import java.util.logging.Logger; /** * Handles the automatic reconnection process. Every time a connection is dropped without * the application explictly closing it, the manager automatically tries to reconnect to @@ -34,7 +35,8 @@ import java.util.Random; * @author Francisco Vives */ public class ReconnectionManager implements ConnectionListener { - + private static Logger log = Logger.getLogger(ReconnectionManager.class.getName()); + // Holds the connection to the server private Connection connection; private Thread reconnectionThread; @@ -132,8 +134,8 @@ public class ReconnectionManager implements ConnectionListener { ReconnectionManager.this .notifyAttemptToReconnectIn(remainingSeconds); } - catch (InterruptedException e1) { - e1.printStackTrace(); + catch (InterruptedException e1) { + log.warning("Sleeping thread interrupted"); // Notify the reconnection has failed ReconnectionManager.this.notifyReconnectionFailed(e1); } diff --git a/source/org/jivesoftware/smack/ServerTrustManager.java b/source/org/jivesoftware/smack/ServerTrustManager.java index 19faed90c..a9e45a308 100644 --- a/source/org/jivesoftware/smack/ServerTrustManager.java +++ b/source/org/jivesoftware/smack/ServerTrustManager.java @@ -29,6 +29,7 @@ import java.security.cert.CertificateException; import java.security.cert.CertificateParsingException; import java.security.cert.X509Certificate; import java.util.*; +import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -41,7 +42,8 @@ import java.util.regex.Pattern; * @author Gaston Dombiak */ class ServerTrustManager implements X509TrustManager { - + private static Logger log = Logger.getLogger(ServerTrustManager.class.getName()); + private static Pattern cnPattern = Pattern.compile("(?i)(cn=)([^,]*)"); private ConnectionConfiguration configuration; @@ -153,8 +155,7 @@ class ServerTrustManager implements X509TrustManager { trusted = trustStore.getCertificateAlias(x509Certificates[nSize - 1]) != null; if (!trusted && nSize == 1 && configuration.isSelfSignedCertificateEnabled()) { - System.out.println("Accepting self-signed certificate of remote server: " + - peerIdentities); + log.info("Accepting self-signed certificate of remote server: " + peerIdentities); trusted = true; } } @@ -268,7 +269,7 @@ class ServerTrustManager implements X509TrustManager { } } // Other types are not good for XMPP so ignore them - System.out.println("SubjectAltName of invalid type found: " + certificate); + log.info("SubjectAltName of invalid type found: " + certificate); }*/ } catch (CertificateParsingException e) { diff --git a/source/org/jivesoftware/smack/XMPPConnection.java b/source/org/jivesoftware/smack/XMPPConnection.java index c775e52e4..13c16e1cd 100644 --- a/source/org/jivesoftware/smack/XMPPConnection.java +++ b/source/org/jivesoftware/smack/XMPPConnection.java @@ -788,7 +788,6 @@ public class XMPPConnection extends Connection { if(config.getCallbackHandler() == null) { ks = null; } else if (context == null) { - //System.out.println("Keystore type: "+configuration.getKeystoreType()); if(config.getKeystoreType().equals("NONE")) { ks = null; pcb = null; diff --git a/source/org/jivesoftware/smack/packet/Packet.java b/source/org/jivesoftware/smack/packet/Packet.java index 27427acda..aeae72fdf 100644 --- a/source/org/jivesoftware/smack/packet/Packet.java +++ b/source/org/jivesoftware/smack/packet/Packet.java @@ -27,6 +27,8 @@ import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Base class for XMPP packets. Every packet has a unique ID (which is automatically @@ -41,7 +43,8 @@ import java.util.concurrent.CopyOnWriteArrayList; * @author Matt Tucker */ public abstract class Packet { - + private static Logger log = Logger.getLogger(Packet.class.getName()); + protected static final String DEFAULT_LANGUAGE = java.util.Locale.getDefault().getLanguage().toLowerCase(); @@ -411,7 +414,7 @@ public abstract class Packet { buf.append(encodedVal).append(""); } catch (Exception e) { - e.printStackTrace(); + log.log(Level.SEVERE, "Error encoding java object", e); } finally { if (out != null) { diff --git a/source/org/jivesoftware/smack/parsing/ExceptionLoggingCallback.java b/source/org/jivesoftware/smack/parsing/ExceptionLoggingCallback.java index 771913ebf..b9073c306 100644 --- a/source/org/jivesoftware/smack/parsing/ExceptionLoggingCallback.java +++ b/source/org/jivesoftware/smack/parsing/ExceptionLoggingCallback.java @@ -20,18 +20,21 @@ package org.jivesoftware.smack.parsing; +import java.util.logging.Level; +import java.util.logging.Logger; + /** - * Simple parsing exception callback that only logs the encountered parsing exception to stderr. + * Simple parsing exception callback that only logs the encountered parsing exception to java util logging. * * @author Florian Schmaus * */ public class ExceptionLoggingCallback extends ParsingExceptionCallback { - + private static Logger log = Logger.getLogger(ExceptionLoggingCallback.class.getName()); + @Override public void handleUnparsablePacket(UnparsablePacket unparsed) throws Exception { - System.err.print("Smack message parsing exception: " + unparsed.getParsingException().getMessage()); - unparsed.getParsingException().printStackTrace(); - System.err.println("Unparsed content: " + unparsed.getContent()); + log.log(Level.SEVERE, "Smack message parsing exception: ", unparsed.getParsingException()); + log.severe("Unparsed content: " + unparsed.getContent()); } } diff --git a/source/org/jivesoftware/smack/util/Base64.java b/source/org/jivesoftware/smack/util/Base64.java index ba6eb371f..2ddd0138f 100644 --- a/source/org/jivesoftware/smack/util/Base64.java +++ b/source/org/jivesoftware/smack/util/Base64.java @@ -5,6 +5,9 @@ * */ package org.jivesoftware.smack.util; + +import java.util.logging.Level; +import java.util.logging.Logger; /** *
Encodes and decodes to and from Base64 notation.
@@ -17,9 +20,9 @@ package org.jivesoftware.smack.util; */ public class Base64 { - -/* ******** P U B L I C F I E L D S ******** */ - + private static Logger log = Logger.getLogger(Base64.class.getName()); + + /* ******** P U B L I C F I E L D S ******** */ /** No options specified. Value is zero. */ public final static int NO_OPTIONS = 0; @@ -311,18 +314,6 @@ public class Base64 /** Defeats instantiation. */ private Base64(){} - /** - * Prints command line usage. - * - * @param msg A message to include with usage info. - */ - private final static void usage( String msg ) - { - System.err.println( msg ); - System.err.println( "Usage: java Base64 -e|-d inputfile outputfile" ); - } // end usage - - /* ******** E N C O D I N G M E T H O D S ******** */ @@ -494,7 +485,7 @@ public class Base64 } // end try catch( java.io.IOException e ) { - e.printStackTrace(); + log.log(Level.SEVERE, "Error encoding object", e); return null; } // end catch finally @@ -623,7 +614,7 @@ public class Base64 } // end try catch( java.io.IOException e ) { - e.printStackTrace(); + log.log(Level.SEVERE, "Error encoding bytes", e); return null; } // end catch finally @@ -777,11 +768,12 @@ public class Base64 destination[ destOffset + 2 ] = (byte)( outBuff ); return 3; - }catch( Exception e){ - System.out.println(""+source[srcOffset]+ ": " + ( DECODABET[ source[ srcOffset ] ] ) ); - System.out.println(""+source[srcOffset+1]+ ": " + ( DECODABET[ source[ srcOffset + 1 ] ] ) ); - System.out.println(""+source[srcOffset+2]+ ": " + ( DECODABET[ source[ srcOffset + 2 ] ] ) ); - System.out.println(""+source[srcOffset+3]+ ": " + ( DECODABET[ source[ srcOffset + 3 ] ] ) ); + }catch( Exception e){ + log.log(Level.SEVERE, e.getMessage(), e); + log.severe(""+source[srcOffset]+ ": " + ( DECODABET[ source[ srcOffset ] ] ) ); + log.severe(""+source[srcOffset+1]+ ": " + ( DECODABET[ source[ srcOffset + 1 ] ] ) ); + log.severe(""+source[srcOffset+2]+ ": " + ( DECODABET[ source[ srcOffset + 2 ] ] ) ); + log.severe(""+source[srcOffset+3]+ ": " + ( DECODABET[ source[ srcOffset + 3 ] ] ) ); return -1; } // end catch } @@ -839,7 +831,7 @@ public class Base64 } // end if: white space, equals sign or better else { - System.err.println( "Bad Base64 input character at " + i + ": " + source[i] + "(decimal)" ); + log.warning("Bad Base64 input character at " + i + ": " + source[i] + "(decimal)"); return null; } // end else: } // each input character @@ -967,12 +959,12 @@ public class Base64 } // end try catch( java.io.IOException e ) { - e.printStackTrace(); + log.log(Level.SEVERE, "Error reading object", e); obj = null; } // end catch catch( java.lang.ClassNotFoundException e ) { - e.printStackTrace(); + log.log(Level.SEVERE, "Class not found for encoded object", e); obj = null; } // end catch finally @@ -1079,7 +1071,7 @@ public class Base64 // Check for size of file if( file.length() > Integer.MAX_VALUE ) { - System.err.println( "File is too big for this convenience method (" + file.length() + " bytes)." ); + log.warning("File is too big for this convenience method (" + file.length() + " bytes)."); return null; } // end if: file too big for int index buffer = new byte[ (int)file.length() ]; @@ -1100,7 +1092,7 @@ public class Base64 } // end try catch( java.io.IOException e ) { - System.err.println( "Error decoding from file " + filename ); + log.log(Level.SEVERE, "Error decoding from file " + filename, e); } // end catch: IOException finally { @@ -1148,7 +1140,7 @@ public class Base64 } // end try catch( java.io.IOException e ) { - System.err.println( "Error encoding from file " + filename ); + log.log(Level.SEVERE, "Error encoding from file " + filename, e); } // end catch: IOException finally { @@ -1175,7 +1167,7 @@ public class Base64 out.write( encoded.getBytes("US-ASCII") ); // Strict, 7-bit output. } // end try catch( java.io.IOException ex ) { - ex.printStackTrace(); + log.log(Level.SEVERE, "Error encoding file " + infile, ex); } // end catch finally { try { out.close(); } @@ -1201,7 +1193,7 @@ public class Base64 out.write( decoded ); } // end try catch( java.io.IOException ex ) { - ex.printStackTrace(); + log.log(Level.SEVERE, "Error decoding file " + infile, ex); } // end catch finally { try { out.close(); } diff --git a/source/org/jivesoftware/smack/util/Cache.java b/source/org/jivesoftware/smack/util/Cache.java index 964ac2382..5426a4ad8 100644 --- a/source/org/jivesoftware/smack/util/Cache.java +++ b/source/org/jivesoftware/smack/util/Cache.java @@ -22,6 +22,7 @@ package org.jivesoftware.smack.util; import org.jivesoftware.smack.util.collections.AbstractMapEntry; import java.util.*; +import java.util.logging.Logger; /** * A specialized Map that is size-limited (using an LRU algorithm) and @@ -49,7 +50,7 @@ import java.util.*; * @author Matt Tucker */ public class Cache
* Default filename encoder {@link Base32Encoder}, as this will work on all
- * filesystems, both case sensitive and case insensitive. It does however
+ * file systems, both case sensitive and case insensitive. It does however
* produce longer filenames.
*
* @param cacheDir
@@ -92,7 +95,7 @@ public class SimpleDirectoryPersistentCache implements EntityCapsPersistentCache
if (nodeFile.createNewFile())
writeInfoToFile(nodeFile, info);
} catch (IOException e) {
- e.printStackTrace();
+ log.log(Level.SEVERE, "Failed to write disco info to file", e);
}
}
@@ -161,7 +164,7 @@ public class SimpleDirectoryPersistentCache implements EntityCapsPersistentCache
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
parser.setInput(reader);
} catch (XmlPullParserException xppe) {
- xppe.printStackTrace();
+ log.log(Level.SEVERE, "Exception initializing parser", xppe);
return null;
}
diff --git a/source/org/jivesoftware/smackx/muc/MultiUserChat.java b/source/org/jivesoftware/smackx/muc/MultiUserChat.java
index d657ee711..db8a80f73 100644
--- a/source/org/jivesoftware/smackx/muc/MultiUserChat.java
+++ b/source/org/jivesoftware/smackx/muc/MultiUserChat.java
@@ -31,6 +31,8 @@ import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ConnectionCreationListener;
@@ -76,7 +78,8 @@ import org.jivesoftware.smackx.packet.MUCUser;
* @author Gaston Dombiak, Larry Kirschner
*/
public class MultiUserChat {
-
+ private static Logger log = Logger.getLogger(MultiUserChat.class.getName());
+
private final static String discoNamespace = "http://jabber.org/protocol/muc";
private final static String discoNode = "http://jabber.org/protocol/muc#rooms";
@@ -179,7 +182,7 @@ public class MultiUserChat {
return result.containsFeature(discoNamespace);
}
catch (XMPPException e) {
- e.printStackTrace();
+ log.log(Level.SEVERE, "Error checking user [" + user + "] for MUC support", e);
return false;
}
}
@@ -222,7 +225,7 @@ public class MultiUserChat {
return answer.iterator();
}
catch (XMPPException e) {
- e.printStackTrace();
+ log.log(Level.SEVERE, "Error getting joined rooms for user [" + user + "]", e);
// Return an iterator on an empty collection
return new ArrayList