/** * Delivers a message directly to this chat, which will add the message * to the collector and deliver it to all listeners registered with the * Chat. This is used by the XMPPConnection class to deliver messages * without a thread ID. * * @param message the message. */ void deliver(Message message) { // Because the collector and listeners are expecting a thread ID with // a specific value, set the thread ID on the message even though it // probably never had one. message.setThread(threadID); for (ChatMessageListener listener : listeners) { listener.processMessage(this, message); } }
/** * Sends a message to the other chat participant. The thread ID, recipient, * and message type of the message will automatically set to those of this chat. * * @param message the message to send. * @throws NotConnectedException * @throws InterruptedException */ public void sendMessage(Message message) throws NotConnectedException, InterruptedException { // Force the recipient, message type, and thread ID since the user elected // to send the message through this chat object. message.setTo(participant); message.setType(Message.Type.chat); message.setThread(threadID); chatManager.sendMessage(this, message); }
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 setMessageThreadTest() throws IOException, SAXException { final String messageThread = "1234"; StringBuilder controlBuilder = new StringBuilder(); controlBuilder.append("<message>") .append("<thread>") .append(messageThread) .append("</thread>") .append("</message>"); String control = controlBuilder.toString(); Message message = getNewMessage(); message.setThread(messageThread); assertEquals(messageThread, message.getThread()); assertXMLEqual(control, message.toXML(StreamOpen.CLIENT_NAMESPACE).toString()); }
reply.setThread(original.getThread());
message.setThread(thread);
msg2.setThread(msg.getThread()); msg2.setType(Message.Type.chat); msg2.setBody("To enter a case please fill out this form and send it back to me");
String threadId = getHeaderIfAvailable(headers, XmppHeaders.THREAD, String.class); if (StringUtils.hasText(threadId)) { target.setThread(threadId);
@Test public void toHeadersStandardOnly() throws XmppStringprepException { DefaultXmppHeaderMapper mapper = new DefaultXmppHeaderMapper(); Message source = new Message(JidCreate.from("test.to"), Message.Type.headline); source.setFrom(JidCreate.from("test.from")); source.setSubject("test.subject"); source.setThread("test.thread"); JivePropertiesManager.addProperty(source, "userDefined1", "foo"); JivePropertiesManager.addProperty(source, "userDefined2", "bar"); Map<String, Object> headers = mapper.toHeadersFromRequest(source); assertEquals("test.to", headers.get(XmppHeaders.TO).toString()); assertEquals("test.from", headers.get(XmppHeaders.FROM).toString()); assertEquals("test.subject", headers.get(XmppHeaders.SUBJECT)); assertEquals("test.thread", headers.get(XmppHeaders.THREAD)); assertEquals(Message.Type.headline, headers.get(XmppHeaders.TYPE)); assertNull(headers.get("userDefined1")); assertNull(headers.get("userDefined2")); }
@Test public void toHeadersUserDefinedOnly() throws XmppStringprepException { DefaultXmppHeaderMapper mapper = new DefaultXmppHeaderMapper(); mapper.setReplyHeaderNames("userDefined*"); Message source = new Message(JidCreate.from("test.to"), Message.Type.headline); source.setFrom(JidCreate.from("test.from")); source.setSubject("test.subject"); source.setThread("test.thread"); JivePropertiesManager.addProperty(source, "userDefined1", "foo"); JivePropertiesManager.addProperty(source, "userDefined2", "bar"); Map<String, Object> headers = mapper.toHeadersFromReply(source); assertNull(headers.get(XmppHeaders.TO)); assertNull(headers.get(XmppHeaders.FROM)); assertNull(headers.get(XmppHeaders.SUBJECT)); assertNull(headers.get(XmppHeaders.THREAD)); assertNull(headers.get(XmppHeaders.TYPE)); assertEquals("foo", headers.get("userDefined1")); assertEquals("bar", headers.get("userDefined2")); }
@Test public void validateMessagePostAsSmackMessage() throws Exception { XMPPConnection connection = mock(XMPPConnection.class); ChatMessageSendingMessageHandler handler = new ChatMessageSendingMessageHandler(connection); handler.setBeanFactory(mock(BeanFactory.class)); handler.afterPropertiesSet(); org.jivesoftware.smack.packet.Message smackMessage = new org.jivesoftware.smack.packet.Message(JidCreate.from("kermit@frog.com")); smackMessage.setBody("Test Message"); Message<?> message = MessageBuilder.withPayload(smackMessage).build(); // first Message new handler.handleMessage(message); verify(connection, times(1)).sendStanza(smackMessage); // assuming we know thread ID although currently we do not provide this capability smackMessage = new org.jivesoftware.smack.packet.Message(JidCreate.from("kermit@frog.com")); smackMessage.setBody("Hello Kitty"); smackMessage.setThread("123"); message = MessageBuilder.withPayload(smackMessage).build(); reset(connection); handler.handleMessage(message); // in threaded conversation we need to look for existing chat verify(connection, times(1)).sendStanza(smackMessage); }
@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()); }
protected XmppSenderConnection(XMPPConnection connection, String to, String thread) { Assert.notNull(connection, "'connection' must not be null"); Assert.hasLength(to, "'to' must not be empty"); Assert.hasLength(thread, "'thread' must not be empty"); this.connection = connection; try { this.requestMessage = new Message(JidCreate.from(to), Message.Type.chat); } catch (XmppStringprepException e) { throw new RuntimeException(e); } this.requestMessage.setThread(thread); }
protected XmppSenderConnection(XMPPConnection connection, String to, String thread) { Assert.notNull(connection, "'connection' must not be null"); Assert.hasLength(to, "'to' must not be empty"); Assert.hasLength(thread, "'thread' must not be empty"); this.connection = connection; try { this.requestMessage = new Message(JidCreate.from(to), Message.Type.chat); } catch (XmppStringprepException e) { throw new RuntimeException(e); } this.requestMessage.setThread(thread); }
protected XmppSenderConnection(XMPPConnection connection, String to, String thread) { Assert.notNull(connection, "'connection' must not be null"); Assert.hasLength(to, "'to' must not be empty"); Assert.hasLength(thread, "'thread' must not be empty"); this.connection = connection; try { this.requestMessage = new Message(JidCreate.from(to), Message.Type.chat); } catch (XmppStringprepException e) { throw new RuntimeException(e); } this.requestMessage.setThread(thread); }
protected void sendExternalEvent(CayenneEvent localEvent) throws Exception { Message message = groupChat.createMessage(); message.setBody(serializeToString(localEvent)); // set thread to our session handle to be able to discard messages from self message.setThread(sessionHandle); groupChat.sendMessage(message); }
protected void sendExternalEvent(CayenneEvent localEvent) throws Exception { Message message = groupChat.createMessage(); message.setBody(serializeToString(localEvent)); // set thread to our session handle to be able to discard messages from self message.setThread(sessionHandle); groupChat.sendMessage(message); }
@Override protected void onSendBeforeWrite(WebServiceMessage message) throws IOException { responseMessage = new Message(requestMessage.getFrom(), Message.Type.chat); responseMessage.setFrom(connection.getUser()); responseMessage.setThread(requestMessage.getThread()); }
@Override protected void onSendBeforeWrite(WebServiceMessage message) throws IOException { responseMessage = new Message(requestMessage.getFrom(), Message.Type.chat); responseMessage.setFrom(connection.getUser()); responseMessage.setThread(requestMessage.getThread()); }
@Override protected void onSendBeforeWrite(WebServiceMessage message) throws IOException { responseMessage = new Message(requestMessage.getFrom(), Message.Type.chat); responseMessage.setFrom(connection.getUser()); responseMessage.setThread(requestMessage.getThread()); }