/** * Set a hint about the message being OX-IM encrypted as body of the message. * * @param message message */ private static void setOXBodyHint(Message message) { message.setBody("This message is encrypted using XEP-0374: OpenPGP for XMPP: Instant Messaging."); }
/** * Creates a new message to the specified recipient and with the specified body. * * @param to the user to send the message to. * @param body the body of the message. */ public Message(Jid to, String body) { this(to); setBody(body); }
/** * Sets the body of the message. * * @param body the body of the message. * @see #setBody(String) * @since 4.2 */ public void setBody(CharSequence body) { String bodyString; if (body != null) { bodyString = body.toString(); } else { bodyString = null; } setBody(bodyString); }
/** * Sends a message to the chat room. * * @param text the text of the message to send. * @throws NotConnectedException * @throws InterruptedException */ public void sendMessage(String text) throws NotConnectedException, InterruptedException { Message message = createMessage(); message.setBody(text); connection.sendStanza(message); }
/** * Sends a message to the chat room. * * @param text * the text of the message to send. * @throws NotConnectedException * @throws InterruptedException */ public void sendMessage(String text) throws NotConnectedException, InterruptedException { Message message = createMessage(); message.setBody(text); connection.sendStanza(message); }
/** * Sends the specified text as a message to the other chat participant. * This is a convenience method for: * * <pre> * Message message = chat.createMessage(); * message.setBody(messageText); * chat.sendMessage(message); * </pre> * * @param text the text to send. * @throws NotConnectedException * @throws InterruptedException */ public void sendMessage(String text) throws NotConnectedException, InterruptedException { Message message = new Message(); message.setBody(text); sendMessage(message); }
private static void send(String messageString, XMPPConnection from, XMPPConnection to) throws NotConnectedException, InterruptedException { Message message = new Message(to.getUser()); message.setBody(messageString); from.sendStanza(message); }
public void send(CharSequence message) throws NotConnectedException, InterruptedException { Message stanza = new Message(); stanza.setBody(message); stanza.setType(Message.Type.chat); send(stanza); }
private static Message createChatPacket(final String threadId, final boolean isEntityFullJid) { Message chatMsg = new Message(JidTestUtil.BARE_JID_1, Message.Type.chat); chatMsg.setBody("the body message - " + System.currentTimeMillis()); Jid jid; if (isEntityFullJid) { jid = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE; } else { jid = JidTestUtil.DUMMY_AT_EXAMPLE_ORG; } chatMsg.setFrom(jid); chatMsg.setThread(threadId); return chatMsg; }
@Test public void oneMessageBodyTest() throws IOException, SAXException { final String messageBody = "This is a test of the emergency broadcast system."; StringBuilder controlBuilder = new StringBuilder(); controlBuilder.append("<message>") .append("<body>") .append(messageBody) .append("</body>") .append("</message>"); String control = controlBuilder.toString(); Message message = getNewMessage(); message.setBody(messageBody); assertEquals(messageBody, message.getBody()); assertXMLEqual(control, message.toXML(StreamOpen.CLIENT_NAMESPACE).toString()); }
/** * Return the OmemoElement wrapped in a Message ready to be sent. * The message is addressed to recipient, contains the OmemoElement * as well as an optional clear text hint as body, a MAM storage hint * and an EME hint about OMEMO encryption. * * @param recipient recipient for the to-field of the message. * @return Message */ public Message asMessage(Jid recipient) { Message messageStanza = new Message(recipient, Message.Type.chat); messageStanza.addExtension(getElement()); if (OmemoConfiguration.getAddOmemoHintBody()) { messageStanza.setBody(BODY_OMEMO_HINT); } StoreHint.set(messageStanza); messageStanza.addExtension(new ExplicitMessageEncryptionElement(OMEMO_NAMESPACE_V_AXOLOTL, OMEMO)); return messageStanza; } }
@Test public void removeMessageBodyTest() { Message message = getNewMessage(); message.setBody("test"); assertTrue(message.getBodies().size() == 1); message.setBody(null); assertTrue(message.getBodies().size() == 0); assertFalse(message.removeBody("sp")); Message.Body body = message.addBody("es", "test"); assertTrue(message.getBodies().size() == 1); message.removeBody(body); assertTrue(message.getBodies().size() == 0); }
@Test public void checkMarkableExtension() throws Exception { Message message = new Message(JidCreate.from("ingrichard@royalty.england.lit/throne")); message.setStanzaId("message-1"); message.setBody("My lord, dispatch; read o'er these articles."); message.addExtension(ChatMarkersElements.MarkableExtension.INSTANCE); Assert.assertEquals(markableMessageStanza, message.toXML(null).toString()); }
String messageId = message.setStanzaId(); final String messageBody = "Test MAM message (" + testRunId + ')'; message.setBody(messageBody);
@Test public void checkMamQueryResults() throws Exception { Message message = new Message(); message.setStanzaId("iasd207"); message.setFrom(JidCreate.from("coven@chat.shakespeare.lit")); message.setTo(JidCreate.from("hag66@shakespeare.lit/pda")); GregorianCalendar calendar = new GregorianCalendar(2002, 10 - 1, 13, 23, 58, 37); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = calendar.getTime(); DelayInformation delay = new DelayInformation(date); Message forwardedMessage = new Message(); forwardedMessage.setFrom(JidCreate.from("coven@chat.shakespeare.lit/firstwitch")); forwardedMessage.setStanzaId("162BEBB1-F6DB-4D9A-9BD8-CFDCC801A0B2"); forwardedMessage.setType(Type.chat); forwardedMessage.setBody("Thrice the brinded cat hath mew."); Forwarded forwarded = new Forwarded(delay, forwardedMessage); message.addExtension(new MamResultExtension("g27", "34482-21985-73620", forwarded)); // FIXME: The order of assertEquals is reversed, fix it by switching it. Assert.assertEquals(message.toXML(StreamOpen.CLIENT_NAMESPACE).toString(), mamQueryResultExample); MamResultExtension mamResultExtension = MamResultExtension.from(message); Assert.assertEquals(mamResultExtension.getId(), "34482-21985-73620"); Assert.assertEquals(mamResultExtension.getForwarded().getDelayInformation().getStamp(), date); Message resultMessage = (Message) mamResultExtension.getForwarded().getForwardedStanza(); Assert.assertEquals(resultMessage.getFrom(), JidCreate.from("coven@chat.shakespeare.lit/firstwitch")); Assert.assertEquals(resultMessage.getStanzaId(), "162BEBB1-F6DB-4D9A-9BD8-CFDCC801A0B2"); Assert.assertEquals(resultMessage.getType(), Type.chat); Assert.assertEquals(resultMessage.getBody(), "Thrice the brinded cat hath mew."); }
msg.setBody("Body of the chat"); addProperty(msg, "favoriteColor", "red"); addProperty(msg, "age", 30);
@Test @Ignore public void validateSmackMessageSent() throws XmppStringprepException { ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("SmackMessageSampleTest-context.xml", this.getClass()); MessageChannel xmppInput = ac.getBean("xmppInput", MessageChannel.class); org.jivesoftware.smack.packet.Message smackMessage = new org.jivesoftware.smack.packet.Message(JidCreate.from("springintegration@gmail.com")); smackMessage.setBody("Message sent as Smack Message"); Message<org.jivesoftware.smack.packet.Message> message = new GenericMessage<>(smackMessage); xmppInput.send(message); ac.close(); }
@Test public void testInboundAdapterUsageWithHeaderMapper() throws Exception { XMPPConnection xmppConnection = Mockito.mock(XMPPConnection.class); ChatMessageListeningEndpoint adapter = context.getBean("xmppInboundAdapter", ChatMessageListeningEndpoint.class); Field xmppConnectionField = ReflectionUtils.findField(ChatMessageListeningEndpoint.class, "xmppConnection"); xmppConnectionField.setAccessible(true); ReflectionUtils.setField(xmppConnectionField, adapter, xmppConnection); StanzaListener stanzaListener = TestUtils.getPropertyValue(adapter, "stanzaListener", StanzaListener.class); Message message = new Message(); message.setBody("hello"); message.setTo(JidCreate.from("oleg")); JivePropertiesManager.addProperty(message, "foo", "foo"); JivePropertiesManager.addProperty(message, "bar", "bar"); stanzaListener.processStanza(message); org.springframework.messaging.Message<?> siMessage = xmppInbound.receive(0); assertEquals("foo", siMessage.getHeaders().get("foo")); assertEquals("oleg", siMessage.getHeaders().get("xmpp_to")); }
@Test public void testWithErrorChannel() throws Exception { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); XMPPConnection connection = mock(XMPPConnection.class); bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, connection); ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint(); DirectChannel outChannel = new DirectChannel(); outChannel.subscribe(message -> { throw new RuntimeException("ooops"); }); PollableChannel errorChannel = new QueueChannel(); endpoint.setBeanFactory(bf); endpoint.setOutputChannel(outChannel); endpoint.setErrorChannel(errorChannel); endpoint.afterPropertiesSet(); StanzaListener listener = (StanzaListener) TestUtils.getPropertyValue(endpoint, "stanzaListener"); Message smackMessage = new Message(JidCreate.from("kermit@frog.com")); smackMessage.setBody("hello"); smackMessage.setThread("1234"); listener.processStanza(smackMessage); ErrorMessage msg = (ErrorMessage) errorChannel.receive(); assertEquals("hello", ((MessagingException) msg.getPayload()).getFailedMessage().getPayload()); }