diff options
author | Vitaly Takmazov | 2016-08-08 10:26:37 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-08-08 10:26:37 +0300 |
commit | 64824ed6dddf776ce3ed36fe96ffc300d4127e29 (patch) | |
tree | b6dbdbac997d6c8a6eb9b2bcdc286ee802e47515 /juick-ws/src/main | |
parent | 351a61da81baccae4392fc65bb09e5e19860eaa5 (diff) |
juick-ws: read component jids and ports from config
Diffstat (limited to 'juick-ws/src/main')
3 files changed, 24 insertions, 35 deletions
diff --git a/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java b/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java index 8a55dc7e..da064726 100644 --- a/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java +++ b/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java @@ -8,6 +8,7 @@ import com.juick.xmpp.Message; import com.juick.xmpp.Stream; import com.juick.xmpp.StreamComponent; import com.juick.xmpp.extensions.JuickMessage; +import org.apache.commons.lang3.math.NumberUtils; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.env.Environment; import org.springframework.jdbc.core.JdbcTemplate; @@ -45,8 +46,8 @@ public class XMPPConnection implements InitializingBean, Stream.StreamListener, xmppPassword = env.getProperty("xmpp_password"); ms = new MessageSerializer(); try { - Socket socket = new Socket("localhost", 5347); - xmpp = new StreamComponent(new JID("", "ws.juick.com", ""), socket.getInputStream(), socket.getOutputStream(), xmppPassword); + Socket socket = new Socket("localhost", NumberUtils.toInt(env.getProperty("xmpp_port", ""), 5347)); + xmpp = new StreamComponent(new JID(env.getProperty("ws_jid", "ws.juick.local")), socket.getInputStream(), socket.getOutputStream(), xmppPassword); xmpp.addChildParser(new JuickMessage()); xmpp.addListener((Stream.StreamListener) this); xmpp.addListener((Message.MessageListener) this); diff --git a/juick-ws/src/main/java/com/juick/ws/components/CrosspostComponent.java b/juick-ws/src/main/java/com/juick/ws/components/CrosspostComponent.java index ea397c28..977e0ed0 100644 --- a/juick-ws/src/main/java/com/juick/ws/components/CrosspostComponent.java +++ b/juick-ws/src/main/java/com/juick/ws/components/CrosspostComponent.java @@ -24,6 +24,7 @@ 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.math.NumberUtils; import org.apache.commons.lang3.tuple.Pair; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; @@ -43,8 +44,6 @@ import java.net.URL; import java.net.URLEncoder; import java.security.Key; import java.util.UUID; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.logging.Level; import java.util.logging.Logger; @@ -57,8 +56,6 @@ public class CrosspostComponent implements InitializingBean, DisposableBean, Str private static Logger logger = Logger.getLogger(CrosspostComponent.class.getName()); - private ExecutorService executorService; - 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"; @@ -73,23 +70,20 @@ public class CrosspostComponent implements InitializingBean, DisposableBean, Str @Override public void afterPropertiesSet() throws Exception { logger.info("component initialized"); - executorService = Executors.newSingleThreadExecutor(); - executorService.submit(() -> { - try { - twitter_consumer_key = env.getProperty("twitter_consumer_key", ""); - twitter_consumer_secret = env.getProperty("twitter_consumer_secret", ""); - - setupSql(env.getProperty("datasource_driver", "com.mysql.jdbc.Driver"), env.getProperty("datasource_url", "")); - setupXmppComponent(env.getProperty("xmpp_password", "")); - } catch (Exception e) { - logger.log(Level.SEVERE, e.getMessage(), e); - } - }); + try { + twitter_consumer_key = env.getProperty("twitter_consumer_key", ""); + twitter_consumer_secret = env.getProperty("twitter_consumer_secret", ""); + + setupSql(env.getProperty("datasource_driver", "com.mysql.jdbc.Driver"), env.getProperty("datasource_url", "")); + setupXmppComponent(env.getProperty("crosspost_jid", "crosspost.juick.local"), + env.getProperty("xmpp_password", ""), NumberUtils.toInt(env.getProperty("xmpp_port", ""), 5347)); + } catch (Exception e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } } @Override public void destroy() { - executorService.shutdown(); logger.info("component destroyed"); } @@ -100,10 +94,10 @@ public class CrosspostComponent implements InitializingBean, DisposableBean, Str sql = new JdbcTemplate(dataSource); } - public void setupXmppComponent(String password) { + public void setupXmppComponent(String jid, String password, int port) { try { - Socket socket = new Socket("localhost", 5347); - xmpp = new StreamComponent(new JID("", "crosspost.juick.com", ""), socket.getInputStream(), socket.getOutputStream(), password); + Socket socket = new Socket("localhost", port); + xmpp = new StreamComponent(new JID(jid), socket.getInputStream(), socket.getOutputStream(), password); xmpp.addChildParser(new JuickMessage()); xmpp.addListener((Stream.StreamListener) this); xmpp.addListener((Message.MessageListener) this); diff --git a/juick-ws/src/main/java/com/juick/ws/components/PushComponent.java b/juick-ws/src/main/java/com/juick/ws/components/PushComponent.java index 11e20ed4..325f4a7e 100644 --- a/juick-ws/src/main/java/com/juick/ws/components/PushComponent.java +++ b/juick-ws/src/main/java/com/juick/ws/components/PushComponent.java @@ -32,6 +32,7 @@ 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.commons.lang3.math.NumberUtils; import org.apache.http.Consts; import org.apache.http.Header; import org.apache.http.HttpResponse; @@ -59,8 +60,6 @@ import java.net.Socket; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; @@ -74,7 +73,6 @@ public class PushComponent implements InitializingBean, DisposableBean, Stream.S private static Logger logger = Logger.getLogger(PushComponent.class.getName()); - private ExecutorService executorService; String wns_application_sip; String wns_client_secret; JdbcTemplate sql; @@ -88,21 +86,17 @@ public class PushComponent implements InitializingBean, DisposableBean, Stream.S @Override public void afterPropertiesSet() { logger.info("component initialized"); - executorService = Executors.newSingleThreadExecutor(); - executorService.submit(() -> { - wns_application_sip = env.getProperty("wns_application_sip", ""); - wns_client_secret = env.getProperty("wns_client_secret", ""); - GCMSender = new Sender(env.getProperty("gcm_key")); + wns_application_sip = env.getProperty("wns_application_sip", ""); + wns_client_secret = env.getProperty("wns_client_secret", ""); + GCMSender = new Sender(env.getProperty("gcm_key")); - setupSql(env.getProperty("datasource_driver", "com.mysql.jdbc.Driver"), env.getProperty("datasource_url", "")); - setupXmppComponent(new JID("", env.getProperty("push_jid"), ""), env.getProperty("xmpp_host", "localhost"), - Integer.parseInt(env.getProperty("xmpp_port", "5347")), env.getProperty("push_xmpp_password", "")); - }); + setupSql(env.getProperty("datasource_driver", "com.mysql.jdbc.Driver"), env.getProperty("datasource_url", "")); + setupXmppComponent(new JID("", env.getProperty("push_jid"), ""), env.getProperty("xmpp_host", "localhost"), + NumberUtils.toInt(env.getProperty("xmpp_port", ""), 5347), env.getProperty("push_xmpp_password", "")); } @Override public void destroy() { - executorService.shutdown(); logger.info("component destroyed"); } |