diff options
-rw-r--r-- | src/java/com/juick/http/www/Main.java | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/src/java/com/juick/http/www/Main.java b/src/java/com/juick/http/www/Main.java index 18c7b8aa..fa4f9850 100644 --- a/src/java/com/juick/http/www/Main.java +++ b/src/java/com/juick/http/www/Main.java @@ -17,9 +17,12 @@ */ package com.juick.http.www; -import com.juick.xmpp.*; +import com.juick.xmpp.JID; +import com.juick.xmpp.Stream; +import com.juick.xmpp.StreamComponent; import java.io.FileInputStream; import java.io.IOException; +import java.net.Socket; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; @@ -36,7 +39,7 @@ import ru.sape.Sape; * @author Ugnich Anton */ @WebServlet(name = "Main", urlPatterns = {"/"}) -public class Main extends HttpServlet { +public class Main extends HttpServlet implements Stream.StreamListener { Connection sql; Connection sqlSearch; @@ -64,11 +67,8 @@ public class Main extends HttpServlet { Class.forName("com.mysql.jdbc.Driver"); sql = DriverManager.getConnection("jdbc:mysql://localhost/juick?autoReconnect=true&user=" + conf.getProperty("mysql_username", "") + "&password=" + conf.getProperty("mysql_password", "")); sqlSearch = DriverManager.getConnection("jdbc:mysql://127.0.0.1:9306?autoReconnect=true&characterEncoding=utf8&maxAllowedPacket=512000", "", ""); - /* - xmpp = new XmppConnectionComponent(new JID("www.juick.com"), conf.getProperty("xmpp_password", ""), "127.0.0.1", 5347, false); - xmpp.addListener((XmppListener) this); - xmpp.start(); - */ + + setupXmppComponent(conf.getProperty("xmpp_password")); PageTemplates.sape = new Sape(conf.getProperty("sape_user"), "juick.com", 2000, 3600); } catch (Exception e) { @@ -76,6 +76,34 @@ public class Main extends HttpServlet { } } + public void setupXmppComponent(final String password) { + Thread thr = new Thread(new Runnable() { + + @Override + public void run() { + try { + Socket socket = new Socket("localhost", 5347); + xmpp = new StreamComponent(new JID("", "www.juick.com", ""), socket.getInputStream(), socket.getOutputStream(), password); + xmpp.addListener(Main.this); + xmpp.startParsing(); + } catch (IOException e) { + System.err.println(e); + } + } + }); + thr.start(); + } + + @Override + public void onStreamFail(String msg) { + System.err.println("XMPP STREAM FAIL: " + msg); + } + + @Override + public void onStreamReady() { + System.err.println("XMPP STREAM READY"); + } + @Override public void destroy() { super.destroy(); |