Search in sources :

Example 56 with Message

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

the class HttpSessionDeliverable method testNamespaceOnEmptyStanza.

/**
     * Verifies that the default namespace is set on empty stanzas.
     *
     * @see <a href="https://igniterealtime.org/issues/browse/OF-1087">OF-1087</a>
     */
@Test
public void testNamespaceOnEmptyStanza() throws Exception {
    // Setup fixture
    final Message message = new Message();
    message.addChildElement("unittest", "unit:test:namespace");
    final List<Packet> packets = new ArrayList<>();
    packets.add(message);
    // Execute system under test
    final HttpSession.Deliverable deliverable = new HttpSession.Deliverable(packets);
    final String result = deliverable.getDeliverable();
    // verify results
    // Note that this assertion depends on the Openfire XML parser-specific ordering of attributes.
    assertEquals("<message xmlns=\"jabber:client\"><unittest xmlns=\"unit:test:namespace\"/></message>", result);
}
Also used : Packet(org.xmpp.packet.Packet) Message(org.xmpp.packet.Message) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 57 with Message

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

the class HttpSessionDeliverable method testNamespaceOnEmptyStanzaWithoutChildElement.

/**
     * Verifies that the default namespace is set on empty stanzas (that do not have a child element)
     *
     * @see <a href="https://igniterealtime.org/issues/browse/OF-1087">OF-1087</a>
     */
@Test
public void testNamespaceOnEmptyStanzaWithoutChildElement() throws Exception {
    // Setup fixture
    final Message message = new Message();
    final List<Packet> packets = new ArrayList<>();
    packets.add(message);
    // Execute system under test
    final HttpSession.Deliverable deliverable = new HttpSession.Deliverable(packets);
    final String result = deliverable.getDeliverable();
    // verify results
    // Note that this assertion depends on the Openfire XML parser-specific ordering of attributes.
    assertEquals("<message xmlns=\"jabber:client\"/>", result);
}
Also used : Packet(org.xmpp.packet.Packet) Message(org.xmpp.packet.Message) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 58 with Message

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

the class PacketCounter method start.

/**
     * Resets all counters, and starts counting.
     */
public void start() {
    // Register a packet listener so that we can track packet traffic.
    interceptor = new PacketInterceptor() {

        public void interceptPacket(final Packet packet, final Session session, final boolean incoming, final boolean processed) {
            if (!processed) {
                // don't count packets twice!
                return;
            }
            stanza.incrementAndGet();
            if (packet instanceof Message) {
                message.incrementAndGet();
            }
            if (packet instanceof Presence) {
                presence.incrementAndGet();
            }
            if (packet instanceof IQ) {
                iq.incrementAndGet();
                switch(((IQ) packet).getType()) {
                    case get:
                        iqGet.incrementAndGet();
                        break;
                    case set:
                        iqSet.incrementAndGet();
                        break;
                    case result:
                        iqResult.incrementAndGet();
                        break;
                    case error:
                        iqError.incrementAndGet();
                        break;
                }
            }
        }
    };
    // reset counters
    stanza.set(0);
    message.set(0);
    presence.set(0);
    iq.set(0);
    iqGet.set(0);
    iqSet.set(0);
    iqResult.set(0);
    iqError.set(0);
    // register listener
    InterceptorManager.getInstance().addInterceptor(interceptor);
}
Also used : Packet(org.xmpp.packet.Packet) Message(org.xmpp.packet.Message) IQ(org.xmpp.packet.IQ) Presence(org.xmpp.packet.Presence) PacketInterceptor(org.jivesoftware.openfire.interceptor.PacketInterceptor) Session(org.jivesoftware.openfire.session.Session)

Example 59 with Message

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

the class GojaraAdminManager method uptime.

private void uptime(String transport) {
    Message message = generateCommand(transport, "uptime");
    router.route(message);
}
Also used : Message(org.xmpp.packet.Message)

Example 60 with Message

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

the class BaseMUCTransport method sendMessage.

/**
     * Sends a simple message through he component manager.
     *
     * @param to Who the message is for.
     * @param from Who the message is from.
     * @param msg Message to be send.
     * @param type Type of message to be sent.
     */
public void sendMessage(JID to, JID from, String msg, Message.Type type) {
    Message m = new Message();
    m.setType(type);
    m.setFrom(from);
    m.setTo(to);
    m.setBody(msg);
    sendPacket(m);
}
Also used : Message(org.xmpp.packet.Message)

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