aboutsummaryrefslogtreecommitdiff
path: root/juick-ws
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-11-30 00:27:23 +0300
committerGravatar Vitaly Takmazov2016-11-30 00:27:23 +0300
commit3e783602987483bbd2ee5791020894891d39b016 (patch)
tree14c710bd9929aa69d3b3a0b8a74fc41852a8ac25 /juick-ws
parenta0414bcd43b5b07018fcd3ba0013c0ea11e26552 (diff)
juick-ws: update to data services
Diffstat (limited to 'juick-ws')
-rw-r--r--juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java22
-rw-r--r--juick-ws/src/main/java/com/juick/ws/XMPPConnection.java22
-rw-r--r--juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java10
-rw-r--r--juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java2
4 files changed, 27 insertions, 29 deletions
diff --git a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java b/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java
index 9704b463..831d16f1 100644
--- a/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java
+++ b/juick-ws/src/main/java/com/juick/ws/WebsocketComponent.java
@@ -1,19 +1,18 @@
package com.juick.ws;
import com.juick.User;
-import com.juick.server.MessagesQueries;
-import com.juick.server.UserQueries;
+import com.juick.service.MessagesService;
+import com.juick.service.UserService;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.util.Assert;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;
+import javax.inject.Inject;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
@@ -26,15 +25,12 @@ import java.util.List;
public class WebsocketComponent extends TextWebSocketHandler {
private static final Logger logger = LoggerFactory.getLogger(WebsocketComponent.class);
- private JdbcTemplate jdbc;
-
private final List<SocketSubscribed> clients = Collections.synchronizedList(new ArrayList<SocketSubscribed>());
-
- public WebsocketComponent(JdbcTemplate jdbc) {
- Assert.notNull(jdbc);
- this.jdbc = jdbc;
- }
+ @Inject
+ UserService userService;
+ @Inject
+ MessagesService messagesService;
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
@@ -53,7 +49,7 @@ public class WebsocketComponent extends TextWebSocketHandler {
if (param.getName().equals("hash")) {
String hash = param.getValue();
if (hash.length() == 16) {
- visitor = UserQueries.getUserByHash(jdbc, hash);
+ visitor = userService.getUserByHash(hash);
} else {
try {
logger.info(String.format("wrong hash for %d from %s", visitor.getUid(), hXRealIP));
@@ -86,7 +82,7 @@ public class WebsocketComponent extends TextWebSocketHandler {
} catch (Exception e) {
}
if (MID > 0) {
- if (MessagesQueries.canViewThread(jdbc, MID, visitor.getUid())) {
+ if (messagesService.canViewThread(MID, visitor.getUid())) {
logger.info(String.format("user %d connected to legacy thread (%d) from %s", visitor.getUid(), MID, hXRealIP));
sockSubscr = new SocketSubscribed(session, hXRealIP, visitor, true);
sockSubscr.MID = MID;
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 6bec6efa..b75ca998 100644
--- a/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java
+++ b/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java
@@ -4,13 +4,12 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.juick.User;
-import com.juick.server.MessagesQueries;
-import com.juick.server.SubscriptionsQueries;
+import com.juick.service.MessagesService;
+import com.juick.service.SubscriptionService;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
-import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.Assert;
import org.springframework.web.socket.TextMessage;
import rocks.xmpp.core.XmppException;
@@ -21,6 +20,7 @@ import rocks.xmpp.core.session.debug.LogbackDebugger;
import rocks.xmpp.core.stanza.model.Message;
import rocks.xmpp.extensions.component.accept.ExternalComponent;
+import javax.inject.Inject;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
@@ -31,7 +31,6 @@ import java.util.stream.Collectors;
public class XMPPConnection implements AutoCloseable {
private static final Logger logger = LoggerFactory.getLogger(XMPPConnection.class);
- private final JdbcTemplate jdbc;
private final WebsocketComponent wsHandler;
private final String xmppPassword;
private final ObjectMapper ms;
@@ -40,15 +39,18 @@ public class XMPPConnection implements AutoCloseable {
private XmppSession xmpp;
+ @Inject
+ MessagesService messagesService;
+ @Inject
+ SubscriptionService subscriptionService;
+
public XMPPConnection(
- final Environment env, final WebsocketComponent wsHandler, final JdbcTemplate jdbc) {
+ final Environment env, final WebsocketComponent wsHandler) {
Assert.notNull(env);
Assert.notNull(wsHandler);
- Assert.notNull(jdbc);
this.wsHandler = wsHandler;
- this.jdbc = jdbc;
xmppPassword = env.getProperty("xmpp_password");
xmppPort = NumberUtils.toInt(env.getProperty("xmpp_port"), 5347);
@@ -76,7 +78,7 @@ public class XMPPConnection implements AutoCloseable {
onJuickMessagePost(jmsg);
} else {
// to get quote
- com.juick.Message reply = MessagesQueries.getReply(jdbc, jmsg.getMid(), jmsg.getRid());
+ com.juick.Message reply = messagesService.getReply(jmsg.getMid(), jmsg.getRid());
onJuickMessageReply(reply);
}
}
@@ -115,7 +117,7 @@ public class XMPPConnection implements AutoCloseable {
private void onJuickMessagePost(final com.juick.Message jmsg) throws JsonProcessingException {
String json = ms.writeValueAsString(jmsg);
- List<Integer> uids = SubscriptionsQueries.getSubscribedUsers(jdbc, jmsg.getUser().getUid(), jmsg.getMid())
+ List<Integer> uids = subscriptionService.getSubscribedUsers(jmsg.getUser().getUid(), jmsg.getMid())
.stream().map(User::getUid).collect(Collectors.toList());
synchronized (wsHandler.getClients()) {
wsHandler.getClients().stream().filter(c ->
@@ -145,7 +147,7 @@ public class XMPPConnection implements AutoCloseable {
private void onJuickMessageReply(final com.juick.Message jmsg) throws JsonProcessingException {
String json = ms.writeValueAsString(jmsg);
List<Integer> threadUsers =
- SubscriptionsQueries.getUsersSubscribedToComments(jdbc, jmsg.getMid(), jmsg.getUser().getUid())
+ subscriptionService.getUsersSubscribedToComments(jmsg.getMid(), jmsg.getUser().getUid())
.stream().map(User::getUid).collect(Collectors.toList());
synchronized (wsHandler.getClients()) {
wsHandler.getClients().stream().filter(c ->
diff --git a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java
index e7f0042e..4c20001a 100644
--- a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java
+++ b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java
@@ -1,12 +1,13 @@
package com.juick.ws.configuration;
+import com.juick.configuration.DataConfiguration;
import com.juick.ws.WebsocketComponent;
import com.juick.ws.XMPPConnection;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
-import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.ServletWebSocketHandlerRegistry;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
@@ -21,20 +22,19 @@ import javax.inject.Inject;
@Configuration
@EnableWebSocket
@PropertySource("classpath:juick.conf")
+@Import(DataConfiguration.class)
class WebsocketConfiguration implements WebSocketConfigurer {
@Inject
private Environment env;
- @Inject
- private JdbcTemplate jdbc;
@Bean
public WebsocketComponent wsHandler() {
- return new WebsocketComponent(jdbc);
+ return new WebsocketComponent();
}
@Bean
public XMPPConnection ws() {
- return new XMPPConnection(env, wsHandler(), jdbc);
+ return new XMPPConnection(env, wsHandler());
}
@Override
diff --git a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java
index 751da635..a754f1a9 100644
--- a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java
+++ b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketInitializer.java
@@ -13,7 +13,7 @@ public class WebsocketInitializer extends AbstractAnnotationConfigDispatcherServ
@Override
protected Class<?>[] getRootConfigClasses() {
- return new Class<?>[]{DataConfiguration.class, WebsocketConfiguration.class};
+ return new Class<?>[]{WebsocketConfiguration.class};
}
@Override