aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/http/www/Main.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/http/www/Main.java')
-rw-r--r--src/main/java/com/juick/http/www/Main.java83
1 files changed, 12 insertions, 71 deletions
diff --git a/src/main/java/com/juick/http/www/Main.java b/src/main/java/com/juick/http/www/Main.java
index 36376d3c..08b92305 100644
--- a/src/main/java/com/juick/http/www/Main.java
+++ b/src/main/java/com/juick/http/www/Main.java
@@ -17,17 +17,10 @@
*/
package com.juick.http.www;
-import com.juick.CrosspostComponent;
-import com.juick.JuickComponent;
-import com.juick.JuickNotificator;
-import com.juick.PushComponent;
+import com.juick.JuickApplication;
import com.juick.server.UserQueries;
-import com.juick.xmpp.JID;
import com.juick.xmpp.Stream;
-import com.juick.xmpp.StreamComponent;
-import com.juick.xmpp.s2s.S2SComponent;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.datasource.DriverManagerDataSource;
import ru.sape.Sape;
import javax.servlet.ServletException;
@@ -37,20 +30,13 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import java.net.InetSocketAddress;
import java.net.URLEncoder;
-import java.nio.channels.AsynchronousSocketChannel;
-import java.nio.channels.Channels;
-import java.nio.channels.CompletionHandler;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
-import java.util.ArrayList;
import java.util.Enumeration;
-import java.util.List;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
/**
*
@@ -58,7 +44,7 @@ import java.util.concurrent.Executors;
*/
@WebServlet(name = "Main", urlPatterns = {"/"})
@MultipartConfig(fileSizeThreshold = 1024 * 1024, maxRequestSize = 1024 * 1024 * 10)
-public class Main extends HttpServlet implements JuickNotificator, Stream.StreamListener {
+public class Main extends HttpServlet implements Stream.StreamListener {
static ExecutorService executorService;
JdbcTemplate sql;
JdbcTemplate sqlSearch;
@@ -70,14 +56,14 @@ public class Main extends HttpServlet implements JuickNotificator, Stream.Stream
Help help = new Help();
User pagesUser = new User();
UserThread pagesUserThread = new UserThread();
- NewMessage pagesNewMessage = new NewMessage();
+ NewMessage pagesNewMessage;
FacebookLogin loginFacebook = new FacebookLogin();
VKontakteLogin loginVK = new VKontakteLogin();
TwitterAuth twitterAuth;
SignUp signup = new SignUp();
Settings settings = new Settings();
RSS rss = new RSS();
- static List<JuickComponent> components = new ArrayList<>();
+ JuickApplication app;
@Override
public void init() throws ServletException {
@@ -86,64 +72,19 @@ public class Main extends HttpServlet implements JuickNotificator, Stream.Stream
try {
Properties conf = new Properties();
conf.load(getServletContext().getResourceAsStream("WEB-INF/juick.conf"));
-
- executorService = Executors.newWorkStealingPool();
- getServletContext().setAttribute("es", executorService);
-
- DriverManagerDataSource dataSource = new DriverManagerDataSource();
- dataSource.setDriverClassName(conf.getProperty("datasource_driver", "com.mysql.jdbc.Driver"));
- dataSource.setUrl(conf.getProperty("datasource_url"));
- sql = new JdbcTemplate(dataSource);
- getServletContext().setAttribute("sql", sql);
- DriverManagerDataSource searchDatasource = new DriverManagerDataSource();
- searchDatasource.setDriverClassName("com.mysql.jdbc.Driver");
- searchDatasource.setUrl("jdbc:mysql://127.0.0.1:9306?autoReconnect=true&useUnicode=yes&characterEncoding=utf8&maxAllowedPacket=512000");
- sqlSearch = new JdbcTemplate(searchDatasource);
- getServletContext().setAttribute("sqlSearch", sqlSearch);
- setupXmppComponent(conf.getProperty("xmpp_password"));
twitterAuth = new TwitterAuth(conf.getProperty("twitter_consumer_key"),
conf.getProperty("twitter_consumer_secret"));
PageTemplates.sape = new Sape(conf.getProperty("sape_user"), "juick.com", 2000, 3600);
- components.add(new S2SComponent(sql, executorService, conf));
- components.add(new CrosspostComponent(sql, conf));
- components.add(new PushComponent(sql, conf));
+ app = new JuickApplication(conf);
+ sql = app.getSql();
+ sqlSearch = app.getSqlSearch();
+ pagesNewMessage = new NewMessage(app);
} catch (Exception e) {
log("www failed", e);
}
}
@Override
- public void push(com.juick.xmpp.Message msg) {
- for (JuickComponent c : components) {
- c.messageReceived(msg);
- }
- }
-
- public void setupXmppComponent(final String password) {
- executorService.submit(() -> {
- try {
- AsynchronousSocketChannel socket = AsynchronousSocketChannel.open();
- socket.connect(new InetSocketAddress("localhost", 5347), socket, new CompletionHandler<Void, AsynchronousSocketChannel>() {
- @Override
- public void completed(Void result, AsynchronousSocketChannel attachment) {
- xmpp = new StreamComponent(new JID("", "www.juick.com", ""), Channels.newInputStream(socket),
- Channels.newOutputStream(socket), password);
- xmpp.addListener(Main.this);
- xmpp.startParsing();
- }
-
- @Override
- public void failed(Throwable exc, AsynchronousSocketChannel attachment) {
- log("www xmpp failed");
- }
- });
- } catch (IOException e) {
- log("xmpp exception", e);
- }
- });
- }
-
- @Override
public void onStreamFail(Exception e) {log("XMPP STREAM FAIL", e);}
@Override
@@ -177,7 +118,7 @@ public class Main extends HttpServlet implements JuickNotificator, Stream.Stream
} else if (uri.equals("/post")) {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (visitor != null) {
- pagesNewMessage.doGetNewMessage(sql, request, response, visitor);
+ pagesNewMessage.doGetNewMessage(request, response, visitor);
} else {
Utils.sendTemporaryRedirect(response, "/login");
}
@@ -312,21 +253,21 @@ public class Main extends HttpServlet implements JuickNotificator, Stream.Stream
if (uri.equals("/post")) {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (visitor != null && !visitor.Banned) {
- pagesNewMessage.doPostMessage(sql, request, response, xmpp, visitor);
+ pagesNewMessage.doPostMessage(request, response, visitor);
} else {
response.sendError(403);
}
} else if (uri.equals("/comment")) {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (visitor != null && !visitor.Banned) {
- pagesNewMessage.doPostComment(sql, request, response, xmpp, visitor);
+ pagesNewMessage.doPostComment(request, response, visitor);
} else {
response.sendError(403);
}
} else if (uri.equals("/like")) {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (visitor != null && !visitor.Banned) {
- pagesNewMessage.doPostRecomm(sql, request, response, xmpp, visitor);
+ pagesNewMessage.doPostRecomm(request, response, visitor);
} else {
response.sendError(403);
}