aboutsummaryrefslogtreecommitdiff
path: root/juick-ws/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-ws/src/main/java')
-rw-r--r--juick-ws/src/main/java/com/juick/ws/XMPPConnection.java12
-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
4 files changed, 76 insertions, 66 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 77a95159c..a9bab3274 100644
--- a/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java
+++ b/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java
@@ -10,7 +10,6 @@ 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;
import org.springframework.scheduling.annotation.Async;
@@ -41,9 +40,7 @@ public class XMPPConnection implements JuickComponent, Stream.StreamListener, Me
MessageSerializer ms;
WebsocketComponent wsHandler;
- @Async
- @Override
- public void init() {
+ public XMPPConnection() {
xmppPassword = env.getProperty("xmpp_password");
ms = new MessageSerializer();
try {
@@ -52,12 +49,17 @@ public class XMPPConnection implements JuickComponent, Stream.StreamListener, Me
xmpp.addChildParser(new JuickMessage());
xmpp.addListener((Stream.StreamListener) this);
xmpp.addListener((Message.MessageListener) this);
- xmpp.startParsing();
} catch (IOException e) {
logger.log(Level.SEVERE, "XMPPConnection error", e);
}
}
+ @Async
+ @Override
+ public void init() {
+ xmpp.startParsing();
+ }
+
@Override
public void onStreamReady() {
logger.info("XMPP stream ready");
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 14d65d077..289e9809a 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 75c42b2c7..b219d9d79 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 7240769e5..fb67e5a2f 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();
}