Search in sources :

Example 11 with Message

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

the class MultiplexerPacketDeliverer method handleUnprocessedPacket.

private void handleUnprocessedPacket(Packet packet) {
    if (packet instanceof Message) {
        messageStrategy.storeOffline((Message) packet);
    } else if (packet instanceof Presence) {
    // presence packets are dropped silently
    //dropPacket(packet);
    } else if (packet instanceof IQ) {
        IQ iq = (IQ) packet;
        // Check if we need to unwrap the packet
        Element child = iq.getChildElement();
        if (child != null && "session".equals(child.getName()) && "http://jabber.org/protocol/connectionmanager".equals(child.getNamespacePrefix())) {
            Element send = child.element("send");
            if (send != null) {
                // Unwrap packet
                Element wrappedElement = (Element) send.elements().get(0);
                if ("message".equals(wrappedElement.getName())) {
                    handleUnprocessedPacket(new Message(wrappedElement));
                }
            }
        } else {
            // IQ packets are logged but dropped
            Log.warn(LocaleUtils.getLocalizedString("admin.error.routing") + "\n" + packet.toString());
        }
    }
}
Also used : Message(org.xmpp.packet.Message) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) Presence(org.xmpp.packet.Presence)

Example 12 with Message

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

the class MultiplexerPacketHandler method handle.

/**
     * Process IQ packet sent by a connection manager indicating that a new session has
     * been created, should be closed or that a packet was failed to be delivered.
     *
     * @param packet the IQ packet.
     */
public void handle(Packet packet) {
    if (packet instanceof IQ) {
        IQ iq = (IQ) packet;
        if (iq.getType() == IQ.Type.result) {
        // Do nothing with result packets
        } else if (iq.getType() == IQ.Type.error) {
            // Log the IQ error packet that the connection manager failed to process
            Log.warn("Connection Manager failed to process IQ packet: " + packet.toXML());
        } else if (iq.getType() == IQ.Type.set) {
            Element child = iq.getChildElement();
            String streamIDValue = child.attributeValue("id");
            if (streamIDValue == null) {
                // No stream ID was included so return a bad_request error
                Element extraError = DocumentHelper.createElement(QName.get("id-required", "http://jabber.org/protocol/connectionmanager#errors"));
                sendErrorPacket(iq, PacketError.Condition.bad_request, extraError);
            } else if ("session".equals(child.getName())) {
                StreamID streamID = BasicStreamIDFactory.createStreamID(streamIDValue);
                Element create = child.element("create");
                if (create != null) {
                    // Get the InetAddress of the client
                    Element hostElement = create.element("host");
                    String hostName = hostElement != null ? hostElement.attributeValue("name") : null;
                    String hostAddress = hostElement != null ? hostElement.attributeValue("address") : null;
                    // Connection Manager wants to create a Client Session
                    boolean created = multiplexerManager.createClientSession(connectionManagerDomain, streamID, hostName, hostAddress);
                    if (created) {
                        sendResultPacket(iq);
                    } else {
                        // Send error to CM. The CM should close the new-born connection
                        sendErrorPacket(iq, PacketError.Condition.not_allowed, null);
                    }
                } else {
                    ClientSession session = multiplexerManager.getClientSession(connectionManagerDomain, streamID);
                    if (session == null) {
                        // Specified Client Session does not exist
                        sendErrorPacket(iq, PacketError.Condition.item_not_found, null);
                    } else if (child.element("close") != null) {
                        // Connection Manager wants to close a Client Session
                        multiplexerManager.closeClientSession(connectionManagerDomain, streamID);
                        sendResultPacket(iq);
                    } else if (child.element("failed") != null) {
                        // Connection Manager failed to deliver a message
                        // Connection Manager wrapped a packet from a Client Session.
                        List wrappedElements = child.element("failed").elements();
                        if (wrappedElements.size() != 1) {
                            // Wrapper element is wrapping 0 or many items
                            Element extraError = DocumentHelper.createElement(QName.get("invalid-payload", "http://jabber.org/protocol/connectionmanager#errors"));
                            sendErrorPacket(iq, PacketError.Condition.bad_request, extraError);
                        } else {
                            Element wrappedElement = (Element) wrappedElements.get(0);
                            String tag = wrappedElement.getName();
                            if ("message".equals(tag)) {
                                XMPPServer.getInstance().getOfflineMessageStrategy().storeOffline(new Message(wrappedElement));
                                sendResultPacket(iq);
                            } else {
                                Element extraError = DocumentHelper.createElement(QName.get("unknown-stanza", "http://jabber.org/protocol/connectionmanager#errors"));
                                sendErrorPacket(iq, PacketError.Condition.bad_request, extraError);
                            }
                        }
                    } else {
                        // Unknown IQ packet received so return error to sender
                        sendErrorPacket(iq, PacketError.Condition.bad_request, null);
                    }
                }
            } else {
                // Unknown IQ packet received so return error to sender
                sendErrorPacket(iq, PacketError.Condition.bad_request, null);
            }
        } else {
            // Unknown IQ packet received so return error to sender
            sendErrorPacket(iq, PacketError.Condition.bad_request, null);
        }
    }
}
Also used : StreamID(org.jivesoftware.openfire.StreamID) Message(org.xmpp.packet.Message) Element(org.dom4j.Element) LocalClientSession(org.jivesoftware.openfire.session.LocalClientSession) ClientSession(org.jivesoftware.openfire.session.ClientSession) IQ(org.xmpp.packet.IQ) List(java.util.List)

