From 1d837a835c04078ec66325e9fb9de21ac401874e Mon Sep 17 00:00:00 2001 From: Alexander Alexeev Date: Wed, 30 Nov 2016 15:10:15 +0700 Subject: prevent string concatenation for disabled loggers --- .../com/juick/components/s2s/ConnectionIn.java | 33 +++++++++++----------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java') diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java index 3220b074..2f007008 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java @@ -21,7 +21,6 @@ import java.util.List; import java.util.UUID; /** - * * @author ugnich */ public class ConnectionIn extends Connection implements Runnable { @@ -43,7 +42,7 @@ public class ConnectionIn extends Connection implements Runnable { @Override public void run() { - LOGGER.info("STREAM FROM ? " + streamID + " START"); + LOGGER.info("STREAM FROM ? {} START", streamID); try { parser.next(); // stream:stream updateTsRemoteData(); @@ -75,7 +74,7 @@ public class ConnectionIn extends Connection implements Runnable { if (tag.equals("result") && parser.getNamespace().equals(NS_DB)) { String dfrom = parser.getAttributeValue(null, "from"); String to = parser.getAttributeValue(null, "to"); - LOGGER.info("STREAM FROM " + dfrom + " TO " + to + " " + streamID + " ASKING FOR DIALBACK"); + LOGGER.info("STREAM FROM {} TO {} {} ASKING FOR DIALBACK", dfrom, to, streamID); if (dfrom.endsWith(xmpp.HOSTNAME) && (dfrom.equals(xmpp.HOSTNAME) || dfrom.endsWith("." + xmpp.HOSTNAME))) { break; } @@ -106,10 +105,10 @@ public class ConnectionIn extends Connection implements Runnable { } if (valid) { sendStanza(""); - LOGGER.info("STREAM FROM " + vfrom + " " + streamID + " DIALBACK VERIFY VALID"); + LOGGER.info("STREAM FROM {} {} DIALBACK VERIFY VALID", vfrom, streamID); } else { sendStanza(""); - LOGGER.warn("STREAM FROM " + vfrom + " " + streamID + " DIALBACK VERIFY INVALID"); + LOGGER.warn("STREAM FROM {} {} DIALBACK VERIFY INVALID", vfrom, streamID); } } else if (tag.equals("presence") && checkFromTo(parser)) { Presence p = Presence.parse(parser, null); @@ -120,7 +119,7 @@ public class ConnectionIn extends Connection implements Runnable { updateTsRemoteData(); Message msg = Message.parse(parser, xmpp.childParsers); if (msg != null && (msg.type == null || !msg.type.equals(Message.Type.error))) { - LOGGER.info("STREAM " + streamID + ": " + msg.toString()); + LOGGER.info("STREAM {}: {}", streamID, msg); if (!bot.incomingMessage(msg)) { xmpp.getRouter().sendStanza(msg.toString()); } @@ -130,11 +129,11 @@ public class ConnectionIn extends Connection implements Runnable { String type = parser.getAttributeValue(null, "type"); String xml = XmlUtils.parseToString(parser, true); if (type == null || !type.equals(Iq.Type.error)) { - LOGGER.info("STREAM " + streamID + ": " + xml); + LOGGER.info("STREAM {}: {}", streamID, xml); xmpp.getRouter().sendStanza(xml); } } else if (sc != null && !isSecured() && tag.equals("starttls")) { - LOGGER.info("STREAM " + streamID + " SECURING"); + LOGGER.info("STREAM {} SECURING", streamID); sendStanza(""); try { socket = sc.getSocketFactory().createSocket(socket, socket.getInetAddress().getHostAddress(), @@ -142,10 +141,10 @@ public class ConnectionIn extends Connection implements Runnable { ((SSLSocket) socket).setUseClientMode(false); ((SSLSocket) socket).startHandshake(); setSecured(true); - LOGGER.info("STREAM " + streamID + " SECURED"); + LOGGER.info("STREAM {} SECURED", streamID); restartParser(); } catch (SSLException sex) { - LOGGER.warn("STREAM " + streamID + " SSL ERROR"); + LOGGER.warn("STREAM {} SSL ERROR {}", streamID, sex); sendStanza(""); xmpp.removeConnectionIn(this); closeConnection(); @@ -153,20 +152,21 @@ public class ConnectionIn extends Connection implements Runnable { } else if (isSecured() && tag.equals("stream") && parser.getNamespace().equals(NS_STREAM)) { sendOpenStream(null, true); } else { - LOGGER.info("STREAM " + streamID + ": " + XmlUtils.parseToString(parser, true)); + if (LOGGER.isInfoEnabled()) // prevent call parseToString if logger disabled + LOGGER.info("STREAM {}: {}", streamID, XmlUtils.parseToString(parser, true)); } } - LOGGER.warn("STREAM " + streamID + " FINISHED"); + LOGGER.warn("STREAM {} FINISHED", streamID); xmpp.removeConnectionIn(this); closeConnection(); } catch (EOFException | SocketException ex) { - LOGGER.info(String.format("STREAM %s CLOSED (dirty)", streamID)); + LOGGER.info("STREAM {} CLOSED (dirty)", streamID); xmpp.removeConnectionIn(this); closeConnection(); } catch (HostUnknownException e) { LOGGER.warn(e.getMessage()); } catch (Exception e) { - LOGGER.warn("STREAM " + streamID + " ERROR", e); + LOGGER.warn("STREAM {} ERROR {}", streamID, e); xmpp.removeConnectionIn(this); closeConnection(); } @@ -195,10 +195,10 @@ public class ConnectionIn extends Connection implements Runnable { sendStanza(""); if (type.equals("valid")) { from.add(sfrom); - LOGGER.info("STREAM FROM " + sfrom + " " + streamID + " READY"); + LOGGER.info("STREAM FROM {} {} READY", sfrom, streamID); } } catch (IOException e) { - LOGGER.warn("STREAM FROM " + sfrom + " " + streamID + " ERROR: " + e.toString()); + LOGGER.warn("STREAM FROM {} {} ERROR: {}", sfrom, streamID, e); } } @@ -219,6 +219,7 @@ public class ConnectionIn extends Connection implements Runnable { } return false; } + class HostUnknownException extends Exception { public HostUnknownException(String message) { super(message); -- cgit v1.2.3