From 1c65b6d29c0fc69d861ffa0e624f73981b62cca6 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Tue, 15 Nov 2016 14:51:36 +0300
Subject: juick-www: ugnich xmpp -> babbler
---
juick-www/build.gradle | 9 +-
juick-www/src/main/java/com/juick/www/Main.java | 64 ++++---------
.../src/main/java/com/juick/www/NewMessage.java | 102 ++++++++++-----------
juick-www/src/main/java/com/juick/www/PM.java | 31 +++----
4 files changed, 86 insertions(+), 120 deletions(-)
diff --git a/juick-www/build.gradle b/juick-www/build.gradle
index 1bed582b..c6c2b637 100644
--- a/juick-www/build.gradle
+++ b/juick-www/build.gradle
@@ -3,9 +3,6 @@ buildscript {
mavenCentral()
jcenter()
}
- dependencies {
- classpath 'com.tkruse.gradle:gradle-groovysh-plugin:1.0.8'
- }
}
plugins {
@@ -20,21 +17,21 @@ apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'org.akhikhl.gretty'
apply plugin: 'com.github.ben-manes.versions'
-apply plugin: 'com.github.tkruse.groovysh'
repositories {
mavenCentral()
+ maven { url "https://jitpack.io" }
}
def springFrameworkVersion = '4.3.4.RELEASE'
dependencies {
compile project(':server-core')
- compile project(':deps:com.juick.xmpp')
+ compile 'org.bitbucket.sco0ter.babbler:xmpp-core-client:279e488e51'
+ compile 'org.bitbucket.sco0ter.babbler:xmpp-extensions-client:279e488e51'
compile 'com.github.scribejava:scribejava-apis:3.2.0'
compile 'net.coobird:thumbnailator:0.4.8'
compile 'com.github.ooxi:serialized-php-parser:0.5.0'
- compile 'net.jodah:failsafe:0.9.5'
compile 'com.mitchellbosecke:pebble:2.2.3'
compile 'com.sun.mail:javax.mail:1.5.6'
compile "org.springframework:spring-webmvc:${springFrameworkVersion}"
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 GET
method.
* @param request servlet request
diff --git a/juick-www/src/main/java/com/juick/www/NewMessage.java b/juick-www/src/main/java/com/juick/www/NewMessage.java
index 310ede73..29c834d6 100644
--- a/juick-www/src/main/java/com/juick/www/NewMessage.java
+++ b/juick-www/src/main/java/com/juick/www/NewMessage.java
@@ -19,19 +19,17 @@ package com.juick.www;
import com.juick.Tag;
import com.juick.server.*;
-import com.juick.xmpp.JID;
-import com.juick.xmpp.Message;
-import com.juick.xmpp.Stream;
-import com.juick.xmpp.extensions.JuickMessage;
-import com.juick.xmpp.extensions.JuickUser;
-import com.juick.xmpp.extensions.Nickname;
-import com.juick.xmpp.extensions.XOOB;
import net.coobird.thumbnailator.Thumbnails;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
+import rocks.xmpp.addr.Jid;
+import rocks.xmpp.core.session.XmppSession;
+import rocks.xmpp.core.stanza.model.Message;
+import rocks.xmpp.extensions.nick.model.Nickname;
+import rocks.xmpp.extensions.oob.model.x.OobX;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@@ -39,6 +37,8 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.file.Files;
@@ -148,7 +148,7 @@ public class NewMessage {
out.println("