From bda2d764a9c187da5aa8cd74fb8c4a9574d3996e Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 30 Mar 2018 17:52:53 +0300 Subject: xmpp integration tests --- .../main/java/com/juick/server/XMPPConnection.java | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'juick-server/src/main/java/com/juick/server/XMPPConnection.java') diff --git a/juick-server/src/main/java/com/juick/server/XMPPConnection.java b/juick-server/src/main/java/com/juick/server/XMPPConnection.java index 406294a1..40cf347a 100644 --- a/juick-server/src/main/java/com/juick/server/XMPPConnection.java +++ b/juick-server/src/main/java/com/juick/server/XMPPConnection.java @@ -36,6 +36,7 @@ import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.math.NumberUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -95,7 +96,6 @@ public class XMPPConnection implements StanzaListener, NotificationListener { private CommandsManager commandsManager; @Value("${xmppbot_jid:juick@localhost}") private Jid jid; - @Value("${componentname:localhost}") private String componentName; @Value("${component_port:5347}") @@ -201,6 +201,17 @@ public class XMPPConnection implements StanzaListener, NotificationListener { messagesService.getMessage(jmsg.getMid()))); } } + } else { + String attachment = StringUtils.EMPTY; + OobX oobX = message.getExtension(OobX.class); + if (oobX != null) { + attachment = oobX.getUri().toString(); + } + try { + serverManager.processMessage(userService.getUserByUID(NumberUtils.toInt(message.getFrom().getLocal(), 0)).orElse(new User()), message.getBody(), attachment); + } catch (Exception e1) { + logger.warn("message exception", e1); + } } } else if (jid.getDomain().endsWith(jid.getDomain()) && (jid.getDomain().equals(this.jid.getDomain()) || jid.getDomain().endsWith("." + jid.getDomain()))) { @@ -607,7 +618,11 @@ public class XMPPConnection implements StanzaListener, NotificationListener { if (username.equals(jid.getLocal())) { try { OobX oobX = msg.getExtension(OobX.class); - incomingMessageJuick(user_from, msg.getFrom(), msg.getBody().trim(), oobX.getUri()); + if (oobX != null) { + incomingMessageJuick(user_from, msg.getFrom(), msg.getBody().trim(), oobX.getUri()); + } else { + incomingMessageJuick(user_from, msg.getFrom(), msg.getBody().trim(), null); + } } catch (Exception e) { return; } @@ -669,7 +684,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener { int mid = messagesService.createMessage(user_from.getUid(), body, attachmentType, tags); subscriptionService.subscribeMessage(mid, user_from.getUid()); if (StringUtils.isNotEmpty(attachmentType)) { - String attachmentFName = attachment.getScheme().equals("juick") ? attachment.getPath() + String attachmentFName = attachment.getScheme().equals("juick") ? attachment.getHost() : HttpUtils.downloadImage(attachment.toURL(), tmpDir); String fname = String.format("%d.%s", mid, attachmentType); ImageUtils.saveImageWithPreviews(attachmentFName, fname, tmpDir, imgDir); -- cgit v1.2.3