aboutsummaryrefslogtreecommitdiff
path: root/juick-ws/src/main/java/com/juick/ws/components
diff options
context:
space:
mode:
Diffstat (limited to 'juick-ws/src/main/java/com/juick/ws/components')
-rw-r--r--juick-ws/src/main/java/com/juick/ws/components/CrosspostComponent.java11
-rw-r--r--juick-ws/src/main/java/com/juick/ws/components/PushComponent.java10
-rw-r--r--juick-ws/src/main/java/com/juick/ws/components/XMPPComponent.java109
3 files changed, 69 insertions, 61 deletions
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 14d65d07..289e9809 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
@@ -66,9 +66,7 @@ public class CrosspostComponent implements JuickComponent, DisposableBean, Strea
@Inject
Environment env;
- @Async
- @Override
- public void init() {
+ public CrosspostComponent() {
logger.info("component initialized");
try {
twitter_consumer_key = env.getProperty("twitter_consumer_key", "");
@@ -82,6 +80,12 @@ public class CrosspostComponent implements JuickComponent, DisposableBean, Strea
}
}
+ @Async
+ @Override
+ public void init() {
+ xmpp.startParsing();
+ }
+
@Override
public void destroy() {
logger.info("component destroyed");
@@ -101,7 +105,6 @@ public class CrosspostComponent implements JuickComponent, DisposableBean, Strea
xmpp.addChildParser(new JuickMessage());
xmpp.addListener((Stream.StreamListener) this);
xmpp.addListener((Message.MessageListener) this);
- xmpp.startParsing();
} catch (IOException e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}
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 75c42b2c..b219d9d7 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
@@ -82,9 +82,7 @@ public class PushComponent implements JuickComponent, DisposableBean, Stream.Str
@Inject
Environment env;
- @Async
- @Override
- public void init() {
+ public PushComponent() {
logger.info("component initialized");
wns_application_sip = env.getProperty("wns_application_sip", "");
wns_client_secret = env.getProperty("wns_client_secret", "");
@@ -95,6 +93,12 @@ public class PushComponent implements JuickComponent, DisposableBean, Stream.Str
NumberUtils.toInt(env.getProperty("xmpp_port", ""), 5347), env.getProperty("push_xmpp_password", ""));
}
+ @Async
+ @Override
+ public void init() {
+ xmpp.startParsing();
+ }
+
@Override
public void destroy() {
logger.info("component destroyed");
diff --git a/juick-ws/src/main/java/com/juick/ws/components/XMPPComponent.java b/juick-ws/src/main/java/com/juick/ws/components/XMPPComponent.java
index 7240769e..fb67e5a2 100644
--- a/juick-ws/src/main/java/com/juick/ws/components/XMPPComponent.java
+++ b/juick-ws/src/main/java/com/juick/ws/components/XMPPComponent.java
@@ -62,6 +62,60 @@ public class XMPPComponent implements JuickComponent, DisposableBean, Stream.Str
@Inject
Environment env;
+ public XMPPComponent() {
+ logger.info("component initialized");
+ try {
+ HOSTNAME = env.getProperty("hostname");
+ componentName = env.getProperty("componentname");
+ int componentPort = NumberUtils.toInt(env.getProperty("component_port"), 5347);
+ int s2sPort = NumberUtils.toInt(env.getProperty("s2s_port"), 5269);
+ JID Jid = new JID(env.getProperty("xmppbot_jid"));
+ STATSFILE = env.getProperty("statsfile");
+ keystore = env.getProperty("keystore");
+ keystorePassword = env.getProperty("keystore_password");
+ brokenSSLhosts = Arrays.asList(env.getProperty("broken_ssl_hosts", "").split(","));
+ bannedHosts = Arrays.asList(env.getProperty("banned_hosts", "").split(","));
+ BasicDataSource dataSource = new BasicDataSource();
+ dataSource.setDriverClassName(env.getProperty("datasource_driver", "com.mysql.jdbc.Driver"));
+ dataSource.setUrl(env.getProperty("datasource_url"));
+ setSql(new JdbcTemplate(dataSource));
+ bot = new JuickBot(this, Jid);
+
+ childParsers.put(JuickMessage.XMLNS, new JuickMessage());
+
+ Socket routerSocket = null;
+ try {
+ routerSocket = new Socket("localhost", componentPort);
+ setRouter(new StreamComponent(new JID("s2s"), routerSocket.getInputStream(), routerSocket.getOutputStream(), env.getProperty("xmpp_password")));
+ getRouter().addChildParser(new JuickMessage());
+ getRouter().addListener((Stream.StreamListener) this);
+ getRouter().addListener((Message.MessageListener) this);
+ getRouter().addListener((Iq.IqListener) this);
+
+ } catch (IOException e) {
+ logger.log(Level.SEVERE, "router error", e);
+ }
+ executorService.submit(() -> {
+ final ServerSocket listener = new ServerSocket(s2sPort);
+ logger.info("s2s listener ready");
+ while (true) {
+ try {
+ Socket socket = listener.accept();
+ ConnectionIn client = new ConnectionIn(this, bot, socket);
+ addConnectionIn(client);
+ executorService.submit(client);
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "s2s error", e);
+ }
+ }
+ });
+ executorService.submit(new CleaningUp(this));
+
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "XMPPComponent error", e);
+ }
+ }
+
public void addConnectionIn(ConnectionIn c) {
synchronized (getInConnections()) {
getInConnections().add(c);
@@ -181,60 +235,7 @@ public class XMPPComponent implements JuickComponent, DisposableBean, Stream.Str
@Async
@Override
public void init() {
-
- logger.info("component initialized");
- try {
- HOSTNAME = env.getProperty("hostname");
- componentName = env.getProperty("componentname");
- int componentPort = NumberUtils.toInt(env.getProperty("component_port"), 5347);
- int s2sPort = NumberUtils.toInt(env.getProperty("s2s_port"), 5269);
- JID Jid = new JID(env.getProperty("xmppbot_jid"));
- STATSFILE = env.getProperty("statsfile");
- keystore = env.getProperty("keystore");
- keystorePassword = env.getProperty("keystore_password");
- brokenSSLhosts = Arrays.asList(env.getProperty("broken_ssl_hosts", "").split(","));
- bannedHosts = Arrays.asList(env.getProperty("banned_hosts", "").split(","));
- BasicDataSource dataSource = new BasicDataSource();
- dataSource.setDriverClassName(env.getProperty("datasource_driver", "com.mysql.jdbc.Driver"));
- dataSource.setUrl(env.getProperty("datasource_url"));
- setSql(new JdbcTemplate(dataSource));
- bot = new JuickBot(this, Jid);
-
- childParsers.put(JuickMessage.XMLNS, new JuickMessage());
-
- executorService.submit(() -> {
- Socket routerSocket = null;
- try {
- routerSocket = new Socket("localhost", componentPort);
- setRouter(new StreamComponent(new JID("s2s"), routerSocket.getInputStream(), routerSocket.getOutputStream(), env.getProperty("xmpp_password")));
- getRouter().addChildParser(new JuickMessage());
- getRouter().addListener((Stream.StreamListener) this);
- getRouter().addListener((Message.MessageListener) this);
- getRouter().addListener((Iq.IqListener) this);
- getRouter().startParsing();
- } catch (IOException e) {
- logger.log(Level.SEVERE, "router error", e);
- }
- });
- executorService.submit(() -> {
- final ServerSocket listener = new ServerSocket(s2sPort);
- logger.info("s2s listener ready");
- while (true) {
- try {
- Socket socket = listener.accept();
- ConnectionIn client = new ConnectionIn(this, bot, socket);
- addConnectionIn(client);
- executorService.submit(client);
- } catch (Exception e) {
- logger.log(Level.SEVERE, "s2s error", e);
- }
- }
- });
- executorService.submit(new CleaningUp(this));
-
- } catch (Exception e) {
- logger.log(Level.SEVERE, "XMPPComponent error", e);
- }
+ getRouter().startParsing();
}