use of org.jivesoftware.smack.packet.Message in project intellij-plugins by JetBrains.
the class JabberTransport method doSendMessage.
private Message doSendMessage(XmlMessage xmlMessage, User user, String threadId) {
Element element = new Element(xmlMessage.getTagName(), xmlMessage.getTagNamespace());
xmlMessage.fillRequest(element);
Message message = createBaseMessage(user, element.getText());
message.setThread(threadId);
message.addExtension(new JDOMExtension(element));
myFacade.getConnection().sendPacket(message);
return message;
}
use of org.jivesoftware.smack.packet.Message in project intellij-plugins by JetBrains.
the class JabberTransport method createBaseMessage.
static Message createBaseMessage(User user, String message) {
Message msg = new Message(user.getName(), Message.Type.CHAT);
msg.setBody(message);
return msg;
}
use of org.jivesoftware.smack.packet.Message in project camel by apache.
the class XmppBinding method extractHeadersFromXmpp.
public Map<String, Object> extractHeadersFromXmpp(Packet xmppPacket, Exchange exchange) {
Map<String, Object> answer = new HashMap<String, Object>();
PacketExtension jpe = xmppPacket.getExtension(JivePropertiesExtension.NAMESPACE);
if (jpe != null && jpe instanceof JivePropertiesExtension) {
extractHeadersFrom((JivePropertiesExtension) jpe, exchange, answer);
}
if (jpe != null && jpe instanceof DefaultPacketExtension) {
extractHeadersFrom((DefaultPacketExtension) jpe, exchange, answer);
}
if (xmppPacket instanceof Message) {
Message xmppMessage = (Message) xmppPacket;
answer.put(XmppConstants.MESSAGE_TYPE, xmppMessage.getType());
answer.put(XmppConstants.SUBJECT, xmppMessage.getSubject());
answer.put(XmppConstants.THREAD_ID, xmppMessage.getThread());
} else if (xmppPacket instanceof PubSub) {
PubSub pubsubPacket = (PubSub) xmppPacket;
answer.put(XmppConstants.MESSAGE_TYPE, pubsubPacket.getType());
}
answer.put(XmppConstants.FROM, xmppPacket.getFrom());
answer.put(XmppConstants.PACKET_ID, xmppPacket.getPacketID());
answer.put(XmppConstants.TO, xmppPacket.getTo());
return answer;
}
use of org.jivesoftware.smack.packet.Message in project camel by apache.
the class XmppGroupChatProducer method process.
public void process(Exchange exchange) {
if (connection == null) {
try {
connection = endpoint.createConnection();
} catch (Exception e) {
throw new RuntimeExchangeException("Could not connect to XMPP server.", exchange, e);
}
}
if (chat == null) {
try {
initializeChat();
} catch (Exception e) {
throw new RuntimeExchangeException("Could not initialize XMPP chat.", exchange, e);
}
}
Message message = chat.createMessage();
message.setTo(room);
message.setFrom(endpoint.getUser());
endpoint.getBinding().populateXmppMessage(message, exchange);
try {
// make sure we are connected
if (!connection.isConnected()) {
this.reconnect();
}
if (LOG.isDebugEnabled()) {
LOG.debug("Sending XMPP message: {}", message.getBody());
}
chat.sendMessage(message);
// must invoke nextMessage to consume the response from the server
// otherwise the client local queue will fill up (CAMEL-1467)
chat.pollMessage();
} catch (Exception e) {
throw new RuntimeExchangeException("Could not send XMPP message: " + message, exchange, e);
}
}
use of org.jivesoftware.smack.packet.Message in project Smack by igniterealtime.
the class PacketParserUtilsTest method singleMessageBodyTest.
@Test
public void singleMessageBodyTest() throws Exception {
String defaultLanguage = Stanza.getDefaultLanguage();
String otherLanguage = determineNonDefaultLanguage();
String control;
// message has default language, body has no language
control = XMLBuilder.create("message").a("from", "romeo@montague.lit/orchard").a("to", "juliet@capulet.lit/balcony").a("id", "zid615d9").a("type", "chat").a("xml:lang", defaultLanguage).e("body").t(defaultLanguage).asString(outputProperties);
Message message = PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
assertEquals(defaultLanguage, message.getBody());
assertTrue(message.getBodyLanguages().isEmpty());
assertEquals(defaultLanguage, message.getBody(defaultLanguage));
assertNull(message.getBody(otherLanguage));
assertXMLEqual(control, message.toXML().toString());
// message has non-default language, body has no language
control = XMLBuilder.create("message").a("from", "romeo@montague.lit/orchard").a("to", "juliet@capulet.lit/balcony").a("id", "zid615d9").a("type", "chat").a("xml:lang", otherLanguage).e("body").t(otherLanguage).asString(outputProperties);
message = PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
assertEquals(otherLanguage, message.getBody());
assertTrue(message.getBodyLanguages().isEmpty());
assertEquals(otherLanguage, message.getBody(otherLanguage));
assertNull(message.getBody(defaultLanguage));
assertXMLEqual(control, message.toXML().toString());
// message has no language, body has no language
control = XMLBuilder.create("message").a("from", "romeo@montague.lit/orchard").a("to", "juliet@capulet.lit/balcony").a("id", "zid615d9").a("type", "chat").e("body").t(defaultLanguage).asString(outputProperties);
message = PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
assertEquals(defaultLanguage, message.getBody());
assertTrue(message.getBodyLanguages().isEmpty());
assertEquals(defaultLanguage, message.getBody(defaultLanguage));
assertNull(message.getBody(otherLanguage));
assertXMLEqual(control, message.toXML().toString());
// message has no language, body has default language
control = XMLBuilder.create("message").a("from", "romeo@montague.lit/orchard").a("to", "juliet@capulet.lit/balcony").a("id", "zid615d9").a("type", "chat").e("body").a("xml:lang", defaultLanguage).t(defaultLanguage).asString(outputProperties);
message = PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
assertEquals(defaultLanguage, message.getBody());
assertTrue(message.getBodyLanguages().isEmpty());
assertEquals(defaultLanguage, message.getBody(defaultLanguage));
assertNull(message.getBody(otherLanguage));
// body attribute xml:lang is unnecessary
assertXMLNotEqual(control, message.toXML().toString());
// message has no language, body has non-default language
control = XMLBuilder.create("message").a("from", "romeo@montague.lit/orchard").a("to", "juliet@capulet.lit/balcony").a("id", "zid615d9").a("type", "chat").e("body").a("xml:lang", otherLanguage).t(otherLanguage).asString(outputProperties);
message = PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
assertNull(message.getBody());
assertFalse(message.getBodyLanguages().isEmpty());
assertTrue(message.getBodyLanguages().contains(otherLanguage));
assertEquals(otherLanguage, message.getBody(otherLanguage));
assertNull(message.getBody(defaultLanguage));
assertXMLEqual(control, message.toXML().toString());
// message has default language, body has non-default language
control = XMLBuilder.create("message").a("from", "romeo@montague.lit/orchard").a("to", "juliet@capulet.lit/balcony").a("id", "zid615d9").a("type", "chat").a("xml:lang", defaultLanguage).e("body").a("xml:lang", otherLanguage).t(otherLanguage).asString(outputProperties);
message = PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
assertNull(message.getBody());
assertFalse(message.getBodyLanguages().isEmpty());
assertTrue(message.getBodyLanguages().contains(otherLanguage));
assertEquals(otherLanguage, message.getBody(otherLanguage));
assertNull(message.getBody(defaultLanguage));
assertXMLEqual(control, message.toXML().toString());
// message has non-default language, body has default language
control = XMLBuilder.create("message").a("from", "romeo@montague.lit/orchard").a("to", "juliet@capulet.lit/balcony").a("id", "zid615d9").a("type", "chat").a("xml:lang", otherLanguage).e("body").a("xml:lang", defaultLanguage).t(defaultLanguage).asString(outputProperties);
message = PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
assertNull(message.getBody());
assertFalse(message.getBodyLanguages().isEmpty());
assertTrue(message.getBodyLanguages().contains(defaultLanguage));
assertEquals(defaultLanguage, message.getBody(defaultLanguage));
assertNull(message.getBody(otherLanguage));
assertXMLEqual(control, message.toXML().toString());
}
Aggregations