From 2b4b08c7954f5ae03681401b613318cfbfde1c76 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 31 Jul 2016 02:02:32 +0300 Subject: www: do not throw on xmpp errors --- juick-www/src/main/java/com/juick/www/Main.java | 3 +- .../src/main/java/com/juick/www/NewMessage.java | 81 +++++++++++++--------- juick-www/src/main/java/com/juick/www/PM.java | 55 ++++++++------- 3 files changed, 80 insertions(+), 59 deletions(-) (limited to 'juick-www/src/main/java/com/juick/www') diff --git a/juick-www/src/main/java/com/juick/www/Main.java b/juick-www/src/main/java/com/juick/www/Main.java index a08ea73e..e8d53e51 100644 --- a/juick-www/src/main/java/com/juick/www/Main.java +++ b/juick-www/src/main/java/com/juick/www/Main.java @@ -32,6 +32,7 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.net.ConnectException; import java.net.Socket; import java.net.URLEncoder; import java.util.Properties; @@ -99,7 +100,7 @@ public class Main extends HttpServlet implements Stream.StreamListener { xmpp.addListener(Main.this); xmpp.startParsing(); } catch (IOException e) { - log("xmpp exception", e); + log("XMPP is not initialized"); } }); thr.start(); 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 d64fce78..8efec54c 100644 --- a/juick-www/src/main/java/com/juick/www/NewMessage.java +++ b/juick-www/src/main/java/com/juick/www/NewMessage.java @@ -228,31 +228,35 @@ public class NewMessage { xoob.URL = attachmentURL; xmsg.addChild(xoob); } + if (xmpp.isLoggedIn()) { - String tagsStr2 = ""; - for (String tag : tagsArr) { - tagsStr2 += " *" + tag; - } - xmsg.body = "@" + jmsg.getUser().getUName() + ":" + tagsStr2 + "\n" + body + "\n\n#" + mid + " http://juick.com/" + mid; + String tagsStr2 = ""; + for (String tag : tagsArr) { + tagsStr2 += " *" + tag; + } + xmsg.body = "@" + jmsg.getUser().getUName() + ":" + tagsStr2 + "\n" + body + "\n\n#" + mid + " http://juick.com/" + mid; - xmsg.to = new JID("juick", "s2s.juick.com", null); - xmpp.send(xmsg); + xmsg.to = new JID("juick", "s2s.juick.com", null); + xmpp.send(xmsg); - xmsg.to.Host = "ws.juick.com"; - xmpp.send(xmsg); + xmsg.to.Host = "ws.juick.com"; + xmpp.send(xmsg); - xmsg.to.Host = "push.juick.com"; - xmpp.send(xmsg); + xmsg.to.Host = "push.juick.com"; + xmpp.send(xmsg); - xmsg.to.Host = "crosspost.juick.com"; - xmsg.to.Username = "twitter"; - xmpp.send(xmsg); - xmsg.to.Username = "fb"; - xmpp.send(xmsg); + xmsg.to.Host = "crosspost.juick.com"; + xmsg.to.Username = "twitter"; + xmpp.send(xmsg); + xmsg.to.Username = "fb"; + xmpp.send(xmsg); - xmsg.to.Host = "nologin.ru"; - xmsg.to.Username = "jubo"; - xmpp.send(xmsg); + xmsg.to.Host = "nologin.ru"; + xmsg.to.Username = "jubo"; + xmpp.send(xmsg); + } else { + logger.log(Level.WARNING, "XMPP unavailable"); + } // @@ -395,16 +399,21 @@ public class NewMessage { xmsg.addChild(xoob); } - xmsg.body = "Reply by @" + jmsg.getUser().getUName() + ":\n>" + quote + "\n" + body + "\n\n#" + mid + "/" + ridnew + " http://juick.com/" + mid + "#" + ridnew; + if (xmpp.isLoggedIn()) { - xmsg.to = new JID("juick", "s2s.juick.com", null); - xmpp.send(xmsg); + xmsg.body = "Reply by @" + jmsg.getUser().getUName() + ":\n>" + quote + "\n" + body + "\n\n#" + mid + "/" + ridnew + " http://juick.com/" + mid + "#" + ridnew; - xmsg.to.Host = "ws.juick.com"; - xmpp.send(xmsg); + xmsg.to = new JID("juick", "s2s.juick.com", null); + xmpp.send(xmsg); - xmsg.to.Host = "push.juick.com"; - xmpp.send(xmsg); + xmsg.to.Host = "ws.juick.com"; + xmpp.send(xmsg); + + xmsg.to.Host = "push.juick.com"; + xmpp.send(xmsg); + } else { + logger.log(Level.WARNING, "XMPP unavailable"); + } Utils.sendTemporaryRedirect(response, "/" + msg.getUser().getUName() + "/" + mid + "#" + ridnew); } @@ -428,14 +437,18 @@ public class NewMessage { boolean res = MessagesQueries.recommendMessage(sql, mid, visitor.getUID()); if (res) { - Message xmsg = new Message(); - xmsg.from = new JID("juick", "juick.com", null); - xmsg.to = new JID("recomm", "s2s.juick.com", null); - JuickMessage jmsg = new JuickMessage(); - jmsg.setMID(mid); - jmsg.setUser(new JuickUser(visitor)); - xmsg.addChild(jmsg); - xmpp.send(xmsg); + if (xmpp.isLoggedIn()) { + Message xmsg = new Message(); + xmsg.from = new JID("juick", "juick.com", null); + xmsg.to = new JID("recomm", "s2s.juick.com", null); + JuickMessage jmsg = new JuickMessage(); + jmsg.setMID(mid); + jmsg.setUser(new JuickUser(visitor)); + xmsg.addChild(jmsg); + xmpp.send(xmsg); + } else { + logger.log(Level.WARNING, "XMPP unavailable"); + } Utils.replyJSON(request, response, "{\"status\":\"ok\"}"); } else { diff --git a/juick-www/src/main/java/com/juick/www/PM.java b/juick-www/src/main/java/com/juick/www/PM.java index 15d69808..ee1d7140 100644 --- a/juick-www/src/main/java/com/juick/www/PM.java +++ b/juick-www/src/main/java/com/juick/www/PM.java @@ -31,12 +31,15 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; /** * * @author Ugnich Anton */ public class PM { + private static final Logger logger = Logger.getLogger(PM.class.getName()); protected void doGetInbox(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException { /* @@ -188,31 +191,35 @@ public class PM { } if (PMQueries.createPM(sql, visitor.getUID(), uid, body)) { - Message msg = new Message(); - msg.from = new JID("juick", "juick.com", null); - msg.to = new JID(Integer.toString(uid), "push.juick.com", null); - JuickMessage jmsg = new JuickMessage(); - jmsg.setUser(visitor); - jmsg.setText(body); - msg.childs.add(jmsg); - xmpp.send(msg); - - msg.to.Host = "ws.juick.com"; - xmpp.send(msg); - - List jids = UserQueries.getJIDsbyUID(sql, uid); - for (String jid : jids) { - Message mm = new Message(); - mm.to = new JID(jid); - mm.type = Message.Type.chat; - if (PMQueries.havePMinRoster(sql, visitor.getUID(), jid)) { - mm.from = new JID(jmsg.getUser().getUName(), "juick.com", "Juick"); - mm.body = body; - } else { - mm.from = new JID("juick", "juick.com", "Juick"); - mm.body = "Private message from @" + jmsg.getUser().getUName() + ":\n" + body; + if (xmpp.isLoggedIn()) { + Message msg = new Message(); + msg.from = new JID("juick", "juick.com", null); + msg.to = new JID(Integer.toString(uid), "push.juick.com", null); + JuickMessage jmsg = new JuickMessage(); + jmsg.setUser(visitor); + jmsg.setText(body); + msg.childs.add(jmsg); + xmpp.send(msg); + + msg.to.Host = "ws.juick.com"; + xmpp.send(msg); + + List jids = UserQueries.getJIDsbyUID(sql, uid); + for (String jid : jids) { + Message mm = new Message(); + mm.to = new JID(jid); + mm.type = Message.Type.chat; + if (PMQueries.havePMinRoster(sql, visitor.getUID(), jid)) { + mm.from = new JID(jmsg.getUser().getUName(), "juick.com", "Juick"); + mm.body = body; + } else { + mm.from = new JID("juick", "juick.com", "Juick"); + mm.body = "Private message from @" + jmsg.getUser().getUName() + ":\n" + body; + } + xmpp.send(mm); } - xmpp.send(mm); + } else { + logger.log(Level.WARNING, "XMPP unavailable"); } Utils.sendTemporaryRedirect(response, "/pm/sent"); -- cgit v1.2.3