aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/java/com/juick/www/Main.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-11-15 14:51:36 +0300
committerGravatar Vitaly Takmazov2016-11-15 14:51:36 +0300
commit1c65b6d29c0fc69d861ffa0e624f73981b62cca6 (patch)
treeeb0eea5841ba6114f9e21ed081d27e2988eba7e8 /juick-www/src/main/java/com/juick/www/Main.java
parent51d9de02265d6cc9d6045d79497d2a987ae2f7f7 (diff)
juick-www: ugnich xmpp -> babbler
Diffstat (limited to 'juick-www/src/main/java/com/juick/www/Main.java')
-rw-r--r--juick-www/src/main/java/com/juick/www/Main.java64
1 files changed, 19 insertions, 45 deletions
diff --git a/juick-www/src/main/java/com/juick/www/Main.java b/juick-www/src/main/java/com/juick/www/Main.java
index 4a873cf3..82f93e00 100644
--- a/juick-www/src/main/java/com/juick/www/Main.java
+++ b/juick-www/src/main/java/com/juick/www/Main.java
@@ -17,18 +17,18 @@
*/
package com.juick.www;
+import com.juick.Message;
import com.juick.server.UserQueries;
-import com.juick.xmpp.JID;
-import com.juick.xmpp.Stream;
-import com.juick.xmpp.StreamComponent;
import com.mitchellbosecke.pebble.error.PebbleException;
-import net.jodah.failsafe.Execution;
-import net.jodah.failsafe.RetryPolicy;
import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.xmlpull.v1.XmlPullParserException;
+import rocks.xmpp.addr.Jid;
+import rocks.xmpp.core.XmppException;
+import rocks.xmpp.core.session.Extension;
+import rocks.xmpp.core.session.XmppSessionConfiguration;
+import rocks.xmpp.extensions.component.accept.ExternalComponent;
import ru.sape.Sape;
import javax.servlet.ServletException;
@@ -38,14 +38,10 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import java.net.Socket;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.util.Objects;
import java.util.Properties;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
/**
*
@@ -53,12 +49,12 @@ import java.util.concurrent.TimeUnit;
*/
@WebServlet(name = "Main", urlPatterns = {"/"})
@MultipartConfig(fileSizeThreshold = 1024 * 1024, maxRequestSize = 1024 * 1024 * 10)
-public class Main extends HttpServlet implements Stream.StreamListener {
+public class Main extends HttpServlet {
JdbcTemplate sql;
JdbcTemplate sqlSearch;
String sqlSearchConnStr = "jdbc:mysql://127.0.0.1:9306?autoReconnect=true&useUnicode=yes&characterEncoding=utf8&maxAllowedPacket=512000";
- Stream xmpp;
+ ExternalComponent xmpp;
Home home = new Home();
Discover discover = new Discover();
PM pm = new PM();
@@ -73,8 +69,6 @@ public class Main extends HttpServlet implements Stream.StreamListener {
SignUp signup = new SignUp();
Settings settings;
RSS rss = new RSS();
- ExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
- Execution execution;
@Override
public void init() throws ServletException {
@@ -94,7 +88,7 @@ public class Main extends HttpServlet implements Stream.StreamListener {
sqlSearch = new JdbcTemplate(dataSourceSearch);
boolean isXmppDisabled = BooleanUtils.toBoolean(conf.getProperty("xmpp_disabled"));
if (!isXmppDisabled) {
- setupXmppComponent(new JID(conf.getProperty("www_xmpp_jid", "www.juick.local")),
+ setupXmppComponent(Jid.of(conf.getProperty("www_xmpp_jid", "www.juick.local")),
conf.getProperty("xmpp_password"), NumberUtils.toInt(conf.getProperty("xmpp_port", ""), 5347));
}
twitterAuth = new TwitterAuth(conf.getProperty("twitter_consumer_key"),
@@ -116,38 +110,18 @@ public class Main extends HttpServlet implements Stream.StreamListener {
}
}
- public void setupXmppComponent(final JID componentJid, final String password, final int port) {
- @SuppressWarnings("unchecked") RetryPolicy retryPolicy = new RetryPolicy()
- .withBackoff(1, 30, TimeUnit.SECONDS)
- .withJitter(0.1)
- .retryOn(IOException.class, XmlPullParserException.class);
- execution = new Execution(retryPolicy);
- executorService.submit(() -> {
- while (!execution.isComplete()) {
- try {
- Socket socket = new Socket("localhost", port);
- xmpp = new StreamComponent(componentJid, socket.getInputStream(), socket.getOutputStream(), password);
- xmpp.addListener(Main.this);
- xmpp.startParsing();
- } catch (IOException e) {
- log("XMPP router disconnected, reconnecting...");
- }
- }
- });
- }
-
- @Override
- public void onStreamFail(Exception e) {
- log("XMPP STREAM FAIL:" + e);
- execution.recordFailure(e);
- }
-
- @Override
- public void onStreamReady() {
- log("XMPP STREAM READY");
+ public void setupXmppComponent(final Jid componentJid, final String password, final int port) {
+ XmppSessionConfiguration configuration = XmppSessionConfiguration.builder()
+ .extensions(Extension.of(Message.class))
+ .build();
+ xmpp = ExternalComponent.create(componentJid.toString(), password, configuration, "localhost", port);
+ try {
+ xmpp.connect();
+ } catch (XmppException e) {
+ log("xmpp extension", e);
+ }
}
-
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request