aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/juick/api/Main.java23
-rw-r--r--src/main/java/com/juick/api/Messages.java15
-rw-r--r--src/main/java/com/juick/api/Others.java10
-rw-r--r--src/main/java/com/juick/api/PM.java3
-rw-r--r--src/main/java/com/juick/api/Users.java23
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 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);