diff options
author | Alexander Alexeev | 2016-11-30 15:10:15 +0700 |
---|---|---|
committer | Alexander Alexeev | 2016-11-30 15:10:15 +0700 |
commit | 1d837a835c04078ec66325e9fb9de21ac401874e (patch) | |
tree | 428217d2c617b9caf2eb6d42a7716789881d0937 | |
parent | b45c000ed478f2407288aab1532425288f998689 (diff) |
prevent string concatenation for disabled loggers
21 files changed, 116 insertions, 105 deletions
diff --git a/juick-api/src/main/java/com/juick/api/TGBot.java b/juick-api/src/main/java/com/juick/api/TGBot.java index e0ab3e1e..d532b02c 100644 --- a/juick-api/src/main/java/com/juick/api/TGBot.java +++ b/juick-api/src/main/java/com/juick/api/TGBot.java @@ -79,7 +79,10 @@ public class TGBot implements AutoCloseable { public void onTextMessage(WebSocket websocket, String text) throws Exception { super.onTextMessage(websocket, text); com.juick.Message jmsg = ms.readValue(text, com.juick.Message.class); - logger.info("got jmsg: " + ms.writeValueAsString(jmsg)); + + if (logger.isInfoEnabled()) // prevent writeValueAsString execution if logger disabled + logger.info("got jmsg: {}", ms.writeValueAsString(jmsg)); + String msgUrl = formatUrl(jmsg); if (jmsg.getRid() == 0) { String msg = formatPost(jmsg); @@ -118,7 +121,7 @@ public class TGBot implements AutoCloseable { bot.execute(telegramMessage, new Callback<SendMessage, SendResponse>() { @Override public void onResponse(SendMessage request, SendResponse response) { - logger.info("got response: " + response.message().toString()); + logger.info("got response: {}", response.message()); } @Override @@ -140,7 +143,7 @@ public class TGBot implements AutoCloseable { })), new Callback<SendMessage, SendResponse>() { @Override public void onResponse(SendMessage request, SendResponse response) { - logger.info("got response: " + response.message().toString()); + logger.info("got response: {}", response.message()); } @Override diff --git a/juick-api/src/main/java/com/juick/api/controllers/Post.java b/juick-api/src/main/java/com/juick/api/controllers/Post.java index 18f417d8..0fbf87e8 100644 --- a/juick-api/src/main/java/com/juick/api/controllers/Post.java +++ b/juick-api/src/main/java/com/juick/api/controllers/Post.java @@ -99,7 +99,7 @@ public class Post { } String attachmentFName = HttpUtils.receiveMultiPartFile(attach, env.getProperty("upload_tmp_dir", - "/var/www/juick.com/i/tmp/")); + "/var/www/juick.com/i/tmp/")); if (StringUtils.isBlank(attachmentFName) && img != null && img.length() > 10) { try { @@ -142,7 +142,7 @@ public class Post { OobX xoob = new OobX(new URI(attachmentURL)); xmsg.addExtension(xoob); } catch (URISyntaxException e) { - logger.error("invalid uri: " + attachmentURL, e); + logger.error("invalid uri: {}, exception {}", attachmentURL, e); } } @@ -173,6 +173,7 @@ public class Post { } return jmsg; } + @RequestMapping(value = "/comment", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public com.juick.Message doPostComment( Principal principal, @@ -263,7 +264,7 @@ public class Post { try { xmsg.addExtension(new OobX(new URI(attachmentURL))); } catch (URISyntaxException e) { - logger.error("invalid uri: " + attachmentURL, e); + logger.error("invalid uri: {}, exception {}", attachmentURL, e); } } diff --git a/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java b/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java index 8b491167..60856ec6 100644 --- a/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java +++ b/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java @@ -38,13 +38,13 @@ public class TelegramWebhook { if (update.message() == null) { message = update.editedMessage(); if (message == null) { - logger.error("error parsing telegram update: " + update.toString()); + logger.error("error parsing telegram update: {}", update); return; } } - logger.info(String.format("got telegram msg %s", message.toString())); + logger.info("got telegram msg {}", message); User user_from = usersService.getUserByUID(telegramService.getUser(message.chat().id())).orElse(new User()); - logger.info(String.format("Found juick user %d", user_from.getUid())); + logger.info("Found juick user {}", user_from.getUid()); List<Long> chats = telegramService.getChats(); String username = message.from().username(); @@ -53,7 +53,7 @@ public class TelegramWebhook { } if (!chats.contains(message.chat().id())) { telegramService.addChat(message.chat().id()); - logger.info("added chat with " + username); + logger.info("added chat with {}", username); telegramService.createTelegramUser(message.from().id(), username); tgBot.telegramSignupNotify(message.from().id().longValue(), usersService.getSignUpHashByTelegramID(message.from().id().longValue(), username)); } else { diff --git a/juick-crosspost/src/main/java/com/juick/components/Crosspost.java b/juick-crosspost/src/main/java/com/juick/components/Crosspost.java index fb6dd7d5..c39898f2 100644 --- a/juick-crosspost/src/main/java/com/juick/components/Crosspost.java +++ b/juick-crosspost/src/main/java/com/juick/components/Crosspost.java @@ -128,7 +128,7 @@ public class Crosspost implements AutoCloseable { return false; } - logger.info("FB: #" + jmsg.getMid()); + logger.info("FB: #{}", jmsg.getMid()); String status = getMessageHashTags(jmsg) + "\n" + jmsg.getText(); @@ -159,7 +159,7 @@ public class Crosspost implements AutoCloseable { conn.disconnect(); } catch (Exception e) { - logger.error("fbPost: " + e.getMessage(), e); + logger.error("fbPost exception", e); } return ret; } @@ -170,7 +170,7 @@ public class Crosspost implements AutoCloseable { return false; } - logger.info("VK: #" + jmsg.getMid()); + logger.info("VK: #", jmsg.getMid()); String status = getMessageHashTags(jmsg) + "\n" + jmsg.getText() + "\nhttp://juick.com/" + jmsg.getMid(); @@ -196,7 +196,7 @@ public class Crosspost implements AutoCloseable { conn.disconnect(); } catch (Exception e) { - logger.error("vkPost: " + e.getMessage(), e); + logger.error("vkPost exception", e); } return ret; } @@ -209,7 +209,7 @@ public class Crosspost implements AutoCloseable { String token = percentEncode(tokens.getLeft()); String token_secret = percentEncode(tokens.getRight()); - logger.info("TWITTER: #" + jmsg.getMid()); + logger.info("TWITTER: #{}", jmsg.getMid()); String status = getMessageHashTags(jmsg) + jmsg.getText(); if (status.length() > 115) { @@ -251,7 +251,7 @@ public class Crosspost implements AutoCloseable { conn.disconnect(); } catch (Exception e) { - logger.error("twitterPost: " + e.getMessage(), e); + logger.error("twitterPost exception", e); } return ret; } @@ -277,7 +277,7 @@ public class Crosspost implements AutoCloseable { return Base64.encodeBase64String(rawHmac); } catch (Exception e) { - logger.error("twitterSignature: " + e.getMessage(), e); + logger.error("twitterSignature exception", e); } return null; } diff --git a/juick-notifications/src/main/java/com/juick/components/CleanUp.java b/juick-notifications/src/main/java/com/juick/components/CleanUp.java index 06d96471..924d6134 100644 --- a/juick-notifications/src/main/java/com/juick/components/CleanUp.java +++ b/juick-notifications/src/main/java/com/juick/components/CleanUp.java @@ -36,7 +36,7 @@ public class CleanUp { Collection<String> devices = apns.getInactiveDevices().keySet(); int count = devices.size(); if (count > 0) { - logger.info(String.format("%d tokens to delete", count)); + logger.info("{} tokens to delete", count); TokensList list = new TokensList(); list.setType("apns"); list.setTokens(new ArrayList<>(devices)); diff --git a/juick-notifications/src/main/java/com/juick/components/Notifications.java b/juick-notifications/src/main/java/com/juick/components/Notifications.java index dac4d22e..f98fdcce 100644 --- a/juick-notifications/src/main/java/com/juick/components/Notifications.java +++ b/juick-notifications/src/main/java/com/juick/components/Notifications.java @@ -133,12 +133,12 @@ public class Notifications implements AutoCloseable { MulticastResult result = GCMSender.send(message, regids, 3); List<Result> results = result.getResults(); for (int i = 0; i < results.size(); i++) { - logger.info("RES " + i + ": " + results.get(i).toString()); + logger.info("RES {}: {}", i, results.get(i)); } } catch (IOException ex) { logger.error(ex.getMessage(), ex); } catch (IllegalArgumentException err) { - logger.warn("Android: Invalid API Key"); + logger.warn("Android: Invalid API Key", err); } } else { logger.info("GMS: no recipients"); @@ -183,7 +183,7 @@ public class Notifications implements AutoCloseable { + "</toast>"; logger.trace(xml); for (String url : urls) { - logger.info("WNS: " + url); + logger.info("WNS: {}", url); sendWNS(wnsToken, url, xml); } } catch (IOException | IllegalStateException ex) { @@ -207,7 +207,7 @@ public class Notifications implements AutoCloseable { if (!tokens.isEmpty()) { for (String token : tokens) { String payload = APNS.newPayload().alertTitle("@" + jmsg.getUser().getName()).alertBody(jmsg.getText()).build(); - logger.info("APNS: " + token); + logger.info("APNS: {}", token); apns.push(token, payload); } } else { diff --git a/juick-server/src/main/java/com/juick/service/security/SimpleRememberMeServices.java b/juick-server/src/main/java/com/juick/service/security/SimpleRememberMeServices.java index 2a28866c..aef133d3 100644 --- a/juick-server/src/main/java/com/juick/service/security/SimpleRememberMeServices.java +++ b/juick-server/src/main/java/com/juick/service/security/SimpleRememberMeServices.java @@ -5,6 +5,8 @@ import com.juick.server.security.entities.JuickUser; import com.juick.service.UserService; import com.juick.util.UserUtils; import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.core.env.Environment; import org.springframework.security.core.Authentication; import org.springframework.security.core.userdetails.UserDetails; @@ -23,6 +25,8 @@ import java.util.Optional; * Created by aalexeev on 11/28/16. */ public class SimpleRememberMeServices extends AbstractRememberMeServices implements RememberMeServices { + private static final Logger logger = LoggerFactory.getLogger(SimpleRememberMeServices.class); + private final UserService userService; public SimpleRememberMeServices( @@ -49,7 +53,7 @@ public class SimpleRememberMeServices extends AbstractRememberMeServices impleme HttpServletRequest request, HttpServletResponse response, Authentication successfulAuthentication) { String username = successfulAuthentication.getName(); - logger.debug("Creating new persistent login for user " + username); + logger.debug("Creating new persistent login for user {}", username); try { int uid = userService.getUIDbyName(username); @@ -62,7 +66,7 @@ public class SimpleRememberMeServices extends AbstractRememberMeServices impleme setCookie(new String[]{hash}, getTokenValiditySeconds(), request, response); } catch (Exception e) { - logger.error("Failed to save cookies ", e); + logger.error("Failed to save cookies", e); } } diff --git a/juick-server/src/main/java/rocks/xmpp/core/session/debug/LogbackDebugger.java b/juick-server/src/main/java/rocks/xmpp/core/session/debug/LogbackDebugger.java index 4b2da8b7..3da660b2 100644 --- a/juick-server/src/main/java/rocks/xmpp/core/session/debug/LogbackDebugger.java +++ b/juick-server/src/main/java/rocks/xmpp/core/session/debug/LogbackDebugger.java @@ -11,22 +11,20 @@ import java.io.OutputStream; * Created by vitalyster on 17.11.2016. */ public class LogbackDebugger implements XmppDebugger { - private static final Logger logger = LoggerFactory.getLogger(LogbackDebugger.class); @Override public void initialize(XmppSession xmppSession) { - } @Override public void writeStanza(String s, Object o) { - logger.info("OUT: " + s); + logger.info("OUT: {}", s); } @Override public void readStanza(String s, Object o) { - logger.info("IN: " + s); + logger.info("IN: {}", s); } @Override diff --git a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java b/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java index 831d16f1..adb39bb2 100644 --- a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java +++ b/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java @@ -52,7 +52,7 @@ public class WebsocketComponent extends TextWebSocketHandler { visitor = userService.getUserByHash(hash); } else { try { - logger.info(String.format("wrong hash for %d from %s", visitor.getUid(), hXRealIP)); + logger.info("wrong hash for {} from {}", visitor.getUid(), hXRealIP); session.close(new CloseStatus(403, "Forbidden")); } catch (IOException e) { logger.warn("ws error", e); @@ -61,19 +61,19 @@ public class WebsocketComponent extends TextWebSocketHandler { break; } } - logger.info(String.format("user %d connected to %s from %s", visitor.getUid(), hLocation.getPath(), hXRealIP)); + logger.info("user {} connected to {} from {}", visitor.getUid(), hLocation.getPath(), hXRealIP); int MID = 0; SocketSubscribed sockSubscr = null; if (hLocation.getPath().equals("/")) { - logger.info(String.format("user %d connected", visitor.getUid())); + logger.info("user {} connected", visitor.getUid()); sockSubscr = new SocketSubscribed(session, hXRealIP, visitor, false); } else if (hLocation.getPath().equals("/_all")) { - logger.info(String.format("user %d connected to legacy _all (%s)", visitor.getUid(), hLocation.getPath())); + logger.info("user {} connected to legacy _all ({})", visitor.getUid(), hLocation.getPath()); sockSubscr = new SocketSubscribed(session, hXRealIP, visitor, true); sockSubscr.allMessages = true; } else if (hLocation.getPath().equals("/_replies")) { - logger.info(String.format("user %d connected to legacy _replies (%s)", visitor.getUid(), hLocation.getPath())); + logger.info("user {} connected to legacy _replies ({})", visitor.getUid(), hLocation.getPath()); sockSubscr = new SocketSubscribed(session, hXRealIP, visitor, true); sockSubscr.allReplies = true; } else if (hLocation.getPath().matches("/\\d+$")) { @@ -83,7 +83,7 @@ public class WebsocketComponent extends TextWebSocketHandler { } if (MID > 0) { if (messagesService.canViewThread(MID, visitor.getUid())) { - logger.info(String.format("user %d connected to legacy thread (%d) from %s", visitor.getUid(), MID, hXRealIP)); + logger.info("user {} connected to legacy thread ({}) from {}", visitor.getUid(), MID, hXRealIP); sockSubscr = new SocketSubscribed(session, hXRealIP, visitor, true); sockSubscr.MID = MID; } else { @@ -98,7 +98,7 @@ public class WebsocketComponent extends TextWebSocketHandler { if (sockSubscr != null) { synchronized (clients) { clients.add(sockSubscr); - logger.info(clients.size() + " clients connected"); + logger.info("{} clients connected", clients.size()); } } } @@ -106,14 +106,14 @@ public class WebsocketComponent extends TextWebSocketHandler { @Override public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception { synchronized (clients) { - logger.info(String.format("session closed with status %d: %s", status.getCode(), status.getReason())); + logger.info("session closed with status {}: {}", status.getCode(), status.getReason()); clients.removeIf(c -> { if (c.session.getId().equals(session.getId())) { return true; } return false; }); - logger.info(clients.size() + " clients connected"); + logger.info("{} clients connected", clients.size()); } } diff --git a/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java b/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java index b75ca998..f535d123 100644 --- a/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java +++ b/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java @@ -68,7 +68,8 @@ public class XMPPConnection implements AutoCloseable { Message msg = e.getMessage(); com.juick.Message jmsg = msg.getExtension(com.juick.Message.class); if (jmsg != null) { - logger.info("got msg: " + ms.writeValueAsString(jmsg)); + if (logger.isInfoEnabled()) // prevent writeValueAsString execution if log is disabled + logger.info("got msg: {}", ms.writeValueAsString(jmsg)); if (jmsg.getMid() == 0) { int uid_to = NumberUtils.toInt(msg.getTo().getLocal(), 0); if (uid_to > 0) { @@ -106,7 +107,7 @@ public class XMPPConnection implements AutoCloseable { synchronized (wsHandler.getClients()) { wsHandler.getClients().stream().filter(c -> !c.legacy && c.visitor.getUid() == uid_to).forEach(c -> { try { - logger.info("sending pm to " + c.visitor.getUid()); + logger.info("sending pm to {}", c.visitor.getUid()); c.session.sendMessage(new TextMessage(json)); } catch (IOException e) { logger.warn("ws error", e); @@ -125,7 +126,7 @@ public class XMPPConnection implements AutoCloseable { || (!c.legacy && uids.contains(c.visitor.getUid()))) // subscriptions .forEach(c -> { try { - logger.info("sending message to " + c.visitor.getUid()); + logger.info("sending message to {}", c.visitor.getUid()); c.session.sendMessage(new TextMessage(json)); } catch (IOException e) { logger.warn("ws error", e); @@ -135,7 +136,7 @@ public class XMPPConnection implements AutoCloseable { c.legacy && c.allMessages) // legacy all posts .forEach(c -> { try { - logger.info("sending message to legacy client " + c.visitor.getUid()); + logger.info("sending message to legacy client {}", c.visitor.getUid()); c.session.sendMessage(new TextMessage(json)); } catch (IOException e) { logger.warn("ws error", e); @@ -155,7 +156,7 @@ public class XMPPConnection implements AutoCloseable { || (!c.legacy && threadUsers.contains(c.visitor.getUid()))) // subscriptions .forEach(c -> { try { - logger.info("sending reply to " + c.visitor.getUid()); + logger.info("sending reply to {}", c.visitor.getUid()); c.session.sendMessage(new TextMessage(json)); } catch (IOException e) { logger.warn("ws error", e); @@ -165,7 +166,7 @@ public class XMPPConnection implements AutoCloseable { (c.legacy && c.allReplies) || (c.legacy && c.MID == jmsg.getMid())) // legacy replies .forEach(c -> { try { - logger.info("sending reply to legacy client " + c.visitor.getUid()); + logger.info("sending reply to legacy client {}", c.visitor.getUid()); c.session.sendMessage(new TextMessage(json)); } catch (IOException e) { logger.warn("ws error", e); diff --git a/juick-www/src/main/java/com/juick/www/FacebookLogin.java b/juick-www/src/main/java/com/juick/www/FacebookLogin.java index 34385a3d..e9c4b786 100644 --- a/juick-www/src/main/java/com/juick/www/FacebookLogin.java +++ b/juick-www/src/main/java/com/juick/www/FacebookLogin.java @@ -85,7 +85,7 @@ public class FacebookLogin { String token = Utils.fetchURL("https://graph.facebook.com/oauth/access_token?client_id=" + FACEBOOK_APPID + "&redirect_uri=" + URLEncoder.encode(FACEBOOK_REDIRECT, "utf-8") + "&client_secret=" + FACEBOOK_SECRET + "&code=" + URLEncoder.encode(code, "utf-8")); if (token == null || token.isEmpty() || !token.startsWith("access_token=")) { - logger.error("FACEBOOK TOKEN ERROR: " + token); + logger.error("FACEBOOK TOKEN ERROR: {}", token); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } diff --git a/juick-www/src/main/java/com/juick/www/NewMessage.java b/juick-www/src/main/java/com/juick/www/NewMessage.java index f6e8ec47..c066c5b3 100644 --- a/juick-www/src/main/java/com/juick/www/NewMessage.java +++ b/juick-www/src/main/java/com/juick/www/NewMessage.java @@ -48,7 +48,6 @@ import java.util.ArrayList; import java.util.List; /** - * * @author Ugnich Anton */ public class NewMessage { @@ -185,7 +184,7 @@ public class NewMessage { } String paramImg = request.getParameter("img"); - if (attachmentFName == null && paramImg != null && paramImg.length() > 10 ) { + if (attachmentFName == null && paramImg != null && paramImg.length() > 10) { try { URL imgUrl = new URL(paramImg); attachmentFName = Utils.downloadImage(imgUrl); @@ -225,7 +224,7 @@ public class NewMessage { try { xmsg.addExtension(new OobX(new URI(attachmentURL))); } catch (URISyntaxException e) { - logger.warn("invalid uri: " + attachmentURL, e); + logger.warn("invalid uri: {} exception {}", attachmentURL, e); } } if (xmpp != null) { @@ -296,8 +295,8 @@ public class NewMessage { out.println("<p class=\"social\"><a href=\"https://plus.google.com/share?url=" + url + "\" class=\"ico32-gp sharenew\">Отправить в Google+</a></p>"); out.println("<p>Ссылка на сообщение: <a href=\"http://juick.com/" + mid + "\">http://juick.com/" + mid + "</a></p>"); out.println("</section>"); - - PageTemplates.pageHomeColumn(out, sql, visitor); + + PageTemplates.pageHomeColumn(out, sql, visitor); PageTemplates.pageFooter(request, out, visitor, false); PageTemplates.pageEnd(out); @@ -393,7 +392,7 @@ public class NewMessage { try { xmsg.addExtension(new OobX(new URI(attachmentURL))); } catch (URISyntaxException e) { - logger.warn("invalid uri: " + attachmentURL, e); + logger.warn("invalid uri: {}, exception {}", attachmentURL, e); } } diff --git a/juick-www/src/main/java/com/juick/www/PageTemplates.java b/juick-www/src/main/java/com/juick/www/PageTemplates.java index f0974e69..74b8b543 100644 --- a/juick-www/src/main/java/com/juick/www/PageTemplates.java +++ b/juick-www/src/main/java/com/juick/www/PageTemplates.java @@ -42,7 +42,6 @@ import java.util.List; import java.util.stream.Collectors; /** - * * @author Ugnich Anton */ public class PageTemplates { @@ -254,7 +253,7 @@ public class PageTemplates { ret = sdfFull.format(fulldate); } } catch (Exception e) { - logger.error("PARSE EXCEPTION: " + fulldate); + logger.error("PARSE EXCEPTION: {}, exception {}", fulldate, e); } } return ret; @@ -263,9 +262,9 @@ public class PageTemplates { public static String formatJSLocalTime(Date ts) { return "<script type=\"text/javascript\">" - + "var d=new Date(" + ts.getTime() + ");" - + "document.write((d.getDate()<10?'0':'')+d.getDate()+'.'+(d.getMonth()<9?'0':'')+(d.getMonth()+1)+'.'+d.getFullYear()+' '+(d.getHours()<10?'0':'')+d.getHours()+':'+(d.getMinutes()<10?'0':'')+d.getMinutes());" - + "</script>"; + + "var d=new Date(" + ts.getTime() + ");" + + "document.write((d.getDate()<10?'0':'')+d.getDate()+'.'+(d.getMonth()<9?'0':'')+(d.getMonth()+1)+'.'+d.getFullYear()+' '+(d.getHours()<10?'0':'')+d.getHours()+':'+(d.getMinutes()<10?'0':'')+d.getMinutes());" + + "</script>"; } public static String formatReplies(int replies) { @@ -326,10 +325,10 @@ public class PageTemplates { out.println(" @<a href=\"/" + msg.getUser().getName() + "/\">" + msg.getUser().getName() + "</a>:"); out.println(" <div class=\"msg-avatar\"><a href=\"/" + msg.getUser().getName() + "/\"><img src=\"//i.juick.com/a/" + msg.getUser().getUid() + ".png\" alt=\"" + msg.getUser().getName() + "\"/></a></div>"); out.println(" <div class=\"msg-ts\"><a href=\"/" + msg.getUser().getName() + "/" + msg.getMid() + "\"><time datetime=\"" + sdfSQL.format(msg.getDate()) + "Z\" title=\"" + sdfSQL.format(msg.getDate()) + " GMT\">" + formatDate(msg.TimeAgo, msg.getDate()) + "</time></a></div>"); - + out.println(" <div class=\"msg-tags\">" + tagsStr + "</div>"); out.println(" </header>"); - + if (msg.AttachmentType != null) { String fname = msg.getMid() + "." + msg.AttachmentType; out.println(" <p class=\"ir\"><a href=\"//i.juick.com/photos-512/" + fname + "\" data-fname=\"" + fname + "\"><img src=\"//i.juick.com/photos-512/" + fname + "\" alt=\"\"/></a></p>"); @@ -346,7 +345,7 @@ public class PageTemplates { out.print("<a href=\"/post?body=!+%23" + msg.getMid() + "\" class=\"a-like\">Мне нравится</a>"); } if (visitor.getUid() == 0 && !msg.ReadOnly) { - out.print("<a href=\"/"+ msg.getMid() + "\" class=\"a-login\">Комментировать</a> "); + out.print("<a href=\"/" + msg.getMid() + "\" class=\"a-login\">Комментировать</a> "); } else if (visitor.getUid() > 0 && (!msg.ReadOnly || visitor.getUid() == msg.getUser().getUid())) { out.print("<a class=\"a-comment\" href=\"/" + msg.getMid() + "\">Комментировать</a> "); } diff --git a/juick-www/src/main/java/com/juick/www/VKontakteLogin.java b/juick-www/src/main/java/com/juick/www/VKontakteLogin.java index 55dfd202..6b1d4571 100644 --- a/juick-www/src/main/java/com/juick/www/VKontakteLogin.java +++ b/juick-www/src/main/java/com/juick/www/VKontakteLogin.java @@ -20,7 +20,8 @@ package com.juick.www; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; import com.juick.server.UserQueries; -import com.juick.www.vk.*; +import com.juick.www.vk.Token; +import com.juick.www.vk.UsersResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.dao.EmptyResultDataAccessException; @@ -35,7 +36,6 @@ import java.net.URLEncoder; import java.util.UUID; /** - * * @author Ugnich Anton */ public class VKontakteLogin { @@ -50,6 +50,7 @@ public class VKontakteLogin { mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT); } + private final ObjectMapper mapper; protected void doGet(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -73,13 +74,11 @@ public class VKontakteLogin { token = json.getAccessToken(); vkID = json.getUserId(); if (token == null || vkID == 0) { - logger.error("VK TOKEN EMPTY: " + tokenjson); + logger.error("VK TOKEN EMPTY: {}", tokenjson); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } - - String graph = Utils.fetchURL("https://api.vk.com/method/users.get?uids=" + vkID + "&fields=screen_name&access_token=" + token); if (graph == null || graph.isEmpty()) { logger.error("VK GRAPH ERROR"); diff --git a/juick-www/src/main/java/ru/sape/SapeConnection.java b/juick-www/src/main/java/ru/sape/SapeConnection.java index 5c2e3397..a15658fa 100644 --- a/juick-www/src/main/java/ru/sape/SapeConnection.java +++ b/juick-www/src/main/java/ru/sape/SapeConnection.java @@ -81,7 +81,7 @@ public class SapeConnection { } if (data.startsWith("FATAL ERROR:")) { - logger.error("Sape responded with error: " + data); + logger.error("Sape responded with error: {}", data); continue; } diff --git a/juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java b/juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java index d411179c..7da2099e 100644 --- a/juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java +++ b/juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java @@ -40,7 +40,10 @@ public class XMPPFTServer implements AutoCloseable { FileTransferManager fileTransferManager = component.getManager(FileTransferManager.class); fileTransferManager.addFileTransferOfferListener(e -> { try { - List<String> allowedTypes = new ArrayList<String>() {{ add("png"); add("jpg"); }}; + List<String> allowedTypes = new ArrayList<String>() {{ + add("png"); + add("jpg"); + }}; String attachmentExtension = FilenameUtils.getExtension(e.getName()).toLowerCase(); String targetFilename = String.format("%s.%s", DigestUtils.md5Hex(String.format("%s-%s", @@ -49,7 +52,7 @@ public class XMPPFTServer implements AutoCloseable { Path filePath = Paths.get(tmpDir, targetFilename); FileTransfer ft = e.accept(filePath).get(); ft.addFileTransferStatusListener(st -> { - logger.debug(String.format("%s: received %d of %d", e.getName(), st.getBytesTransferred(), e.getSize())); + logger.debug("{}: received {} of {}", e.getName(), st.getBytesTransferred(), e.getSize()); if (ft.isDone()) { logger.info("transfer completed"); Message msg = new Message(); diff --git a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java index a2f593ee..7be2400a 100644 --- a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java +++ b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java @@ -202,7 +202,8 @@ public class XMPPServer implements AutoCloseable { try { connOut.sendStanza(xml); } catch (IOException e) { - logger.warn("STREAM TO " + connOut.to + " " + connOut.streamID + " ERROR: " + e.toString()); + logger.warn("STREAM TO {} {} ERROR: {}", + connOut.to, connOut.streamID, e); } return; } diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java b/juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java index 700293df..4a39ffb5 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java @@ -87,7 +87,7 @@ public class Connection { public void sendStanza(String xml) throws IOException { if (streamID != null) { - logger.trace("OUT: " + xml + "\n"); + logger.trace("OUT: {}\n", xml); } writer.write(xml); writer.flush(); @@ -98,7 +98,7 @@ public class Connection { public void closeConnection() { if (streamID != null) { - logger.info(String.format("CLOSING STREAM %s", streamID)); + logger.info("CLOSING STREAM {}", streamID); } try { 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("<db:verify from='" + vto + "' to='" + vfrom + "' id='" + vid + "' type='valid'/>"); - LOGGER.info("STREAM FROM " + vfrom + " " + streamID + " DIALBACK VERIFY VALID"); + LOGGER.info("STREAM FROM {} {} DIALBACK VERIFY VALID", vfrom, streamID); } else { sendStanza("<db:verify from='" + vto + "' to='" + vfrom + "' id='" + vid + "' type='invalid'/>"); - 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("<proceed xmlns=\"" + NS_TLS + "\" />"); 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("<failed xmlns\"" + NS_TLS + "\" />"); 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("<db:result from='" + xmpp.HOSTNAME + "' to='" + sfrom + "' type='" + type + "'/>"); 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); diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java index c15a2a25..5b1da316 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java @@ -58,7 +58,7 @@ public class ConnectionOut extends Connection implements Runnable { @Override public void run() { - logger.info("STREAM TO " + to + " START"); + logger.info("STREAM TO {} START", to); try { socket = new Socket(); socket.connect(DNSQueries.getServerAddress(to)); @@ -72,7 +72,7 @@ public class ConnectionOut extends Connection implements Runnable { throw new Exception("STREAM TO " + to + " INVALID FIRST PACKET"); } - logger.info("STREAM TO " + to + " " + streamID + " OPEN"); + logger.info("STREAM TO {} {} OPEN", to, streamID); xmpp.addConnectionOut(ConnectionOut.this); boolean xmppversionnew = parser.getAttributeValue(null, "version") != null; if (!xmppversionnew) { @@ -90,16 +90,16 @@ public class ConnectionOut extends Connection implements Runnable { String type = parser.getAttributeValue(null, "type"); if (type != null && type.equals("valid")) { streamReady = true; - logger.info("STREAM TO " + to + " " + streamID + " READY"); + logger.info("STREAM TO {} {} READY", to, streamID); String cache = xmpp.getFromCache(to); if (cache != null) { - logger.info("STREAM TO " + to + " " + streamID + " SENDING CACHE"); + logger.info("STREAM TO {} {} SENDING CACHE", to, streamID); sendStanza(cache); } } else { - logger.info("STREAM TO " + to + " " + streamID + " DIALBACK FAIL"); + logger.info("STREAM TO {} {} DIALBACK FAIL", to, streamID); } XmlUtils.skip(parser); } else if (tag.equals("verify") && parser.getNamespace().equals(NS_DB)) { @@ -116,7 +116,7 @@ public class ConnectionOut extends Connection implements Runnable { } else if (tag.equals("features") && parser.getNamespace().equals(NS_STREAM)) { StreamFeatures features = StreamFeatures.parse(parser); if (sc != null && !isSecured() && features.STARTTLS >= 0 && !xmpp.brokenSSLhosts.contains(to)) { - logger.info("STREAM TO " + to + " " + streamID + " SECURING"); + logger.info("STREAM TO {} {} SECURING", to, streamID); sendStanza("<starttls xmlns=\"" + NS_TLS + "\" />"); } else { processDialback(); @@ -127,11 +127,11 @@ public class ConnectionOut extends Connection implements Runnable { socket.getPort(), true); ((SSLSocket) socket).startHandshake(); setSecured(true); - logger.info("STREAM " + streamID + " SECURED"); + logger.info("STREAM {} SECURED", streamID); restartParser(); sendOpenStream(); } catch (SSLException sex) { - logger.error(String.format("s2s ssl error: %s %s", to, streamID), sex); + logger.error("s2s ssl error: {} {}, error {}", to, streamID, sex); sendStanza("<failed xmlns\"" + NS_TLS + "\" />"); xmpp.removeConnectionOut(this); closeConnection(); @@ -139,19 +139,20 @@ public class ConnectionOut extends Connection implements Runnable { } else if (isSecured() && tag.equals("stream") && parser.getNamespace().equals(NS_STREAM)) { streamID = parser.getAttributeValue(null, "id"); } else { - logger.info("STREAM TO " + to + " " + streamID + ": " + XmlUtils.parseToString(parser, true)); + if (logger.isInfoEnabled()) // prevent parseToString call if logger disabled + logger.info("STREAM TO {} {} : {}", to, streamID, XmlUtils.parseToString(parser, true)); } } - logger.warn("STREAM TO " + to + " " + streamID + " FINISHED"); + logger.warn("STREAM TO {} {} FINISHED", to, streamID); xmpp.removeConnectionOut(ConnectionOut.this); closeConnection(); } catch (EOFException | SocketException eofex) { - logger.info(String.format("STREAM %s %s CLOSED (dirty)", to, streamID)); + logger.info("STREAM {} {} CLOSED (dirty)", to, streamID); xmpp.removeConnectionOut(ConnectionOut.this); closeConnection(); } catch (Exception e) { - logger.error(String.format("s2s out exception: %s %s", to, streamID), e); + logger.error("s2s out exception: {} {}, exception {}", to, streamID, e); xmpp.removeConnectionOut(ConnectionOut.this); closeConnection(); } @@ -161,7 +162,7 @@ public class ConnectionOut extends Connection implements Runnable { try { sendStanza("<db:verify from='" + xmpp.HOSTNAME + "' to='" + to + "' id='" + sid + "'>" + key + "</db:verify>"); } catch (IOException e) { - logger.warn("STREAM TO " + to + " " + streamID + " ERROR", e); + logger.warn("STREAM TO {} {} ERROR {}", to, streamID, e); } } } diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java index 5af00329..9272a3d0 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java @@ -30,7 +30,6 @@ import java.util.List; import java.util.concurrent.TimeUnit; /** - * * @author ugnich */ public class ConnectionRouter extends Connection implements Runnable { @@ -100,7 +99,7 @@ public class ConnectionRouter extends Connection implements Runnable { if (jid.Host.equals(componentName)) { if (tag.equals("message")) { Message xmsg = Message.parse(parser, xmpp.childParsers); - logger.info("STREAM ROUTER (PROCESS): " + xmsg.toString()); + logger.info("STREAM ROUTER (PROCESS): {}", xmsg); JuickMessage jmsg = (JuickMessage) xmsg.getChild(JuickMessage.XMLNS); if (jmsg != null) { if (jid.Username != null && jid.Username.equals("recomm")) { @@ -116,23 +115,25 @@ public class ConnectionRouter extends Connection implements Runnable { } } else if (jid.Host.endsWith(xmpp.HOSTNAME) && (jid.Host.equals(xmpp.HOSTNAME) || jid.Host.endsWith("." + xmpp.HOSTNAME))) { String xml = XmlUtils.parseToString(parser, true); - logger.info("STREAM ROUTER: " + xml); + logger.info("STREAM ROUTER: {}", xml); } else { String xml = XmlUtils.parseToString(parser, true); - logger.info("STREAM ROUTER (OUT): " + xml); + logger.info("STREAM ROUTER (OUT): {}", xml); xmpp.sendOut(jid.Host, xml); } } else { - logger.info("STREAM ROUTER (NO TO): " + XmlUtils.parseToString(parser, true)); + if (logger.isInfoEnabled()) // prevent parseToString for disabled logs + logger.info("STREAM ROUTER (NO TO): {}", XmlUtils.parseToString(parser, true)); } } else { - logger.info("STREAM ROUTER: " + XmlUtils.parseToString(parser, true)); + if (logger.isInfoEnabled()) // prevent parseToString for disabled logs + logger.info("STREAM ROUTER: {}", XmlUtils.parseToString(parser, true)); } } logger.warn("STREAM ROUTER FINISHED"); } catch (Exception e) { - logger.warn("router error, reconnection " + e.toString()); + logger.warn("router error, reconnection ", e); execution.recordFailure(e); } } |