aboutsummaryrefslogtreecommitdiff
path: root/juick-ws/src/main/java/com
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-11-28 14:37:02 +0300
committerGravatar Vitaly Takmazov2016-11-28 14:37:02 +0300
commit5b2bd7f928bbf9d3233ff029ed5c09ac46daf0de (patch)
treecfad7f15e35c51d11a488df5a9b2be5300b9af54 /juick-ws/src/main/java/com
parentc252087c54e91e63f89775eba4c65cf87ae21e5d (diff)
all components using jackson now, org.json serializer moved to compatibility tests package
Diffstat (limited to 'juick-ws/src/main/java/com')
-rw-r--r--juick-ws/src/main/java/com/juick/ws/XMPPConnection.java54
1 files changed, 29 insertions, 25 deletions
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 30dad3f3..2019ec0a 100644
--- a/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java
+++ b/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java
@@ -1,7 +1,9 @@
package com.juick.ws;
+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.json.MessageSerializer;
import com.juick.server.MessagesQueries;
import com.juick.server.SubscriptionsQueries;
import org.apache.commons.lang3.math.NumberUtils;
@@ -31,7 +33,7 @@ public class XMPPConnection implements AutoCloseable {
private final JdbcTemplate jdbc;
private final WebsocketComponent wsHandler;
private final String xmppPassword;
- private final MessageSerializer ms;
+ private final ObjectMapper ms;
private final int xmppPort;
private final String wsJid;
@@ -51,29 +53,33 @@ public class XMPPConnection implements AutoCloseable {
xmppPort = NumberUtils.toInt(env.getProperty("xmpp_port"), 5347);
wsJid = env.getProperty("ws_jid", "ws.juick.local");
- ms = new MessageSerializer();
+ ms = new XmlMapper();
XmppSessionConfiguration configuration = XmppSessionConfiguration.builder()
.extensions(Extension.of(com.juick.Message.class))
.build();
xmpp = ExternalComponent.create(wsJid, xmppPassword, configuration, "localhost", xmppPort);
xmpp.addInboundMessageListener(e -> {
- Message msg = e.getMessage();
- com.juick.Message jmsg = msg.getExtension(com.juick.Message.class);
- if (jmsg != null) {
- logger.info("got msg: " + ms.serialize(jmsg).toString());
- if (jmsg.getMid() == 0) {
- int uid_to = NumberUtils.toInt(msg.getTo().getLocal(), 0);
- if (uid_to > 0) {
- onJuickPM(uid_to, jmsg);
+ try {
+ Message msg = e.getMessage();
+ com.juick.Message jmsg = msg.getExtension(com.juick.Message.class);
+ if (jmsg != null) {
+ logger.info("got msg: " + ms.writeValueAsString(jmsg));
+ if (jmsg.getMid() == 0) {
+ int uid_to = NumberUtils.toInt(msg.getTo().getLocal(), 0);
+ if (uid_to > 0) {
+ onJuickPM(uid_to, jmsg);
+ }
+ } else if (jmsg.getRid() == 0) {
+ onJuickMessagePost(jmsg);
+ } else {
+ // to get quote
+ com.juick.Message reply = MessagesQueries.getReply(jdbc, jmsg.getMid(), jmsg.getRid());
+ onJuickMessageReply(reply);
}
- } else if (jmsg.getRid() == 0) {
- onJuickMessagePost(jmsg);
- } else {
- // to get quote
- com.juick.Message reply = MessagesQueries.getReply(jdbc, jmsg.getMid(), jmsg.getRid());
- onJuickMessageReply(reply);
}
+ } catch (JsonProcessingException ex) {
+ logger.error("mapper exception", ex);
}
});
try {
@@ -91,10 +97,8 @@ public class XMPPConnection implements AutoCloseable {
logger.info("XmppSession on WS destroyed");
}
- MessageSerializer messageSerializer = new MessageSerializer();
-
- private void onJuickPM(final int uid_to, final com.juick.Message jmsg) {
- String json = messageSerializer.serialize(jmsg).toString();
+ private void onJuickPM(final int uid_to, final com.juick.Message jmsg) throws JsonProcessingException {
+ String json = ms.writeValueAsString(jmsg);
synchronized (wsHandler.getClients()) {
wsHandler.getClients().stream().filter(c -> !c.legacy && c.visitor.getUid() == uid_to).forEach(c -> {
try {
@@ -107,8 +111,8 @@ public class XMPPConnection implements AutoCloseable {
}
}
- private void onJuickMessagePost(final com.juick.Message jmsg) {
- String json = messageSerializer.serialize(jmsg).toString();
+ 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())
.stream().map(User::getUid).collect(Collectors.toList());
synchronized (wsHandler.getClients()) {
@@ -136,8 +140,8 @@ public class XMPPConnection implements AutoCloseable {
}
}
- private void onJuickMessageReply(final com.juick.Message jmsg) {
- String json = messageSerializer.serialize(jmsg).toString();
+ 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())
.stream().map(User::getUid).collect(Collectors.toList());