Example 13 with Message

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

the class UpdateManager method processAvailablePluginsResponse.

private void processAvailablePluginsResponse(String response, boolean notificationsEnabled) throws DocumentException {
    // Reset last known list of available plugins
    availablePlugins = new HashMap<>();
    // Parse response and keep info as AvailablePlugin objects
    SAXReader xmlReader = new SAXReader();
    xmlReader.setEncoding("UTF-8");
    Element xmlResponse = xmlReader.read(new StringReader(response)).getRootElement();
    Iterator plugins = xmlResponse.elementIterator("plugin");
    while (plugins.hasNext()) {
        Element plugin = (Element) plugins.next();
        String pluginName = plugin.attributeValue("name");
        String latestVersion = plugin.attributeValue("latest");
        String icon = plugin.attributeValue("icon");
        String readme = plugin.attributeValue("readme");
        String changelog = plugin.attributeValue("changelog");
        String url = plugin.attributeValue("url");
        String licenseType = plugin.attributeValue("licenseType");
        String description = plugin.attributeValue("description");
        String author = plugin.attributeValue("author");
        String minServerVersion = plugin.attributeValue("minServerVersion");
        String fileSize = plugin.attributeValue("fileSize");
        AvailablePlugin available = new AvailablePlugin(pluginName, description, latestVersion, author, icon, changelog, readme, licenseType, minServerVersion, url, fileSize);
        // Add plugin to the list of available plugins at js.org
        availablePlugins.put(pluginName, available);
    }
    // Figure out local plugins that need to be updated
    buildPluginsUpdateList();
    // Check if we need to send notifications to admins
    if (notificationsEnabled && isNotificationEnabled() && !pluginUpdates.isEmpty()) {
        Collection<JID> admins = XMPPServer.getInstance().getAdmins();
        for (Update update : pluginUpdates) {
            Message notification = new Message();
            notification.setFrom(serverName);
            notification.setBody(getNotificationMessage() + " " + update.getComponentName() + " " + update.getLatestVersion());
            for (JID jid : admins) {
                notification.setTo(jid);
                router.route(notification);
            }
        }
    }
    // Save information of available plugins
    saveAvailablePluginsInfo();
}
Also used : JID(org.xmpp.packet.JID) Message(org.xmpp.packet.Message) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) StringReader(java.io.StringReader) Iterator(java.util.Iterator)

Example 14 with Message

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

the class WorkgroupCompatibleClient method notifyQueueDepartued.

public void notifyQueueDepartued(JID sender, JID receiver, UserRequest request, Request.CancelType type) {
    Message message = new Message();
    if (sender != null) {
        message.setFrom(sender);
    }
    message.setTo(receiver);
    Element depart = message.getElement().addElement("depart-queue", "http://jabber.org/protocol/workgroup");
    // Add an element that explains the reason why the user is being removed from the queue
    depart.addElement(type.getDescription());
    // Send the notification
    request.getWorkgroup().send(message);
}
Also used : Message(org.xmpp.packet.Message) Element(org.dom4j.Element)

Example 15 with Message

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

the class WorkgroupCompatibleClient method notifyQueueStatus.

public void notifyQueueStatus(JID sender, JID receiver, UserRequest request, boolean isPolling) {
    Packet statusPacket;
    if (isPolling) {
        statusPacket = new IQ();
    } else {
        statusPacket = new Message();
    }
    statusPacket.setFrom(sender);
    statusPacket.setTo(receiver);
    // Add Queue Status Packet to IQ
    Element status = statusPacket.getElement().addElement("queue-status", "http://jabber.org/protocol/workgroup");
    // Add Time Element
    Element time = status.addElement("time");
    time.setText(Integer.toString(request.getTimeStatus()));
    // Add Position Element
    Element position = status.addElement("position");
    position.setText(Integer.toString(request.getPosition() + 1));
    status.add(request.getSessionElement());
    // Send the queue status
    request.getWorkgroup().send(statusPacket);
}
Also used : Packet(org.xmpp.packet.Packet) Message(org.xmpp.packet.Message) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ)

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