diff options
author | Vitaly Takmazov | 2016-01-14 13:16:40 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-01-14 13:16:40 +0300 |
commit | 5c207f65b0cafbaa0cbdae72a5a485cf7aa62556 (patch) | |
tree | 60c303f317236c2caab896173fafdaff1eebb115 /src/main/java/com/juick | |
parent | 38013dd67292fa186e3a07d098bc9a484ea2bd0f (diff) | |
parent | ee86970fcae9878af0adcad00cf5333647b8babf (diff) |
Merge branch 'develop' of ssh://den.jabber.ru:2205/var/lib/git/com.juick.api into develop
Diffstat (limited to 'src/main/java/com/juick')
-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 |
5 files changed, 38 insertions, 36 deletions
diff --git a/src/main/java/com/juick/api/Main.java b/src/main/java/com/juick/api/Main.java index 07504179d..09dd4cbd3 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 548e816fb..cde3987fe 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 5e5c74754..323ed41a8 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 ffcd155a8..f22a4add3 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 37c9ca496..5bae4028e 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); |