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/CrosspostComponent.java56
-rw-r--r--src/main/java/com/juick/PushComponent.java61
2 files changed, 48 insertions, 69 deletions
diff --git a/src/main/java/com/juick/CrosspostComponent.java b/src/main/java/com/juick/CrosspostComponent.java
index 7fd50564..22de81b6 100644
--- a/src/main/java/com/juick/CrosspostComponent.java
+++ b/src/main/java/com/juick/CrosspostComponent.java
@@ -24,13 +24,13 @@ import com.juick.xmpp.Stream;
import com.juick.xmpp.StreamComponent;
import com.juick.xmpp.extensions.JuickMessage;
import com.juick.xmpp.utils.Base64;
-import java.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.UnsupportedEncodingException;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import javax.net.ssl.HttpsURLConnection;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import java.io.*;
import java.net.Socket;
import java.net.URL;
import java.net.URLEncoder;
@@ -47,11 +47,6 @@ import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
-import javax.crypto.Mac;
-import javax.crypto.spec.SecretKeySpec;
-import javax.net.ssl.HttpsURLConnection;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
/**
*
@@ -75,24 +70,21 @@ public class CrosspostComponent implements ServletContextListener, Stream.Strea
public void contextInitialized(final ServletContextEvent sce) {
logger.info("component initialized");
executorService = Executors.newSingleThreadExecutor();
- executorService.submit(new Runnable() {
- @Override
- public void run() {
- try {
- Properties conf = new Properties();
- conf.load(sce.getServletContext().getResourceAsStream("WEB-INF/juick.conf"));
-
- LogManager.getLogManager().readConfiguration(
- sce.getServletContext().getResourceAsStream("WEB-INF/logging.properties"));
- 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", ""));
- setupXmppComponent(conf.getProperty("xmpp_password", ""));
- } catch (Exception e) {
- logger.log(Level.SEVERE, e.getMessage(), e);
- }
+ executorService.submit((Runnable) () -> {
+ try {
+ Properties conf = new Properties();
+ conf.load(sce.getServletContext().getResourceAsStream("WEB-INF/juick.conf"));
+
+ LogManager.getLogManager().readConfiguration(
+ sce.getServletContext().getResourceAsStream("WEB-INF/logging.properties"));
+ 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", ""));
+ setupXmppComponent(conf.getProperty("xmpp_password", ""));
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, e.getMessage(), e);
}
});
}
@@ -129,9 +121,7 @@ public class CrosspostComponent implements ServletContextListener, Stream.Strea
sql = DriverManager.getConnection(
String.format("jdbc:mysql://%s/%s?autoReconnect=true&user=%s&password=%s",
host, database, username, password));
- } catch (SQLException e) {
- logger.log(Level.SEVERE, e.getMessage(), e);
- } catch (ClassNotFoundException e) {
+ } catch (SQLException | ClassNotFoundException e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}
}
diff --git a/src/main/java/com/juick/PushComponent.java b/src/main/java/com/juick/PushComponent.java
index aab56778..0c3d70d7 100644
--- a/src/main/java/com/juick/PushComponent.java
+++ b/src/main/java/com/juick/PushComponent.java
@@ -22,14 +22,14 @@ import com.google.android.gcm.server.MulticastResult;
import com.google.android.gcm.server.Result;
import com.google.android.gcm.server.Sender;
import com.juick.json.MessageSerializer;
-import com.juick.server.PushQueries;
import com.juick.server.MessagesQueries;
+import com.juick.server.PushQueries;
import com.juick.xmpp.JID;
import com.juick.xmpp.Message.MessageListener;
-import com.juick.xmpp.utils.XmlUtils;
import com.juick.xmpp.Stream;
import com.juick.xmpp.StreamComponent;
import com.juick.xmpp.extensions.JuickMessage;
+import com.juick.xmpp.utils.XmlUtils;
import com.notnoop.apns.APNS;
import com.notnoop.apns.ApnsService;
import org.apache.http.Consts;
@@ -48,10 +48,7 @@ import org.json.JSONObject;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
-import java.io.BufferedReader;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
import java.net.Socket;
import java.sql.Connection;
import java.sql.Driver;
@@ -84,25 +81,22 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
public void contextInitialized(final ServletContextEvent sce) {
logger.info("component initialized");
executorService = Executors.newSingleThreadExecutor();
- executorService.submit(new Runnable() {
- @Override
- public void run() {
- Properties conf = new Properties();
- try {
- conf.load(sce.getServletContext().getResourceAsStream("WEB-INF/juick.conf"));
- LogManager.getLogManager().readConfiguration(
- sce.getServletContext().getResourceAsStream("WEB-INF/logging.properties"));
- wns_application_sip = conf.getProperty("wns_application_sip", "");
- wns_client_secret = conf.getProperty("wns_client_secret", "");
- GCMSender = new Sender(conf.getProperty("gcm_key"));
+ executorService.submit((Runnable) () -> {
+ Properties conf = new Properties();
+ try {
+ conf.load(sce.getServletContext().getResourceAsStream("WEB-INF/juick.conf"));
+ LogManager.getLogManager().readConfiguration(
+ sce.getServletContext().getResourceAsStream("WEB-INF/logging.properties"));
+ wns_application_sip = conf.getProperty("wns_application_sip", "");
+ 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", ""));
- 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) {
- logger.log(Level.SEVERE, e.getMessage(), e);
- }
+ setupSql(conf.getProperty("mysql_host"), conf.getProperty("mysql_username"),
+ conf.getProperty("mysql_password", ""), conf.getProperty("mysql_database", ""));
+ 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) {
+ logger.log(Level.SEVERE, e.getMessage(), e);
}
});
}
@@ -139,9 +133,7 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
sql = DriverManager.getConnection(
String.format("jdbc:mysql://%s/%s?autoReconnect=true&user=%s&password=%s",
host, database, username, password));
- } catch (SQLException e) {
- logger.log(Level.SEVERE, e.getMessage(), e);
- } catch (ClassNotFoundException e) {
+ } catch (SQLException | ClassNotFoundException e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}
}
@@ -200,7 +192,7 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
/*** ANDROID ***/
List<String> regids;
if (isPM) {
- regids = new ArrayList<String>();
+ regids = new ArrayList<>();
String targetId = PushQueries.getAndroidRegID(sql, recipientID);
if (targetId != null && !targetId.isEmpty()) {
regids.add(targetId);
@@ -232,9 +224,9 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
/*** WinPhone ***/
List<String> urls;
if (isPM) {
- urls = new ArrayList<String>();
+ urls = new ArrayList<>();
String targetURL = PushQueries.getWinPhoneURL(sql, recipientID);
- if (targetURL != null && !targetURL.isEmpty()) {
+ if (!TextUtils.isEmpty(targetURL)) {
urls.add(targetURL);
}
} else {
@@ -266,14 +258,11 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
+ "</commands>"
+ "</toast>";
logger.fine(xml);
- for (int i = 0; i < urls.size(); i++) {
- String url = urls.get(i);
+ for (String url : urls) {
logger.info("WNS: " + url);
sendWNS(wnsToken, url, xml);
}
- } catch (IOException e) {
- logger.log(Level.SEVERE, "WNS: ", e);
- } catch (IllegalStateException e) {
+ } catch (IOException | IllegalStateException e) {
logger.log(Level.SEVERE, "WNS: ", e);
}
}
@@ -281,7 +270,7 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
/*** iOS ***/
List<String> tokens;
if (isPM) {
- tokens = new ArrayList<String>();
+ tokens = new ArrayList<>();
String targetToken = PushQueries.getAPNSToken(sql, recipientID);
if (targetToken != null && !targetToken.isEmpty()) {
tokens.add(targetToken);
@@ -311,7 +300,7 @@ public class PushComponent implements ServletContextListener, Stream.StreamListe
}
HttpClient client = HttpClientBuilder.create().build();
String url = "https://login.live.com/accesstoken.srf";
- List<NameValuePair> formParams = new ArrayList<NameValuePair>();
+ List<NameValuePair> formParams = new ArrayList<>();
formParams.add(new BasicNameValuePair("grant_type", "client_credentials"));
formParams.add(new BasicNameValuePair("client_id", wns_application_sip));
formParams.add(new BasicNameValuePair("client_secret", wns_client_secret));