Search in sources :

Example 51 with Message

use of org.xmpp.packet.Message in project Openfire by igniterealtime.

the class UserCreationPlugin method generateMessages.

public void generateMessages() {
    JiveGlobals.setProperty("conversation.maxTimeDebug", String.valueOf(DEFAULT_MAX_TIME_DEBUG));
    XMPPServer server = XMPPServer.getInstance();
    ExecutorService taskExecutor = Executors.newFixedThreadPool(8);
    for (User user : UserManager.getInstance().getUsers()) {
        final JID userJid = server.createJID(user.getUsername(), null);
        System.out.println("Creating messages for user: " + userJid.getNode());
        for (RosterItem ri : user.getRoster().getRosterItems()) {
            final JID rosterItemJid = ri.getJid();
            taskExecutor.execute(new Runnable() {

                @Override
                public void run() {
                    for (int j = 0; j < NUMBER_CONVERSATION; j++) {
                        String thread = RandomStringUtils.randomAlphanumeric(6);
                        for (int i = 0; i < NUMBER_MESSAGES; i++) {
                            if (i % 2 == 0) {
                                Message msg = new Message();
                                msg.setBody("Hello to " + rosterItemJid.getNode() + " from " + userJid.getNode() + ", conversation number " + j + " of " + NUMBER_CONVERSATION + ", message " + i + " of " + NUMBER_MESSAGES + " thread " + thread);
                                msg.setType(Message.Type.chat);
                                msg.setFrom(userJid);
                                msg.setTo(rosterItemJid);
                                msg.setThread(thread);
                                XMPPServer.getInstance().getMessageRouter().route(msg);
                                try {
                                    /* otherwise monitoring plugin stores messages out of order */
                                    Thread.sleep(1);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                Message msg = new Message();
                                msg.setBody("Hello to " + userJid.getNode() + " from " + rosterItemJid.getNode() + ", conversation number " + j + " of " + NUMBER_CONVERSATION + ", message " + i + " of " + NUMBER_MESSAGES + " thread " + thread);
                                msg.setType(Message.Type.chat);
                                msg.setFrom(rosterItemJid);
                                msg.setTo(userJid);
                                msg.setThread(thread);
                                XMPPServer.getInstance().getMessageRouter().route(msg);
                                try {
                                    /* otherwise monitoring plugin stores messages out of order */
                                    Thread.sleep(1);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                        try {
                            Thread.sleep(DEFAULT_MAX_TIME_DEBUG);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            });
        }
    }
    taskExecutor.shutdown();
    try {
        taskExecutor.awaitTermination(2, TimeUnit.HOURS);
        System.out.println("Conversation generation finished");
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    JiveGlobals.deleteProperty("conversation.maxTimeDebug");
}
Also used : RosterItem(org.jivesoftware.openfire.roster.RosterItem) XMPPServer(org.jivesoftware.openfire.XMPPServer) User(org.jivesoftware.openfire.user.User) JID(org.xmpp.packet.JID) Message(org.xmpp.packet.Message) ExecutorService(java.util.concurrent.ExecutorService)

Example 52 with Message

use of org.xmpp.packet.Message in project Openfire by igniterealtime.

the class OfflineMessageStoreTest method shouldStoreEmptyChatMessagesWithOtherExtensions.

@Test
public void shouldStoreEmptyChatMessagesWithOtherExtensions() {
    Message message = new Message();
    message.setType(Message.Type.chat);
    PacketExtension chatState = new PacketExtension("composing", "http://jabber.org/protocol/chatstates");
    message.addExtension(chatState);
    PacketExtension packetExtension2 = new PacketExtension("received", "urn:xmpp:receipts");
    message.addExtension(packetExtension2);
    assertTrue(OfflineMessageStore.shouldStoreMessage(message));
}
Also used : PacketExtension(org.xmpp.packet.PacketExtension) Message(org.xmpp.packet.Message) Test(org.junit.Test)

Example 53 with Message

use of org.xmpp.packet.Message in project Openfire by igniterealtime.

the class MessageCarbonsTest method testReceived.

@Test
public void testReceived() {
    Message message = new Message();
    message.setType(Message.Type.chat);
    message.setBody("Tests");
    Forwarded forwarded = new Forwarded(message);
    Received received = new Received(forwarded);
    String xml = received.getElement().asXML();
    assertEquals("<received xmlns=\"urn:xmpp:carbons:2\"><forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body></message></forwarded></received>", xml);
}
Also used : Message(org.xmpp.packet.Message) Forwarded(org.jivesoftware.openfire.forward.Forwarded) Test(org.junit.Test)

Example 54 with Message

use of org.xmpp.packet.Message in project Openfire by igniterealtime.

the class MessageCarbonsTest method testSent.

@Test
public void testSent() {
    Message message = new Message();
    message.setType(Message.Type.chat);
    message.setBody("Tests");
    Forwarded forwarded = new Forwarded(message);
    Sent sent = new Sent(forwarded);
    String xml = sent.getElement().asXML();
    assertEquals("<sent xmlns=\"urn:xmpp:carbons:2\"><forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body></message></forwarded></sent>", xml);
}
Also used : Message(org.xmpp.packet.Message) Forwarded(org.jivesoftware.openfire.forward.Forwarded) Test(org.junit.Test)

Example 55 with Message

use of org.xmpp.packet.Message in project Openfire by igniterealtime.

the class ForwardTest method testForwarded.

@Test
public void testForwarded() {
    Message message = new Message();
    message.setType(Message.Type.chat);
    message.setBody("Tests");
    message.addExtension(new DataForm(DataForm.Type.submit));
    Forwarded forwarded = new Forwarded(message);
    Forwarded forwarded2 = new Forwarded(message);
    String xml1 = forwarded.getElement().asXML();
    String xml2 = forwarded2.getElement().asXML();
    assertEquals("<forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body><x xmlns=\"jabber:x:data\" type=\"submit\"/></message></forwarded>", xml1);
    assertEquals("<forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body><x xmlns=\"jabber:x:data\" type=\"submit\"/></message></forwarded>", xml2);
}
Also used : Message(org.xmpp.packet.Message) DataForm(org.xmpp.forms.DataForm) Test(org.junit.Test)

Aggregations

Message (org.xmpp.packet.Message)111 Element (org.dom4j.Element)35 JID (org.xmpp.packet.JID)25 Test (org.junit.Test)23 Presence (org.xmpp.packet.Presence)18 IQ (org.xmpp.packet.IQ)16 ArrayList (java.util.ArrayList)10 Packet (org.xmpp.packet.Packet)10 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)9 Date (java.util.Date)6 ClientSession (org.jivesoftware.openfire.session.ClientSession)6 NotFoundException (org.jivesoftware.util.NotFoundException)6 StringReader (java.io.StringReader)4 List (java.util.List)4 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)4 User (org.jivesoftware.openfire.user.User)4 IOException (java.io.IOException)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 SAXReader (org.dom4j.io.SAXReader)3 DefaultElement (org.dom4j.tree.DefaultElement)3