diff options
-rw-r--r-- | .gitignore | 4 | ||||
m--------- | deps/com.juick.json | 10 | ||||
m--------- | deps/com.juick.server | 10 | ||||
-rw-r--r-- | src/main/java/com/juick/api/Main.java | 23 | ||||
-rw-r--r-- | src/main/java/com/juick/api/Messages.java | 15 | ||||
-rw-r--r-- | src/main/java/com/juick/api/Others.java | 10 | ||||
-rw-r--r-- | src/main/java/com/juick/api/PM.java | 3 | ||||
-rw-r--r-- | src/main/java/com/juick/api/Users.java | 23 | ||||
-rw-r--r-- | src/test/java/com/juick/tests/JsonTests.java | 5 |
9 files changed, 53 insertions, 50 deletions
@@ -2,11 +2,11 @@ build/* .gradle/*
deps/*
.idea/*
-*.iml
+**/*.iml
**/juick.conf
/build/
/bin/
/.nb-gradle/
.settings/*
.classpath
-.project
\ No newline at end of file +.project
diff --git a/deps/com.juick.json b/deps/com.juick.json -Subproject d4cbeb802cba9fb3bd0885c31807bdff7b3f6b2 +Subproject c152ab72d3ba8f662706eb4b1342d839762a243 diff --git a/deps/com.juick.server b/deps/com.juick.server -Subproject 79e48598873f6a2b4ec1aa850e310a689d862af +Subproject c37ed56f884661666b964e47efd23a36be9b24d diff --git a/src/main/java/com/juick/api/Main.java b/src/main/java/com/juick/api/Main.java index 07504179..09dd4cbd 100644 --- a/src/main/java/com/juick/api/Main.java +++ b/src/main/java/com/juick/api/Main.java @@ -28,6 +28,7 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; +import java.util.logging.Logger; import javax.servlet.ServletException; import javax.servlet.annotation.MultipartConfig; import javax.servlet.annotation.WebServlet; @@ -75,18 +76,14 @@ public class Main extends HttpServlet implements Stream.StreamListener { } public void setupXmppComponent(final String password) { - Thread thr = new Thread(new Runnable() { - - @Override - public void run() { - try { - Socket socket = new Socket("localhost", 5347); - xmpp = new StreamComponent(new JID("", "api.juick.com", ""), socket.getInputStream(), socket.getOutputStream(), password); - xmpp.addListener(Main.this); - xmpp.startParsing(); - } catch (IOException e) { - System.err.println(e); - } + Thread thr = new Thread(() -> { + try { + Socket socket = new Socket("localhost", 5347); + xmpp = new StreamComponent(new JID("", "api.juick.com", ""), socket.getInputStream(), socket.getOutputStream(), password); + xmpp.addListener(Main.this); + xmpp.startParsing(); + } catch (IOException e) { + log("XMPP exception", e); } }); thr.start(); @@ -94,7 +91,7 @@ public class Main extends HttpServlet implements Stream.StreamListener { @Override public void onStreamFail(String msg) { - System.err.println("XMPP STREAM FAIL: " + msg); + log("XMPP failed: " + msg); } @Override diff --git a/src/main/java/com/juick/api/Messages.java b/src/main/java/com/juick/api/Messages.java index 548e816f..cde3987f 100644 --- a/src/main/java/com/juick/api/Messages.java +++ b/src/main/java/com/juick/api/Messages.java @@ -6,12 +6,13 @@ import com.juick.xmpp.JID; import com.juick.xmpp.Message; import com.juick.xmpp.Stream; import com.juick.xmpp.extensions.JuickMessage; -import java.io.IOException; -import java.sql.Connection; -import java.util.ArrayList; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.sql.Connection; +import java.util.List; /** * @@ -30,9 +31,9 @@ public class Messages { public void doGetHome(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException { int before_mid = Utils.parseInt(request.getParameter("before_mid"), 0); - ArrayList<Integer> mids = MessagesQueries.getMyFeed(sql, vuid, before_mid); + List<Integer> mids = MessagesQueries.getMyFeed(sql, vuid, before_mid); if (mids != null && !mids.isEmpty()) { - ArrayList<com.juick.Message> msgs = MessagesQueries.getMessages(sql, mids); + List<com.juick.Message> msgs = MessagesQueries.getMessages(sql, mids); if (msgs != null && !msgs.isEmpty()) { String json = messageSerializer.serializeList(msgs); Main.replyJSON(request, response, json); @@ -47,9 +48,9 @@ public class Messages { public void doGetRecommended(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException { int before_mid = Utils.parseInt(request.getParameter("before_mid"), 0); - ArrayList<Integer> mids = MessagesQueries.getUserRecommendations(sql, vuid, before_mid); + List<Integer> mids = MessagesQueries.getUserRecommendations(sql, vuid, before_mid); if (mids != null && !mids.isEmpty()) { - ArrayList<com.juick.Message> msgs = MessagesQueries.getMessages(sql, mids); + List<com.juick.Message> msgs = MessagesQueries.getMessages(sql, mids); if (msgs != null && !msgs.isEmpty()) { String json = messageSerializer.serializeList(msgs); Main.replyJSON(request, response, json); diff --git a/src/main/java/com/juick/api/Others.java b/src/main/java/com/juick/api/Others.java index 5e5c7475..323ed41a 100644 --- a/src/main/java/com/juick/api/Others.java +++ b/src/main/java/com/juick/api/Others.java @@ -1,13 +1,15 @@ package com.juick.api; +import com.juick.User; import com.juick.json.UserSerializer; import com.juick.server.PMQueries; -import java.io.IOException; -import java.sql.Connection; -import java.util.ArrayList; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.sql.Connection; +import java.util.List; /** * @@ -37,7 +39,7 @@ public class Others { } catch (Exception e) { } - ArrayList<com.juick.User> lastconv = PMQueries.getPMLastConversationsUsers(sql, vuid, cnt); + List<User> lastconv = PMQueries.getPMLastConversationsUsers(sql, vuid, cnt); if (lastconv != null && !lastconv.isEmpty()) { String json = "{\"pms\":" + userSerializer.serializeList(lastconv) + "}"; Main.replyJSON(request, response, json); diff --git a/src/main/java/com/juick/api/PM.java b/src/main/java/com/juick/api/PM.java index ffcd155a..f22a4add 100644 --- a/src/main/java/com/juick/api/PM.java +++ b/src/main/java/com/juick/api/PM.java @@ -10,6 +10,7 @@ import com.juick.xmpp.extensions.JuickMessage; import java.io.IOException; 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; @@ -40,7 +41,7 @@ public class PM { return; } - ArrayList<com.juick.Message> msgs = PMQueries.getPMMessages(sql, vuid, uid); + List<com.juick.Message> msgs = PMQueries.getPMMessages(sql, vuid, uid); if (msgs != null && !msgs.isEmpty()) { String json = messageSerializer.serializeList(msgs); Main.replyJSON(request, response, json); diff --git a/src/main/java/com/juick/api/Users.java b/src/main/java/com/juick/api/Users.java index 37c9ca49..5bae4028 100644 --- a/src/main/java/com/juick/api/Users.java +++ b/src/main/java/com/juick/api/Users.java @@ -1,16 +1,17 @@ package com.juick.api; -import com.juick.User; import com.juick.json.UserSerializer; import com.juick.server.UserQueries; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.sql.Connection; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import java.util.List; /** * @@ -27,11 +28,11 @@ public class Users { } public void doGetUsers(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException { - ArrayList<com.juick.User> users = new ArrayList<User>(); + List<com.juick.User> users = new ArrayList<>(); String punames[] = request.getParameterValues("uname"); if (punames != null) { - ArrayList<String> unames = new ArrayList<String>(Arrays.asList(punames)); + ArrayList<String> unames = new ArrayList<>(Arrays.asList(punames)); Iterator<String> i = unames.iterator(); while (i.hasNext()) { if (!i.next().matches("^[a-zA-Z0-9\\-]{2,16}$")) { @@ -45,7 +46,7 @@ public class Users { String pjids[] = request.getParameterValues("jid"); if (pjids != null) { - ArrayList<String> jids = new ArrayList<String>(Arrays.asList(pjids)); + List<String> jids = new ArrayList<>(Arrays.asList(pjids)); Iterator<String> ii = jids.iterator(); while (ii.hasNext()) { if (!ii.next().matches("^[a-zA-Z0-9\\-\\_\\@\\.]{6,64}$")) { @@ -80,9 +81,9 @@ public class Users { } if (uid > 0) { - ArrayList<Integer> uids = UserQueries.getUserRead(sql, uid); + List<Integer> uids = UserQueries.getUserRead(sql, uid); if (uids.size() > 0) { - ArrayList<com.juick.User> users = UserQueries.getUsersByID(sql, uids); + List<com.juick.User> users = UserQueries.getUsersByID(sql, uids); if (users.size() > 0) { String json = userSerializer.serializeList(users); Main.replyJSON(request, response, json); @@ -108,9 +109,9 @@ public class Users { } if (uid > 0) { - ArrayList<Integer> uids = UserQueries.getUserReaders(sql, uid); + List<Integer> uids = UserQueries.getUserReaders(sql, uid); if (uids.size() > 0) { - ArrayList<com.juick.User> users = UserQueries.getUsersByID(sql, uids); + List<com.juick.User> users = UserQueries.getUsersByID(sql, uids); if (users.size() > 0) { String json = userSerializer.serializeList(users); Main.replyJSON(request, response, json); diff --git a/src/test/java/com/juick/tests/JsonTests.java b/src/test/java/com/juick/tests/JsonTests.java index c99432a6..35854171 100644 --- a/src/test/java/com/juick/tests/JsonTests.java +++ b/src/test/java/com/juick/tests/JsonTests.java @@ -14,6 +14,7 @@ import java.sql.Connection; import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.List;
import java.util.Properties;
public class JsonTests {
@@ -40,10 +41,10 @@ public class JsonTests { @Test
public void CompareSerializers() {
- ArrayList<Integer> mids = MessagesQueries.getMyFeed(sql, 3694, 2799786);
+ List<Integer> mids = MessagesQueries.getMyFeed(sql, 3694, 2799786);
MessageSerializer messageSerializer = new MessageSerializer();
if (mids != null && !mids.isEmpty()) {
- ArrayList<com.juick.Message> msgs = MessagesQueries.getMessages(sql, mids);
+ List<com.juick.Message> msgs = MessagesQueries.getMessages(sql, mids);
if (msgs != null && !msgs.isEmpty()) {
String json = messageSerializer.serializeList(msgs);
try {
|