From 53fb0b3e0e790df007a198deef21c115ed236b3e Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Mon, 27 Jun 2016 10:33:52 +0300
Subject: merge with spring-jdbc
---
src/main/java/com/juick/PushComponent.java | 2 +-
src/main/java/com/juick/http/www/Discover.java | 4 +-
src/main/java/com/juick/http/www/Errors.java | 14 +-
.../java/com/juick/http/www/FacebookLogin.java | 80 +++------
src/main/java/com/juick/http/www/Help.java | 18 +-
src/main/java/com/juick/http/www/Home.java | 4 +-
src/main/java/com/juick/http/www/Login.java | 29 +--
src/main/java/com/juick/http/www/Main.java | 73 ++------
src/main/java/com/juick/http/www/NewMessage.java | 34 ++--
src/main/java/com/juick/http/www/PM.java | 20 +--
.../java/com/juick/http/www/PageTemplates.java | 75 ++------
src/main/java/com/juick/http/www/RSS.java | 24 +--
src/main/java/com/juick/http/www/Settings.java | 22 +--
src/main/java/com/juick/http/www/SignUp.java | 197 +++++----------------
src/main/java/com/juick/http/www/TwitterAuth.java | 3 +-
src/main/java/com/juick/http/www/User.java | 27 ++-
src/main/java/com/juick/http/www/Utils.java | 4 +-
.../java/com/juick/http/www/VKontakteLogin.java | 59 ++----
18 files changed, 188 insertions(+), 501 deletions(-)
(limited to 'src/main')
diff --git a/src/main/java/com/juick/PushComponent.java b/src/main/java/com/juick/PushComponent.java
index 386448f4..0cb8e626 100644
--- a/src/main/java/com/juick/PushComponent.java
+++ b/src/main/java/com/juick/PushComponent.java
@@ -157,7 +157,7 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
}
@Override
- public void onStreamFail(Exception e) {logger.log(Level.SEVERE, "XMPP STREAM FAIL", e);}
+ public void onStreamFail(String e) {logger.log(Level.SEVERE, "XMPP STREAM FAIL", e);}
@Override
public void onMessage(com.juick.xmpp.Message msg) {
diff --git a/src/main/java/com/juick/http/www/Discover.java b/src/main/java/com/juick/http/www/Discover.java
index e7d85d8a..bdb86380 100644
--- a/src/main/java/com/juick/http/www/Discover.java
+++ b/src/main/java/com/juick/http/www/Discover.java
@@ -20,6 +20,8 @@ package com.juick.http.www;
import com.juick.server.AdsQueries;
import com.juick.server.MessagesQueries;
import com.juick.server.TagQueries;
+import org.springframework.jdbc.core.JdbcTemplate;
+
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;
@@ -37,7 +39,7 @@ import javax.servlet.http.HttpServletResponse;
*/
public class Discover {
- protected void doGet(Connection sql, Connection sqlSearch, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doGet(JdbcTemplate sql, JdbcTemplate sqlSearch, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
String paramTagStr = URLDecoder.decode(request.getRequestURI().substring(5), "UTF-8");
diff --git a/src/main/java/com/juick/http/www/Errors.java b/src/main/java/com/juick/http/www/Errors.java
index f65b6201..2161daf1 100644
--- a/src/main/java/com/juick/http/www/Errors.java
+++ b/src/main/java/com/juick/http/www/Errors.java
@@ -1,11 +1,12 @@
package com.juick.http.www;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.sql.Connection;
+import org.springframework.jdbc.core.JdbcTemplate;
+
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
/**
*
@@ -15,7 +16,7 @@ public class Errors {
public static String tagsHTML = null;
- public static void doGet404(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ public static void doGet404(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (tagsHTML == null) {
@@ -24,8 +25,7 @@ public class Errors {
response.setStatus(404);
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
PageTemplates.pageHead(out, "404 Страница не найдена", null);
PageTemplates.pageNavigation(out, visitor, null);
PageTemplates.pageHomeColumn(out, sql, visitor);
@@ -37,8 +37,6 @@ public class Errors {
PageTemplates.pageFooter(request, out, visitor, false);
PageTemplates.pageEnd(out);
- } finally {
- out.close();
}
}
}
diff --git a/src/main/java/com/juick/http/www/FacebookLogin.java b/src/main/java/com/juick/http/www/FacebookLogin.java
index fcb08d6c..cf444abc 100644
--- a/src/main/java/com/juick/http/www/FacebookLogin.java
+++ b/src/main/java/com/juick/http/www/FacebookLogin.java
@@ -18,20 +18,19 @@
package com.juick.http.www;
import com.juick.server.UserQueries;
+import org.json.JSONObject;
+import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.servlet.ServletException;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.json.JSONObject;
/**
*
@@ -45,7 +44,7 @@ public class FacebookLogin {
private static final String FACEBOOK_SECRET = "95813bfb6ab8f473410c50d4f971649e";
private static final String FACEBOOK_REDIRECT = "http://juick.com/_fblogin";
- protected void doGet(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doGet(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String fbstate;
String code = request.getParameter("code");
@@ -132,61 +131,22 @@ public class FacebookLogin {
}
}
- private int getUIDbyFBID(Connection sql, long fbID) {
- int uid = 0;
- PreparedStatement stmt = null;
- ResultSet rs = null;
+ private int getUIDbyFBID(JdbcTemplate sql, long fbID) {
try {
- stmt = sql.prepareStatement("SELECT user_id FROM facebook WHERE fb_id=? AND user_id IS NOT NULL");
- stmt.setLong(1, fbID);
- rs = stmt.executeQuery();
- if (rs.first()) {
- uid = rs.getInt(1);
- }
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(rs, stmt);
+ return sql.queryForObject("SELECT user_id FROM facebook WHERE fb_id=? AND user_id IS NOT NULL",
+ Integer.class, fbID);
+ } catch (EmptyResultDataAccessException e) {
+ return 0;
}
- return uid;
}
- private boolean insertDB(Connection sql, long fbID, String loginhash, String token, String fbName, String fbLink) {
- boolean ret = false;
- PreparedStatement stmt = null;
- try {
- stmt = sql.prepareStatement("INSERT INTO facebook(fb_id,loginhash,access_token,fb_name,fb_link) VALUES (?,?,?,?,?)");
- stmt.setLong(1, fbID);
- stmt.setString(2, loginhash);
- stmt.setString(3, token);
- stmt.setString(4, fbName);
- stmt.setString(5, fbLink);
- stmt.executeUpdate();
- ret = true;
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(null, stmt);
- }
- return ret;
+ private boolean insertDB(JdbcTemplate sql, long fbID, String loginhash, String token, String fbName, String fbLink) {
+ return sql.update("INSERT INTO facebook(fb_id,loginhash,access_token,fb_name,fb_link) VALUES (?,?,?,?,?)",
+ fbID, loginhash, token, fbName, fbLink) > 0;
}
- private boolean updateDB(Connection sql, long fbID, String token, String fbName, String fbLink) {
- boolean ret = false;
- PreparedStatement stmt = null;
- try {
- stmt = sql.prepareStatement("UPDATE facebook SET access_token=?,fb_name=?,fb_link=? WHERE fb_id=?");
- stmt.setString(1, token);
- stmt.setString(2, fbName);
- stmt.setString(3, fbLink);
- stmt.setLong(4, fbID);
- stmt.executeUpdate();
- ret = true;
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(null, stmt);
- }
- return ret;
+ private boolean updateDB(JdbcTemplate sql, long fbID, String token, String fbName, String fbLink) {
+ return sql.update("UPDATE facebook SET access_token=?,fb_name=?,fb_link=? WHERE fb_id=?",
+ token, fbName, fbLink, fbID) > 0;
}
}
diff --git a/src/main/java/com/juick/http/www/Help.java b/src/main/java/com/juick/http/www/Help.java
index 438fc3a9..503044e6 100644
--- a/src/main/java/com/juick/http/www/Help.java
+++ b/src/main/java/com/juick/http/www/Help.java
@@ -17,15 +17,12 @@
*/
package com.juick.http.www;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.sql.Connection;
+import org.springframework.jdbc.core.JdbcTemplate;
+
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.io.*;
/**
*
@@ -33,11 +30,11 @@ import javax.servlet.http.HttpServletResponse;
*/
public class Help {
- protected void doRedirectToHelpIndex(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doRedirectToHelpIndex(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Utils.sendTemporaryRedirect(response, "/help/ru/");
}
- protected void doGetHelp(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doGetHelp(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
String path[] = request.getRequestURI().split("/");
@@ -64,8 +61,7 @@ public class Help {
}
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
PageTemplates.pageHead(out, "Помощь", null);
PageTemplates.pageNavigation(out, visitor, null);
@@ -81,8 +77,6 @@ public class Help {
PageTemplates.pageFooter(request, out, visitor, false);
PageTemplates.pageEnd(out);
- } finally {
- out.close();
}
}
diff --git a/src/main/java/com/juick/http/www/Home.java b/src/main/java/com/juick/http/www/Home.java
index 8dc3e70c..89d4005f 100644
--- a/src/main/java/com/juick/http/www/Home.java
+++ b/src/main/java/com/juick/http/www/Home.java
@@ -19,6 +19,8 @@ package com.juick.http.www;
import com.juick.server.AdsQueries;
import com.juick.server.MessagesQueries;
+import org.springframework.jdbc.core.JdbcTemplate;
+
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLEncoder;
@@ -35,7 +37,7 @@ import javax.servlet.http.HttpServletResponse;
*/
public class Home {
- protected void doGet(Connection sql, Connection sqlSearch, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException {
+ protected void doGet(JdbcTemplate sql, JdbcTemplate sqlSearch, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException {
int paramBefore = 0;
String paramBeforeStr = request.getParameter("before");
if (paramBeforeStr != null) {
diff --git a/src/main/java/com/juick/http/www/Login.java b/src/main/java/com/juick/http/www/Login.java
index 3e9c5e09..f12c7096 100644
--- a/src/main/java/com/juick/http/www/Login.java
+++ b/src/main/java/com/juick/http/www/Login.java
@@ -17,11 +17,10 @@
*/
package com.juick.http.www;
+import org.springframework.jdbc.core.JdbcTemplate;
+
import java.io.IOException;
import java.io.PrintWriter;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
@@ -33,7 +32,7 @@ import javax.servlet.http.HttpServletResponse;
*/
public class Login {
- protected void doGetLoginForm(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doGetLoginForm(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (visitor != null) {
Utils.sendTemporaryRedirect(response, "/");
@@ -41,8 +40,7 @@ public class Login {
}
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
out.println("");
out.println("");
out.println("
");
@@ -182,12 +180,10 @@ public class Login {
out.println("");
out.println("");
- } finally {
- out.close();
}
}
- protected void doGetLogin(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doGetLogin(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String hash = request.getQueryString();
if (hash.length() > 32) {
response.sendError(400);
@@ -204,7 +200,7 @@ public class Login {
}
}
- protected void doPostLogin(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doPostLogin(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
if (username == null || password == null || username.length() > 32 || password.isEmpty()) {
@@ -230,19 +226,10 @@ public class Login {
}
}
- protected void doGetLogout(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doGetLogout(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (visitor != null) {
- PreparedStatement stmt = null;
- try {
- stmt = sql.prepareStatement("DELETE FROM logins WHERE user_id=?");
- stmt.setInt(1, visitor.getUID());
- stmt.executeUpdate();
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(null, stmt);
- }
+ sql.update("DELETE FROM logins WHERE user_id=?", visitor.getUID());
}
Cookie c = new Cookie("hash", "-");
diff --git a/src/main/java/com/juick/http/www/Main.java b/src/main/java/com/juick/http/www/Main.java
index 7896c207..604ccf9a 100644
--- a/src/main/java/com/juick/http/www/Main.java
+++ b/src/main/java/com/juick/http/www/Main.java
@@ -21,6 +21,8 @@ import com.juick.server.UserQueries;
import com.juick.xmpp.JID;
import com.juick.xmpp.Stream;
import com.juick.xmpp.StreamComponent;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.datasource.DriverManagerDataSource;
import ru.sape.Sape;
import javax.servlet.ServletException;
@@ -32,9 +34,6 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.Socket;
import java.net.URLEncoder;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
import java.util.Properties;
/**
@@ -45,8 +44,8 @@ import java.util.Properties;
@MultipartConfig(fileSizeThreshold = 1024 * 1024, maxRequestSize = 1024 * 1024 * 10)
public class Main extends HttpServlet implements Stream.StreamListener {
- Connection sql;
- Connection sqlSearch;
+ JdbcTemplate sql;
+ JdbcTemplate sqlSearch;
String sqlSearchConnStr = "jdbc:mysql://127.0.0.1:9306?autoReconnect=true&useUnicode=yes&characterEncoding=utf8&maxAllowedPacket=512000";
Stream xmpp;
Home home = new Home();
@@ -72,9 +71,14 @@ public class Main extends HttpServlet implements Stream.StreamListener {
Properties conf = new Properties();
conf.load(getServletContext().getResourceAsStream("/WEB-INF/juick.conf"));
- Class.forName("com.mysql.jdbc.Driver");
- sql = DriverManager.getConnection("jdbc:mysql://localhost/juick?autoReconnect=true&user=" + conf.getProperty("mysql_username", "") + "&password=" + conf.getProperty("mysql_password", ""));
- sqlSearch = null; // init this on search, timeout is too low
+ DriverManagerDataSource dataSource = new DriverManagerDataSource();
+ dataSource.setDriverClassName(conf.getProperty("datasource_driver", "com.mysql.jdbc.Driver"));
+ dataSource.setUrl(conf.getProperty("datasource_url"));
+ DriverManagerDataSource dataSourceSearch = new DriverManagerDataSource();
+ dataSourceSearch.setDriverClassName(conf.getProperty("datasource_driver", "com.mysql.jdbc.Driver"));
+ dataSourceSearch.setUrl(sqlSearchConnStr);
+ sql = new JdbcTemplate(dataSource);
+ sqlSearch = new JdbcTemplate(dataSourceSearch);
setupXmppComponent(conf.getProperty("xmpp_password"));
twitterAuth = new TwitterAuth(conf.getProperty("twitter_consumer_key"),
@@ -84,27 +88,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
log(null, e);
}
}
- public void closeSqlSearch() {
- if (sqlSearch != null) {
- try {
- sqlSearch.close();
- sqlSearch = null;
- } catch (SQLException e) {
- log("An error on closing sql search connection", e);
- }
- }
- };
- public Connection getSqlSearch() {
- if (sqlSearch == null) {
- try {
- sqlSearch = DriverManager.getConnection(sqlSearchConnStr, "", "");
- }
- catch (Exception e) {
- log("Couldn't open sqlSearch connection",e);
- }
- }
- return sqlSearch;
- }
+
public void setupXmppComponent(final String password) {
Thread thr = new Thread(() -> {
try {
@@ -120,33 +104,13 @@ public class Main extends HttpServlet implements Stream.StreamListener {
}
@Override
- public void onStreamFail(Exception e) {log("XMPP STREAM FAIL", e);}
+ public void onStreamFail(String e) {log("XMPP STREAM FAIL:" + e);}
@Override
public void onStreamReady() {
log("XMPP STREAM READY");
}
- @Override
- public void destroy() {
- super.destroy();
- if (sql != null) {
- try {
- sql.close();
- sql = null;
- } catch (SQLException e) {
- log(null, e);
- }
- }
- if (sqlSearch != null) {
- try {
- sqlSearch.close();
- sqlSearch = null;
- } catch (SQLException e) {
- log(null, e);
- }
- }
- }
/**
* Handles the HTTP GET
method.
@@ -168,8 +132,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
Utils.sendPermanentRedirect(response, "/tag/" + URLEncoder.encode(tag, "UTF-8"));
} else {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
- home.doGet(sql, getSqlSearch(), request, response, visitor);
- closeSqlSearch();
+ home.doGet(sql, sqlSearch, request, response, visitor);
}
} else if (uri.equals("/post")) {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
@@ -226,8 +189,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
} else if (uri.startsWith("/help/")) {
help.doGetHelp(sql, request, response);
} else if (uri.startsWith("/tag/")) {
- discover.doGet(sql, getSqlSearch(), request, response);
- closeSqlSearch();
+ discover.doGet(sql, sqlSearch, request, response);
} else if (uri.matches("^/\\d+$")) {
String strID = request.getRequestURI().substring(1);
int mid = 0;
@@ -255,8 +217,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
com.juick.User user = com.juick.server.UserQueries.getUserByName(sql, uriparts[1]);
if (user != null && user.getUName().equals(uriparts[1]) && !user.Banned) {
if (uriparts.length == 2) { // http://juick.com/username/
- pagesUser.doGetBlog(sql, getSqlSearch(), request, response, user);
- closeSqlSearch();
+ pagesUser.doGetBlog(sql, sqlSearch, request, response, user);
} else if (uriparts[2].equals("tags")) {
pagesUser.doGetTags(sql, request, response, user);
} else if (uriparts[2].equals("friends")) {
diff --git a/src/main/java/com/juick/http/www/NewMessage.java b/src/main/java/com/juick/http/www/NewMessage.java
index 86725db7..642bd794 100644
--- a/src/main/java/com/juick/http/www/NewMessage.java
+++ b/src/main/java/com/juick/http/www/NewMessage.java
@@ -18,11 +18,7 @@
package com.juick.http.www;
import com.juick.Tag;
-import com.juick.server.CrosspostQueries;
-import com.juick.server.MessagesQueries;
-import com.juick.server.SubscriptionsQueries;
-import com.juick.server.TagQueries;
-import com.juick.server.UserQueries;
+import com.juick.server.*;
import com.juick.xmpp.JID;
import com.juick.xmpp.Message;
import com.juick.xmpp.Stream;
@@ -30,17 +26,18 @@ import com.juick.xmpp.extensions.JuickMessage;
import com.juick.xmpp.extensions.JuickUser;
import com.juick.xmpp.extensions.Nickname;
import com.juick.xmpp.extensions.XOOB;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLEncoder;
-import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
/**
*
@@ -48,10 +45,9 @@ import javax.servlet.http.HttpServletResponse;
*/
public class NewMessage {
- protected void doGetNewMessage(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException {
+ protected void doGetNewMessage(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException {
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
PageTemplates.pageHead(out, "Написать", ""
+ ""
+ ""
@@ -83,12 +79,10 @@ public class NewMessage {
PageTemplates.pageFooter(request, out, visitor, false);
PageTemplates.pageEnd(out);
- } finally {
- out.close();
}
}
- void printUserTags(Connection sql, PrintWriter out, com.juick.User visitor) {
+ void printUserTags(JdbcTemplate sql, PrintWriter out, com.juick.User visitor) {
List tags = TagQueries.getUserTagsAll(sql, visitor.getUID());
if (tags.isEmpty()) {
@@ -134,7 +128,7 @@ public class NewMessage {
out.println("");
}
- public void doPostMessage(Connection sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException {
+ public void doPostMessage(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException {
String body = request.getParameter("body");
if (body == null || body.length() < 1 || body.length() > 4096) {
response.sendError(400);
@@ -265,12 +259,12 @@ public class NewMessage {
out.println("");
out.println("Сообщение опубликовано
");
out.println("Поделитесь своим новым постом в социальных сетях:
");
- if (CrosspostQueries.getTwitterTokens(sql, visitor.getUID()) == null) {
+ if (CrosspostQueries.getTwitterTokens(sql, visitor.getUID()).isPresent()) {
out.println("Отправить в Twitter
");
}
out.println("Отправить в LiveJournal
");
out.println("Отправить в ВКонтакте
");
- if (CrosspostQueries.getFacebookToken(sql, visitor.getUID()) == null) {
+ if (CrosspostQueries.getFacebookToken(sql, visitor.getUID()).isPresent()) {
out.println("Отправить в Facebook
");
}
out.println("Отправить в Google+
");
@@ -282,7 +276,7 @@ public class NewMessage {
}
}
- public void doPostComment(Connection sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException {
+ public void doPostComment(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException {
int mid = Utils.parseInt(request.getParameter("mid"), 0);
if (mid == 0) {
response.sendError(400);
@@ -383,7 +377,7 @@ public class NewMessage {
Utils.sendTemporaryRedirect(response, "/" + msg.getUser().getUName() + "/" + mid + "#" + ridnew);
}
- public void doPostRecomm(Connection sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException {
+ public void doPostRecomm(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException {
int mid = Utils.parseInt(request.getParameter("mid"), 0);
if (mid == 0) {
response.sendError(400);
diff --git a/src/main/java/com/juick/http/www/PM.java b/src/main/java/com/juick/http/www/PM.java
index a9505bdb..b64e6c43 100644
--- a/src/main/java/com/juick/http/www/PM.java
+++ b/src/main/java/com/juick/http/www/PM.java
@@ -23,6 +23,8 @@ import com.juick.xmpp.JID;
import com.juick.xmpp.Message;
import com.juick.xmpp.Stream;
import com.juick.xmpp.extensions.JuickMessage;
+import org.springframework.jdbc.core.JdbcTemplate;
+
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
@@ -38,7 +40,7 @@ import javax.servlet.http.HttpServletResponse;
*/
public class PM {
- protected void doGetInbox(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException {
+ protected void doGetInbox(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException {
/*
int paramBefore = 0;
String paramBeforeStr = request.getParameter("before");
@@ -54,8 +56,7 @@ public class PM {
List msgs = PMQueries.getLastPMInbox(sql, visitor.getUID());
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
PageTemplates.pageHead(out, title, null);
PageTemplates.pageNavigation(out, visitor, null);
PageTemplates.pageHomeColumn(out, sql, visitor);
@@ -97,12 +98,10 @@ public class PM {
PageTemplates.pageFooter(request, out, visitor, false);
PageTemplates.pageEnd(out);
- } finally {
- out.close();
}
}
- protected void doGetSent(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException {
+ protected void doGetSent(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, com.juick.User visitor) throws ServletException, IOException {
/*
int paramBefore = 0;
String paramBeforeStr = request.getParameter("before");
@@ -123,8 +122,7 @@ public class PM {
}
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
PageTemplates.pageHead(out, title, null);
PageTemplates.pageNavigation(out, visitor, null);
PageTemplates.pageHomeColumn(out, sql, visitor);
@@ -169,12 +167,10 @@ public class PM {
PageTemplates.pageFooter(request, out, visitor, false);
PageTemplates.pageEnd(out);
- } finally {
- out.close();
}
}
- public void doPostPM(Connection sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException {
+ public void doPostPM(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, Stream xmpp, com.juick.User visitor) throws ServletException, IOException {
String uname = request.getParameter("uname");
if (uname.startsWith("@")) {
uname = uname.substring(1);
@@ -200,7 +196,7 @@ public class PM {
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(UserQueries.getUserByUID(sql, visitor.getUID()));
+ jmsg.setUser(visitor);
jmsg.setText(body);
msg.childs.add(jmsg);
xmpp.send(msg);
diff --git a/src/main/java/com/juick/http/www/PageTemplates.java b/src/main/java/com/juick/http/www/PageTemplates.java
index fedb11bf..89b0c737 100644
--- a/src/main/java/com/juick/http/www/PageTemplates.java
+++ b/src/main/java/com/juick/http/www/PageTemplates.java
@@ -20,6 +20,7 @@ package com.juick.http.www;
import com.juick.Message;
import com.juick.Tag;
import com.juick.server.MessagesQueries;
+import com.juick.server.TagQueries;
import com.juick.server.UserQueries;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
@@ -35,7 +36,11 @@ import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
+
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.util.StringUtils;
import ru.sape.Sape;
/**
@@ -105,13 +110,13 @@ public class PageTemplates {
out.println("");
}
- public static void pageHomeColumn(PrintWriter out, Connection sql, com.juick.User visitor) {
+ public static void pageHomeColumn(PrintWriter out, JdbcTemplate sql, com.juick.User visitor) {
pageHomeColumn(out, sql, visitor, false);
}
- public static void pageHomeColumn(PrintWriter out, Connection sql, com.juick.User visitor, boolean showAdv) {
+ public static void pageHomeColumn(PrintWriter out, JdbcTemplate sql, com.juick.User visitor, boolean showAdv) {
if (tagsHTML == null) {
- tagsHTML = PageTemplates.getPopularTags(sql, 80);
+ tagsHTML = PageTemplates.formatPopularTags(sql, 80);
}
out.println("");
}
- public static String getPopularTags(Connection sql, int cnt) {
- String ret = "";
-
- PreparedStatement stmt = null;
- ResultSet rs = null;
- try {
- stmt = sql.prepareStatement("SELECT name FROM tags WHERE top=1 ORDER BY name ASC");
- rs = stmt.executeQuery();
- rs.beforeFirst();
- while (rs.next()) {
- if (!ret.isEmpty()) {
- ret += " ";
- }
- try {
- ret += "" + Utils.encodeHTML(rs.getString(1)) + "";
- } catch (UnsupportedEncodingException e) {
- }
-
- }
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(rs, stmt);
- }
-
- return ret;
- }
-
- public static void printContestRating(PrintWriter out, Connection sql) {
- out.println("
");
- out.println("");
- out.println("Кто выиграет iPod?
");
- out.println("");
-
- int i = 0;
- PreparedStatement stmt = null;
- ResultSet rs = null;
- try {
- stmt = sql.prepareStatement("SELECT users.id,users.nick,COUNT(users_refs.user_id) AS cnt FROM users INNER JOIN users_refs ON users.id=users_refs.ref WHERE users.id>2 GROUP BY users_refs.ref ORDER BY cnt DESC LIMIT 10");
- rs = stmt.executeQuery();
- rs.beforeFirst();
- while (rs.next()) {
- String uname = rs.getString(2);
- if (i == 0) {
- out.println(" " + uname + " | " + rs.getInt(3) + " |
");
- } else {
- out.println(" " + uname + " | " + rs.getInt(3) + " |
");
- }
- i++;
- }
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(rs, stmt);
- }
-
- out.println("
");
- out.println("");
+ public static String formatPopularTags(JdbcTemplate sql, int cnt) {
+ List popularTags = TagQueries.getPopularTags(sql).stream()
+ .map(t -> "" + Utils.encodeHTML(t) + "").collect(Collectors.toList());
+ return StringUtils.collectionToDelimitedString(popularTags, " ");
}
public static void pageFooter(HttpServletRequest request, PrintWriter out, com.juick.User visitor, boolean sapeon) {
@@ -455,7 +406,7 @@ public class PageTemplates {
return msg;
}
- public static void printMessages(PrintWriter out, Connection sql, com.juick.User user, List mids, com.juick.User visitor, int YandexID, int ad_mid) {
+ public static void printMessages(PrintWriter out, JdbcTemplate sql, com.juick.User user, List mids, com.juick.User visitor, int YandexID, int ad_mid) {
List msgs = MessagesQueries.getMessages(sql, mids);
for (int i = 0; i < msgs.size(); i++) {
diff --git a/src/main/java/com/juick/http/www/RSS.java b/src/main/java/com/juick/http/www/RSS.java
index 72893915..349743b5 100644
--- a/src/main/java/com/juick/http/www/RSS.java
+++ b/src/main/java/com/juick/http/www/RSS.java
@@ -19,16 +19,16 @@ package com.juick.http.www;
import com.juick.Message;
import com.juick.server.MessagesQueries;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
-import java.sql.Connection;
import java.text.SimpleDateFormat;
import java.util.Date;
-import java.util.Iterator;
import java.util.List;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
/**
*
@@ -36,10 +36,9 @@ import javax.servlet.http.HttpServletResponse;
*/
public class RSS {
- private static final SimpleDateFormat sdfSQL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static final SimpleDateFormat sdfRSS = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
- protected void doGet(Connection sql, HttpServletRequest request, HttpServletResponse response, int uid, String uname) throws ServletException, IOException {
+ protected void doGet(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, int uid, String uname) throws ServletException, IOException {
List mids = MessagesQueries.getUserBlog(sql, uid, 0, 0);
if (mids.isEmpty()) {
response.sendError(404);
@@ -73,14 +72,9 @@ public class RSS {
out.println("]]>");
out.println("");
- synchronized (sdfSQL) {
- try {
- Date date = sdfSQL.parse(msg.TimestampString);
- out.println("" + sdfRSS.format(date) + "");
- } catch (Exception e) {
- System.err.println("PARSE EXCEPTION: " + msg.TimestampString);
- }
- }
+ Date date = msg.getDate();
+ out.println("" + sdfRSS.format(date) + "");
+
out.println("http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + "");
if (!msg.Tags.isEmpty()) {
diff --git a/src/main/java/com/juick/http/www/Settings.java b/src/main/java/com/juick/http/www/Settings.java
index de37bdd0..f197ff12 100644
--- a/src/main/java/com/juick/http/www/Settings.java
+++ b/src/main/java/com/juick/http/www/Settings.java
@@ -17,6 +17,8 @@
*/
package com.juick.http.www;
+import org.springframework.jdbc.core.JdbcTemplate;
+
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
@@ -33,12 +35,11 @@ import javax.servlet.http.HttpServletResponse;
*/
public class Settings {
- protected void doGet(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doGet(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
PageTemplates.pageHead(out, "Логин", "");
PageTemplates.pageNavigation(out, visitor, null);
@@ -56,12 +57,10 @@ public class Settings {
PageTemplates.pageFooter(request, out, visitor, false);
PageTemplates.pageEnd(out);
- } finally {
- out.close();
}
}
- protected void doPost(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doPost(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
if (username == null || password == null || username.length() > 32 || password.isEmpty()) {
@@ -79,16 +78,7 @@ public class Settings {
if (uid > 0) {
- PreparedStatement stmt = null;
- try {
- stmt = sql.prepareStatement("DELETE FROM logins WHERE user_id=?");
- stmt.setInt(1, uid);
- stmt.executeUpdate();
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(null, stmt);
- }
+ throw new IOException("Settings");
}
String referer = request.getHeader("Referer");
diff --git a/src/main/java/com/juick/http/www/SignUp.java b/src/main/java/com/juick/http/www/SignUp.java
index 64b62e48..1ee23386 100644
--- a/src/main/java/com/juick/http/www/SignUp.java
+++ b/src/main/java/com/juick/http/www/SignUp.java
@@ -18,16 +18,17 @@
package com.juick.http.www;
import com.juick.server.UserQueries;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
+import org.apache.commons.lang3.tuple.Pair;
+import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.jdbc.core.JdbcTemplate;
+
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.List;
/**
*
@@ -35,7 +36,7 @@ import javax.servlet.http.HttpServletResponse;
*/
public class SignUp {
- protected void doGet(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doGet(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
String type = request.getParameter("type");
@@ -61,8 +62,7 @@ public class SignUp {
}
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
PageTemplates.pageHead(out, "Новый пользователь", null);
PageTemplates.pageNavigation(out, visitor, null);
@@ -110,12 +110,10 @@ public class SignUp {
PageTemplates.pageFooter(request, out, visitor, false);
PageTemplates.pageEnd(out);
- } finally {
- out.close();
}
}
- protected void doPost(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doPost(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
int uid = 0;
@@ -204,170 +202,57 @@ public class SignUp {
response.sendRedirect("/");
}
- private boolean setUserRef(Connection sql, int uid, int ref) {
- boolean ret = false;
- PreparedStatement stmt = null;
- try {
- stmt = sql.prepareStatement("INSERT INTO users_refs(user_id,ref) VALUES (?,?)");
- stmt.setInt(1, uid);
- stmt.setInt(2, ref);
- stmt.executeUpdate();
- ret = true;
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(null, stmt);
- }
- return ret;
+ private boolean setUserRef(JdbcTemplate sql, int uid, int ref) {
+ return sql.update("INSERT INTO users_refs(user_id,ref) VALUES (?,?)", uid, ref) > 0;
}
- private String getFacebookNameByHash(Connection sql, String hash) {
- String ret = null;
-
- PreparedStatement stmt = null;
- ResultSet rs = null;
+ private String getFacebookNameByHash(JdbcTemplate sql, String hash) {
try {
- stmt = sql.prepareStatement("SELECT fb_name,fb_link FROM facebook WHERE loginhash=?");
- stmt.setString(1, hash);
- rs = stmt.executeQuery();
- if (rs.first()) {
- ret = "" + rs.getString(1) + "";
- }
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(rs, stmt);
+ return sql.queryForObject("SELECT fb_name,fb_link FROM facebook WHERE loginhash=?", String.class, hash);
+ } catch (EmptyResultDataAccessException e) {
+ return null;
}
-
- return ret;
}
- private String getTelegramNameByHash(Connection sql, String hash) {
- String ret = null;
-
- PreparedStatement stmt = null;
- ResultSet rs = null;
+ private String getTelegramNameByHash(JdbcTemplate sql, String hash) {
try {
- stmt = sql.prepareStatement("SELECT tg_name FROM telegram WHERE loginhash=?");
- stmt.setString(1, hash);
- rs = stmt.executeQuery();
- if (rs.first()) {
- ret = "" + rs.getString(1) + "";
- }
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(rs, stmt);
+ String name = sql.queryForObject("SELECT tg_name FROM telegram WHERE loginhash=?", String.class, hash);
+ return "" + name + "";
+ } catch (EmptyResultDataAccessException e) {
+ return null;
}
-
- return ret;
}
- private boolean setFacebookUser(Connection sql, String hash, int uid) {
- boolean ret = false;
- PreparedStatement stmt = null;
- try {
- stmt = sql.prepareStatement("UPDATE facebook SET user_id=?,loginhash=NULL WHERE loginhash=?");
- stmt.setInt(1, uid);
- stmt.setString(2, hash);
- stmt.executeUpdate();
- ret = true;
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(null, stmt);
- }
- return ret;
+ private boolean setFacebookUser(JdbcTemplate sql, String hash, int uid) {
+ return sql.update("UPDATE facebook SET user_id=?,loginhash=NULL WHERE loginhash=?", uid, hash) > 0;
}
- private String getVKNameByHash(Connection sql, String hash) {
- String ret = null;
-
- PreparedStatement stmt = null;
- ResultSet rs = null;
- try {
- stmt = sql.prepareStatement("SELECT vk_name,vk_link FROM vk WHERE loginhash=?");
- stmt.setString(1, hash);
- rs = stmt.executeQuery();
- if (rs.first()) {
- ret = "" + rs.getString(1) + "";
- }
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(rs, stmt);
+ private String getVKNameByHash(JdbcTemplate sql, String hash) {
+ List> logins = sql.query("SELECT vk_name,vk_link FROM vk WHERE loginhash=?",
+ (rs, num) -> {
+ return Pair.of(rs.getString(1), rs.getString(2));
+ }, hash);
+ if (logins.size() > 0) {
+ return "" + logins.get(0).getLeft() + "";
}
-
- return ret;
+ return null;
}
- private boolean setVKUser(Connection sql, String hash, int uid) {
- boolean ret = false;
- PreparedStatement stmt = null;
- try {
- stmt = sql.prepareStatement("UPDATE vk SET user_id=?,loginhash=NULL WHERE loginhash=?");
- stmt.setInt(1, uid);
- stmt.setString(2, hash);
- stmt.executeUpdate();
- ret = true;
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(null, stmt);
- }
- return ret;
+ private boolean setVKUser(JdbcTemplate sql, String hash, int uid) {
+ return sql.update("UPDATE vk SET user_id=?,loginhash=NULL WHERE loginhash=?", uid, hash) > 0;
}
- private boolean setTelegramUser(Connection sql, String hash, int uid) {
- boolean ret = false;
- PreparedStatement stmt = null;
- try {
- stmt = sql.prepareStatement("UPDATE telegram SET user_id=?,loginhash=NULL WHERE loginhash=?");
- stmt.setInt(1, uid);
- stmt.setString(2, hash);
- stmt.executeUpdate();
- ret = true;
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(null, stmt);
- }
- return ret;
+ private boolean setTelegramUser(JdbcTemplate sql, String hash, int uid) {
+ return sql.update("UPDATE telegram SET user_id=?,loginhash=NULL WHERE loginhash=?", uid, hash) > 0;
}
- private String getJIDByHash(Connection sql, String hash) {
- String ret = null;
-
- PreparedStatement stmt = null;
- ResultSet rs = null;
+ private String getJIDByHash(JdbcTemplate sql, String hash) {
try {
- stmt = sql.prepareStatement("SELECT jid FROM jids WHERE loginhash=?");
- stmt.setString(1, hash);
- rs = stmt.executeQuery();
- if (rs.first()) {
- ret = rs.getString(1);
- }
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(rs, stmt);
+ return sql.queryForObject("SELECT jid FROM jids WHERE loginhash=?", String.class, hash);
+ } catch (EmptyResultDataAccessException e) {
+ return null;
}
-
- return ret;
}
- private boolean setJIDUser(Connection sql, String hash, int uid) {
- boolean ret = false;
- PreparedStatement stmt = null;
- try {
- stmt = sql.prepareStatement("UPDATE jids SET user_id=?,loginhash=NULL WHERE loginhash=?");
- stmt.setInt(1, uid);
- stmt.setString(2, hash);
- stmt.executeUpdate();
- ret = true;
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(null, stmt);
- }
- return ret;
+ private boolean setJIDUser(JdbcTemplate sql, String hash, int uid) {
+ return sql.update("UPDATE jids SET user_id=?,loginhash=NULL WHERE loginhash=?", uid, hash) > 0;
}
}
diff --git a/src/main/java/com/juick/http/www/TwitterAuth.java b/src/main/java/com/juick/http/www/TwitterAuth.java
index ff02c28b..bbad4d83 100644
--- a/src/main/java/com/juick/http/www/TwitterAuth.java
+++ b/src/main/java/com/juick/http/www/TwitterAuth.java
@@ -7,6 +7,7 @@ import com.github.scribejava.core.oauth.OAuth10aService;
import com.github.scribejava.core.oauth.OAuthService;
import com.juick.server.UserQueries;
import org.json.JSONObject;
+import org.springframework.jdbc.core.JdbcTemplate;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
@@ -29,7 +30,7 @@ public class TwitterAuth {
this.consumerSecret = consumerSecret;
}
- protected void doGet(Connection sql, HttpServletRequest request, HttpServletResponse response)
+ protected void doGet(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String hash = "", request_token = "", request_token_secret = "";
String verifier = request.getParameter("oauth_verifier");
diff --git a/src/main/java/com/juick/http/www/User.java b/src/main/java/com/juick/http/www/User.java
index 84d1ad9a..a4fdcf21 100644
--- a/src/main/java/com/juick/http/www/User.java
+++ b/src/main/java/com/juick/http/www/User.java
@@ -20,21 +20,18 @@ package com.juick.http.www;
import com.juick.server.MessagesQueries;
import com.juick.server.TagQueries;
import com.juick.server.UserQueries;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import javax.servlet.ServletException;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
/**
*
@@ -42,7 +39,7 @@ import javax.servlet.http.HttpServletResponse;
*/
public class User {
- protected void doGetBlog(Connection sql, Connection sqlSearch, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException {
+ protected void doGetBlog(JdbcTemplate sql, JdbcTemplate sqlSearch, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
List mids;
@@ -158,7 +155,7 @@ public class User {
}
}
- protected void doGetTags(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException {
+ protected void doGetTags(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (visitor == null) {
@@ -181,7 +178,7 @@ public class User {
}
}
- protected void doGetFriends(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException {
+ protected void doGetFriends(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (visitor == null) {
@@ -227,7 +224,7 @@ public class User {
}
}
- protected void doGetReaders(Connection sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException {
+ protected void doGetReaders(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, com.juick.User user) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (visitor == null) {
@@ -285,7 +282,7 @@ public class User {
}
}
- public static void pageUserColumn(PrintWriter out, Connection sql, com.juick.User user, com.juick.User visitor) {
+ public static void pageUserColumn(PrintWriter out, JdbcTemplate sql, com.juick.User user, com.juick.User visitor) {
out.println("");
}
- public static String pageUserTags(Connection sql, com.juick.User user, com.juick.User visitor, int cnt) {
+ public static String pageUserTags(JdbcTemplate sql, com.juick.User user, com.juick.User visitor, int cnt) {
com.juick.Tag tags[] = null;
int maxUsageCnt = 0;
diff --git a/src/main/java/com/juick/http/www/Utils.java b/src/main/java/com/juick/http/www/Utils.java
index 931e2c21..ab721020 100644
--- a/src/main/java/com/juick/http/www/Utils.java
+++ b/src/main/java/com/juick/http/www/Utils.java
@@ -17,6 +17,8 @@
*/
package com.juick.http.www;
+import org.springframework.jdbc.core.JdbcTemplate;
+
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -77,7 +79,7 @@ public class Utils {
return attachmentFName;
}
- public static com.juick.User getVisitorUser(Connection sql, HttpServletRequest request, HttpServletResponse response) {
+ public static com.juick.User getVisitorUser(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) {
String hash = getCookie(request, "hash");
if (hash != null) {
com.juick.User visitor = com.juick.server.UserQueries.getUserByHash(sql, hash);
diff --git a/src/main/java/com/juick/http/www/VKontakteLogin.java b/src/main/java/com/juick/http/www/VKontakteLogin.java
index 5f26fef1..8fad3b7a 100644
--- a/src/main/java/com/juick/http/www/VKontakteLogin.java
+++ b/src/main/java/com/juick/http/www/VKontakteLogin.java
@@ -18,19 +18,18 @@
package com.juick.http.www;
import com.juick.server.UserQueries;
-import java.io.IOException;
-import java.net.URLEncoder;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.UUID;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.jdbc.core.JdbcTemplate;
+
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.json.JSONException;
-import org.json.JSONObject;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.util.UUID;
/**
*
@@ -42,7 +41,7 @@ public class VKontakteLogin {
private static final String VK_SECRET = "z2afNI8jA5lIpZ2jsTm1";
private static final String VK_REDIRECT = "http://juick.com/_vklogin";
- protected void doGet(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doGet(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String code = request.getParameter("code");
if (code == null || code.equals("")) {
response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
@@ -114,42 +113,16 @@ public class VKontakteLogin {
}
}
- private int getUIDbyVKID(Connection sql, long vkID) {
- int uid = 0;
- PreparedStatement stmt = null;
- ResultSet rs = null;
+ private int getUIDbyVKID(JdbcTemplate sql, long vkID) {
try {
- stmt = sql.prepareStatement("SELECT user_id FROM vk WHERE vk_id=? AND user_id IS NOT NULL");
- stmt.setLong(1, vkID);
- rs = stmt.executeQuery();
- if (rs.first()) {
- uid = rs.getInt(1);
- }
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(rs, stmt);
+ return sql.queryForObject("SELECT user_id FROM vk WHERE vk_id=? AND user_id IS NOT NULL", Integer.class, vkID);
+ } catch (EmptyResultDataAccessException e) {
+ return 0;
}
- return uid;
}
- private boolean insertDB(Connection sql, long vkID, String loginhash, String token, String vkName, String vkLink) {
- boolean ret = false;
- PreparedStatement stmt = null;
- try {
- stmt = sql.prepareStatement("INSERT INTO vk(vk_id,loginhash,access_token,vk_name,vk_link) VALUES (?,?,?,?,?)");
- stmt.setLong(1, vkID);
- stmt.setString(2, loginhash);
- stmt.setString(3, token);
- stmt.setString(4, vkName);
- stmt.setString(5, vkLink);
- stmt.executeUpdate();
- ret = true;
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(null, stmt);
- }
- return ret;
+ private boolean insertDB(JdbcTemplate sql, long vkID, String loginhash, String token, String vkName, String vkLink) {
+ return sql.update("INSERT INTO vk(vk_id,loginhash,access_token,vk_name,vk_link) VALUES (?,?,?,?,?)",
+ vkID, loginhash, token, vkName, vkLink) > 0;
}
}
--
cgit v1.2.3
From 606f43f50904f7d811cf9b438e0e820e586be900 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Mon, 27 Jun 2016 13:16:43 +0300
Subject: spring-jdbc near complete
---
deps/com.juick.server | 2 +-
src/main/java/com/juick/CrosspostComponent.java | 41 ++++---
src/main/java/com/juick/PushComponent.java | 92 ++++++++--------
src/main/java/com/juick/http/www/Errors.java | 2 +-
src/main/java/com/juick/http/www/Main.java | 2 +-
src/main/java/com/juick/http/www/PM.java | 16 ++-
.../java/com/juick/http/www/PageTemplates.java | 30 ++----
src/main/java/com/juick/http/www/Settings.java | 7 +-
src/main/java/com/juick/http/www/User.java | 100 ++++-------------
src/main/java/com/juick/http/www/UserThread.java | 15 +--
.../com/juick/xmpp/extensions/JuickMessage.java | 17 ++-
.../java/com/juick/xmpp/s2s/ConnectionRouter.java | 45 +++++---
src/main/java/com/juick/xmpp/s2s/JuickBot.java | 118 ++++++++++-----------
.../java/com/juick/xmpp/s2s/XMPPComponent.java | 24 ++---
14 files changed, 222 insertions(+), 289 deletions(-)
(limited to 'src/main')
diff --git a/deps/com.juick.server b/deps/com.juick.server
index 9e740f48..6362eab3 160000
--- a/deps/com.juick.server
+++ b/deps/com.juick.server
@@ -1 +1 @@
-Subproject commit 9e740f48cca7332c67a165c6cf60e09bc549e686
+Subproject commit 6362eab34390b187944c7e3c12eb444e2fb2c455
diff --git a/src/main/java/com/juick/CrosspostComponent.java b/src/main/java/com/juick/CrosspostComponent.java
index d5f13ab2..d7ee8724 100644
--- a/src/main/java/com/juick/CrosspostComponent.java
+++ b/src/main/java/com/juick/CrosspostComponent.java
@@ -24,6 +24,9 @@ import com.juick.xmpp.Stream;
import com.juick.xmpp.StreamComponent;
import com.juick.xmpp.extensions.JuickMessage;
import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang3.tuple.Pair;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.datasource.DriverManagerDataSource;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
@@ -35,7 +38,6 @@ import java.net.Socket;
import java.net.URL;
import java.net.URLEncoder;
import java.security.Key;
-import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
@@ -61,7 +63,7 @@ public class CrosspostComponent implements ServletContextListener, Stream.Strea
public final static String TWITTERURL = "https://api.twitter.com/1.1/statuses/update.json";
public final static String FBURL = "https://graph.facebook.com/me/feed";
public final static String VKURL = "https://api.vk.com/method/wall.post";
- Connection sql;
+ JdbcTemplate sql;
Stream xmpp;
String twitter_consumer_key;
String twitter_consumer_secret;
@@ -80,8 +82,7 @@ public class CrosspostComponent implements ServletContextListener, Stream.Strea
twitter_consumer_key = conf.getProperty("twitter_consumer_key", "");
twitter_consumer_secret = conf.getProperty("twitter_consumer_secret", "");
- setupSql(conf.getProperty("mysql_host"), conf.getProperty("mysql_username"),
- conf.getProperty("mysql_password", ""), conf.getProperty("mysql_database", ""));
+ setupSql(conf.getProperty("datasource_driver", "com.mysql.jdbc.Driver"), conf.getProperty("datasource_url", ""));
setupXmppComponent(conf.getProperty("xmpp_password", ""));
} catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage(), e);
@@ -115,15 +116,11 @@ public class CrosspostComponent implements ServletContextListener, Stream.Strea
logger.info("component destroyed");
}
- public void setupSql(String host, String username, String password, String database) {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- sql = DriverManager.getConnection(
- String.format("jdbc:mysql://%s/%s?autoReconnect=true&user=%s&password=%s",
- host, database, username, password));
- } catch (SQLException | ClassNotFoundException e) {
- logger.log(Level.SEVERE, e.getMessage(), e);
- }
+ public void setupSql(String driver, String url) {
+ DriverManagerDataSource dataSource = new DriverManagerDataSource();
+ dataSource.setDriverClassName(driver);
+ dataSource.setUrl(url);
+ sql = new JdbcTemplate(dataSource);
}
public void setupXmppComponent(String password) {
@@ -161,8 +158,8 @@ public class CrosspostComponent implements ServletContextListener, Stream.Strea
}
public boolean facebookPost(com.juick.Message jmsg) {
- String token = CrosspostQueries.getFacebookToken(sql, jmsg.getUser().getUID());
- if (token == null) {
+ String token = CrosspostQueries.getFacebookToken(sql, jmsg.getUser().getUID()).orElse("");
+ if (token.isEmpty()) {
return false;
}
@@ -198,8 +195,8 @@ public class CrosspostComponent implements ServletContextListener, Stream.Strea
}
public boolean vkontaktePost(com.juick.Message jmsg) {
- String tokens[] = CrosspostQueries.getVKTokens(sql, jmsg.getUser().getUID());
- if (tokens == null || tokens.length != 2) {
+ Pair tokens = CrosspostQueries.getVKTokens(sql, jmsg.getUser().getUID()).orElse(Pair.of("", ""));
+ if (tokens.getLeft().isEmpty() || tokens.getRight().isEmpty()) {
return false;
}
@@ -209,7 +206,7 @@ public class CrosspostComponent implements ServletContextListener, Stream.Strea
boolean ret = false;
try {
- String body = "owner_id=" + tokens[0] + "&access_token=" + URLEncoder.encode(tokens[1], "UTF-8") + "&from_group=1&message=" + URLEncoder.encode(status, "UTF-8");
+ String body = "owner_id=" + tokens.getLeft() + "&access_token=" + URLEncoder.encode(tokens.getRight(), "UTF-8") + "&from_group=1&message=" + URLEncoder.encode(status, "UTF-8");
HttpsURLConnection conn = (HttpsURLConnection) new URL(VKURL).openConnection();
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
@@ -235,12 +232,12 @@ public class CrosspostComponent implements ServletContextListener, Stream.Strea
}
public boolean twitterPost(com.juick.Message jmsg) {
- String tokens[] = CrosspostQueries.getTwitterTokens(sql, jmsg.getUser().getUID());
- if (tokens == null || tokens.length != 2) {
+ Pair tokens = CrosspostQueries.getTwitterTokens(sql, jmsg.getUser().getUID()).orElse(Pair.of("", ""));
+ if (tokens.getLeft().isEmpty() || tokens.getRight().isEmpty()) {
return false;
}
- String token = percentEncode(tokens[0]);
- String token_secret = percentEncode(tokens[1]);
+ String token = percentEncode(tokens.getLeft());
+ String token_secret = percentEncode(tokens.getRight());
logger.info("TWITTER: #" + jmsg.getMID());
diff --git a/src/main/java/com/juick/PushComponent.java b/src/main/java/com/juick/PushComponent.java
index 0cb8e626..e33d5fc3 100644
--- a/src/main/java/com/juick/PushComponent.java
+++ b/src/main/java/com/juick/PushComponent.java
@@ -24,6 +24,8 @@ import com.google.android.gcm.server.Sender;
import com.juick.json.MessageSerializer;
import com.juick.server.MessagesQueries;
import com.juick.server.PushQueries;
+import com.juick.server.SubscriptionsQueries;
+import com.juick.server.UserQueries;
import com.juick.xmpp.JID;
import com.juick.xmpp.Message.MessageListener;
import com.juick.xmpp.Stream;
@@ -45,6 +47,8 @@ import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.http.util.TextUtils;
import org.json.JSONObject;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.datasource.DriverManagerDataSource;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
@@ -60,6 +64,7 @@ import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
+import java.util.stream.Collectors;
/**
*
@@ -72,7 +77,7 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
private ExecutorService executorService;
String wns_application_sip;
String wns_client_secret;
- Connection sql;
+ JdbcTemplate sql;
Socket socket;
Stream xmpp;
Sender GCMSender;
@@ -91,8 +96,7 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
wns_client_secret = conf.getProperty("wns_client_secret", "");
GCMSender = new Sender(conf.getProperty("gcm_key"));
- setupSql(conf.getProperty("mysql_host"), conf.getProperty("mysql_username"),
- conf.getProperty("mysql_password", ""), conf.getProperty("mysql_database", ""));
+ setupSql(conf.getProperty("datasource_driver", "com.mysql.jdbc.Driver"), conf.getProperty("datasource_url", ""));
setupXmppComponent(new JID("", conf.getProperty("push_jid"), ""), conf.getProperty("xmpp_host", "localhost"),
Integer.parseInt(conf.getProperty("xmpp_port", "5347")), conf.getProperty("push_xmpp_password", ""));
} catch (IOException e) {
@@ -127,15 +131,11 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
logger.info("component destroyed");
}
- public void setupSql(String host, String username, String password, String database) {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- sql = DriverManager.getConnection(
- String.format("jdbc:mysql://%s/%s?autoReconnect=true&user=%s&password=%s",
- host, database, username, password));
- } catch (SQLException | ClassNotFoundException e) {
- logger.log(Level.SEVERE, e.getMessage(), e);
- }
+ public void setupSql(String driver, String url) {
+ DriverManagerDataSource dataSource = new DriverManagerDataSource();
+ dataSource.setDriverClassName(driver);
+ dataSource.setUrl(url);
+ sql = new JdbcTemplate(dataSource);
}
public void setupXmppComponent(JID jid, String host, int port, String password) {
@@ -157,42 +157,36 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
}
@Override
- public void onStreamFail(String e) {logger.log(Level.SEVERE, "XMPP STREAM FAIL", e);}
+ public void onStreamFail(Exception e) {logger.log(Level.SEVERE, "XMPP STREAM FAIL", e);}
@Override
public void onMessage(com.juick.xmpp.Message msg) {
- JuickMessage jmsg = (JuickMessage) msg.getChild(JuickMessage.XMLNS);
- if (jmsg == null) {
- return;
- }
- logger.info("Message to push: " + msg.toString());
-
+ JuickMessage jmsg = (JuickMessage)msg.getChild(JuickMessage.XMLNS);
+ List subscribedUsers = new ArrayList<>();
boolean isPM = jmsg.getMID() == 0;
boolean isReply = jmsg.getRID() > 0;
- int senderID = 0, recipientID = 0;
- if (isReply) {
- senderID = jmsg.getUser().getUID();
- }
+ int pmTo = 0;
if (isPM) {
- // PM
- try {
- recipientID = Integer.parseInt(msg.to.Username);
- } catch (NumberFormatException e) {
- logger.info("Wrong PM recipient: " + msg.to.Username);
- return;
+ pmTo = Integer.parseInt(msg.to.Username);
+ } else {
+ if (isReply) {
+ subscribedUsers =
+ SubscriptionsQueries.getUsersSubscribedToComments(sql, jmsg.getMID(), jmsg.getUser().getUID());
+ } else {
+ // new message
+ subscribedUsers = SubscriptionsQueries.getSubscribedUsers(sql, jmsg.getUser().getUID(), jmsg.getMID());
}
}
/*** ANDROID ***/
- List regids;
+ final List regids = new ArrayList<>();
if (isPM) {
- regids = new ArrayList<>();
- String targetId = PushQueries.getAndroidRegID(sql, recipientID);
- if (targetId != null && !targetId.isEmpty()) {
- regids.add(targetId);
- }
+ PushQueries.getAndroidRegID(sql, pmTo).ifPresent(regids::add);
} else {
- regids = isReply ? PushQueries.getAndroidSubscribersToComments(sql, jmsg.getMID(), senderID) : PushQueries.getAndroidSubscribers(sql, senderID);
+ List uids = subscribedUsers.stream().map(User::getUID).collect(Collectors.toList());
+ if (uids.size() > 0) {
+ regids.addAll(PushQueries.getAndroidTokens(sql, uids));
+ }
}
if (!regids.isEmpty()) {
@@ -216,15 +210,14 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
}
/*** WinPhone ***/
- List urls;
+ final List urls = new ArrayList<>();
if (isPM) {
- urls = new ArrayList<>();
- String targetURL = PushQueries.getWinPhoneURL(sql, recipientID);
- if (!TextUtils.isEmpty(targetURL)) {
- urls.add(targetURL);
- }
+ PushQueries.getWinPhoneURL(sql, pmTo).ifPresent(urls::add);
} else {
- urls = isReply ? PushQueries.getWindowsSubscribersToComments(sql, jmsg.getMID(), senderID) :PushQueries.getWinPhoneSubscribers(sql, senderID);
+ List uids = subscribedUsers.stream().map(User::getUID).collect(Collectors.toList());
+ if (uids.size() > 0) {
+ urls.addAll(PushQueries.getWindowsTokens(sql, uids));
+ }
}
@@ -262,15 +255,14 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
}
/*** iOS ***/
- List tokens;
+ final List tokens = new ArrayList<>();
if (isPM) {
- tokens = new ArrayList<>();
- String targetToken = PushQueries.getAPNSToken(sql, recipientID);
- if (targetToken != null && !targetToken.isEmpty()) {
- tokens.add(targetToken);
- }
+ PushQueries.getAPNSToken(sql, pmTo).ifPresent(tokens::add);
} else {
- tokens = isReply ? PushQueries.getAppleSubscribersToComments(sql, jmsg.getMID(), senderID) : PushQueries.getAPNSSubscribers(sql, senderID);
+ List uids = subscribedUsers.stream().map(User::getUID).collect(Collectors.toList());
+ if (uids.size() > 0) {
+ tokens.addAll(PushQueries.getAPNSTokens(sql, uids));
+ }
}
if (!tokens.isEmpty()) {
ApnsService service = APNS.newService().withCert("/etc/juick/ios.p12", "juick")
diff --git a/src/main/java/com/juick/http/www/Errors.java b/src/main/java/com/juick/http/www/Errors.java
index 2161daf1..0044c209 100644
--- a/src/main/java/com/juick/http/www/Errors.java
+++ b/src/main/java/com/juick/http/www/Errors.java
@@ -20,7 +20,7 @@ public class Errors {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (tagsHTML == null) {
- tagsHTML = PageTemplates.getPopularTags(sql, 80);
+ tagsHTML = PageTemplates.formatPopularTags(sql, 80);
}
response.setStatus(404);
diff --git a/src/main/java/com/juick/http/www/Main.java b/src/main/java/com/juick/http/www/Main.java
index 604ccf9a..63bf1c1f 100644
--- a/src/main/java/com/juick/http/www/Main.java
+++ b/src/main/java/com/juick/http/www/Main.java
@@ -104,7 +104,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
}
@Override
- public void onStreamFail(String e) {log("XMPP STREAM FAIL:" + e);}
+ public void onStreamFail(Exception e) {log("XMPP STREAM FAIL:" + e);}
@Override
public void onStreamReady() {
diff --git a/src/main/java/com/juick/http/www/PM.java b/src/main/java/com/juick/http/www/PM.java
index b64e6c43..b351eb0e 100644
--- a/src/main/java/com/juick/http/www/PM.java
+++ b/src/main/java/com/juick/http/www/PM.java
@@ -25,14 +25,12 @@ import com.juick.xmpp.Stream;
import com.juick.xmpp.extensions.JuickMessage;
import org.springframework.jdbc.core.JdbcTemplate;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.sql.Connection;
-import java.util.ArrayList;
-import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.List;
/**
*
@@ -74,7 +72,7 @@ public class PM {
out.println(" ");
out.println(" ");
out.println(" ");
- out.println("
");
+ out.println("
");
out.println("
" + txt + "
");
out.println("