Package org.xmpp.packet

Examples of org.xmpp.packet.IQ


     * @param packet the packet to be bounced.
     * @param error the reason why the operation failed.
     */
    private void sendErrorPacket(Packet packet, PacketError.Condition error) {
        if (packet instanceof IQ) {
            IQ reply = IQ.createResultIQ((IQ) packet);
            reply.setChildElement(((IQ) packet).getChildElement().createCopy());
            reply.setError(error);
            router.route(reply);
        }
        else {
            Packet reply = packet.createCopy();
            reply.setError(error);
            reply.setFrom(packet.getTo());
            reply.setTo(packet.getFrom());
            router.route(reply);
        }
    }
View Full Code Here


        if (IQ.Type.get == packet.getType()) {
            // Could cache this information for every server we see
            Element answerElement = bodyElement.createCopy();
            answerElement.element("name").setText(AdminConsole.getAppName());
            answerElement.element("version").setText(AdminConsole.getVersionString());
            IQ result = IQ.createResultIQ(packet);
            result.setChildElement(answerElement);
            return result;
        }
        else if (IQ.Type.set == packet.getType()) {
            // Answer an not-acceptable error since IQ should be of type GET
            IQ result = IQ.createResultIQ(packet);
            result.setError(PacketError.Condition.not_acceptable);
            return result;
        }
        // Ignore any other type of packet
        return null;
    }
View Full Code Here

                return;
            }
            processPresence(packet);
        }
        else if ("iq".equals(tag)) {
            IQ packet;
            try {
                packet = getIQ(doc);
            }
            catch(IllegalArgumentException e) {
                Log.debug("SocketReader: Rejecting packet. JID malformed", e);
                // The original packet contains a malformed JID so answer an error
                IQ reply = new IQ();
                if (!doc.elements().isEmpty()) {
                    reply.setChildElement(((Element) doc.elements().get(0)).createCopy());
                }
                reply.setID(doc.attributeValue("id"));
                reply.setTo(session.getAddress());
                if (doc.attributeValue("to") != null) {
                    reply.getElement().addAttribute("from", doc.attributeValue("to"));
                }
                reply.setError(PacketError.Condition.jid_malformed);
                session.process(reply);
                return;
            }
            processIQ(packet);
        }
View Full Code Here

        Element query = doc.element("query");
        if (query != null && "jabber:iq:roster".equals(query.getNamespaceURI())) {
            return new Roster(doc);
        }
        else {
            return new IQ(doc);
        }
    }
View Full Code Here

     * request.
     *
     * @param iqRequest IQ request sent by an owner of the node.
     */
    void sendAffiliations(IQ iqRequest) {
        IQ reply = IQ.createResultIQ(iqRequest);
        Element childElement = iqRequest.getChildElement().createCopy();
        reply.setChildElement(childElement);
        Element affiliations = childElement.element("affiliations");

        for (NodeAffiliate affiliate : affiliates) {
            if (affiliate.getAffiliation() == NodeAffiliate.Affiliation.none) {
                continue;
View Full Code Here

     * request.
     *
     * @param iqRequest IQ request sent by an owner of the node.
     */
    void sendSubscriptions(IQ iqRequest) {
        IQ reply = IQ.createResultIQ(iqRequest);
        Element childElement = iqRequest.getChildElement().createCopy();
        reply.setChildElement(childElement);
        Element subscriptions = childElement.element("subscriptions");

        for (NodeAffiliate affiliate : affiliates) {
            for (NodeSubscription subscription : affiliate.getSubscriptions()) {
                if (subscription.isAuthorizationPending()) {
View Full Code Here

                return;
            }
            processPresence(packet);
        }
        else if ("iq".equals(tag)) {
            IQ packet;
            try {
                packet = getIQ(doc);
            }
            catch (IllegalArgumentException e) {
                Log.debug("Rejecting packet. JID malformed", e);
                // The original packet contains a malformed JID so answer an error
                IQ reply = new IQ();
                if (!doc.elements().isEmpty()) {
                    reply.setChildElement(((Element)doc.elements().get(0)).createCopy());
                }
                reply.setID(doc.attributeValue("id"));
                reply.setTo(session.getAddress());
                if (doc.attributeValue("to") != null) {
                    reply.getElement().addAttribute("from", doc.attributeValue("to"));
                }
                reply.setError(PacketError.Condition.jid_malformed);
                session.process(reply);
                return;
            }
            if (packet.getID() == null && JiveGlobals.getBooleanProperty("xmpp.server.validation.enabled", false)) {
                // IQ packets MUST have an 'id' attribute so close the connection
View Full Code Here

        Element query = doc.element("query");
        if (query != null && "jabber:iq:roster".equals(query.getNamespaceURI())) {
            return new Roster(doc);
        }
        else {
            return new IQ(doc, !validateJIDs());
        }
    }
View Full Code Here

        return transferList.iterator();
    }

    public void getChatTranscripts(IQ iq, String uniqueUserID) {
        try {
            IQ replyPacket = IQ.createResultIQ(iq);
            Element transcripts = replyPacket.setChildElement("transcripts",
                "http://jivesoftware.com/protocol/workgroup");
            transcripts.addAttribute("userID", uniqueUserID);

            Connection con = null;
            PreparedStatement pstmt = null;
View Full Code Here

            Log.error(ex.getMessage(), ex);
        }
    }

    public void getChatTranscript(IQ iq, String sessionID) {
        final IQ reply = IQ.createResultIQ(iq);

        String transcriptXML = null;
        try {
            Element transcript = reply.setChildElement("transcript",
                "http://jivesoftware.com/protocol/workgroup");
            transcript.addAttribute("sessionID", sessionID);
            Connection con = null;
            PreparedStatement pstmt = null;
            ResultSet rs = null;
            try {
                con = DbConnectionManager.getConnection();
                pstmt = con.prepareStatement(GET_TRANSCRIPT);
                pstmt.setString(1, sessionID);
                rs = pstmt.executeQuery();
                if (rs.next()) {
                    transcriptXML = DbConnectionManager.getLargeTextField(rs, 1);
                }
            }
            catch (SQLException sqle) {
                Log.error(sqle.getMessage(), sqle);
            }
            finally {
                DbConnectionManager.closeConnection(rs, pstmt, con);
            }
            if (transcriptXML != null) {
                Document element = DocumentHelper.parseText(transcriptXML);
                // Add the Messages and Presences contained in the retrieved transcript element
                for (Iterator<Element> it = element.getRootElement().elementIterator(); it.hasNext();) {
                    Element packet = it.next();
                    transcript.add(packet.createCopy());
                }
            }
            workgroup.send(reply);
        }
        catch (Exception ex) {
            Log.error(
                    "There was an error retrieving the following transcript. SessionID = " +
                    sessionID + " Transcript=" + transcriptXML, ex);

            reply.setChildElement(iq.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.item_not_found));
            workgroup.send(reply);
        }
    }
View Full Code Here

TOP

Related Classes of org.xmpp.packet.IQ

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.