Package rocks.xmpp.core.stanza.model.client

Examples of rocks.xmpp.core.stanza.model.client.IQ


                "        <field var='x-gender'><value>male</value></field>\n" +
                "      </item>\n" +
                "    </x>\n" +
                "  </query>\n" +
                "</iq>\n";
        IQ iq = unmarshal(xml, IQ.class);
        Search search = iq.getExtension(Search.class);

        Assert.assertNotNull(search);

        DataForm dataForm = search.getAdditionalInformation();
        Assert.assertNotNull(dataForm);
View Full Code Here


        });

        xmppSession.addIQListener(new IQListener() {
            @Override
            public void handle(IQEvent e) {
                IQ iq = e.getIQ();
                if (e.isIncoming() && isEnabled() && !e.isConsumed() && iq.getType() == IQ.Type.SET) {

                    Socks5ByteStream socks5ByteStream = iq.getExtension(Socks5ByteStream.class);
                    if (socks5ByteStream != null) {
                        if (socks5ByteStream.getSessionId() == null) {
                            // If the request is malformed (e.g., the <query/> element does not include the 'sid' attribute), the Target MUST return an error of <bad-request/>.
                            xmppSession.send(iq.createError(new StanzaError(new BadRequest())));
                        } else {
                            notifyByteStreamEvent(new S5bEvent(Socks5ByteStreamManager.this, socks5ByteStream.getSessionId(), xmppSession, iq, socks5ByteStream.getStreamHosts()));
                        }
                        e.consume();
                    }
View Full Code Here

                contactExchange.getItems().add(rosterItem);
            }
            // http://xmpp.org/extensions/xep-0144.html#stanza
            Presence presence = xmppSession.getPresenceManager().getPresence(jid);
            if (presence.isAvailable()) {
                xmppSession.query(new IQ(presence.getFrom(), IQ.Type.SET, contactExchange));
            } else {
                // If the sending entity does not know that the receiving entity is online and available, it MUST send a <message/> stanza to the receiving entity's "bare JID" (user@host) rather than an <iq/> stanza to a particular resource.
                Message message = new Message(jid, Message.Type.NORMAL);
                message.getExtensions().add(contactExchange);
                xmppSession.send(message);
View Full Code Here

                "  <error type='modify'>\n" +
                "    <bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>\n" +
                "    <item-required xmlns='http://jabber.org/protocol/pubsub#errors'/>\n" +
                "  </error>\n" +
                "</iq>\n";
        IQ iq = unmarshal(xml, IQ.class);
        Assert.assertTrue(iq.getError().getExtension() instanceof ItemRequired);
    }
View Full Code Here

     * @return The software version or null, if this protocol is not supported.
     * @throws rocks.xmpp.core.stanza.model.StanzaException If the entity returned a stanza error.
     * @throws rocks.xmpp.core.session.NoResponseException  If the entity did not respond.
     */
    public SoftwareVersion getSoftwareVersion(Jid jid) throws XmppException {
        IQ iq = new IQ(IQ.Type.GET, new SoftwareVersion());
        iq.setTo(jid);
        IQ result = xmppSession.query(iq);
        return result.getExtension(SoftwareVersion.class);
    }
View Full Code Here

    public List<StreamHost> discoverProxies() throws XmppException {
        ItemNode itemNode = serviceDiscoveryManager.discoverItems(null);
        for (Item item : itemNode.getItems()) {
            InfoNode infoNode = serviceDiscoveryManager.discoverInformation(item.getJid());
            if (infoNode.getFeatures().contains(new Feature(Socks5ByteStream.NAMESPACE))) {
                IQ result = xmppSession.query(new IQ(item.getJid(), IQ.Type.GET, new Socks5ByteStream()));
                Socks5ByteStream socks5ByteStream = result.getExtension(Socks5ByteStream.class);
                if (socks5ByteStream != null) {
                    return socks5ByteStream.getStreamHosts();
                }
            }
        }
View Full Code Here

                "  <error type='modify'>\n" +
                "    <bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>\n" +
                "    <payload-required xmlns='http://jabber.org/protocol/pubsub#errors'/>\n" +
                "  </error>\n" +
                "</iq>\n";
        IQ iq = unmarshal(xml, IQ.class);
        Assert.assertTrue(iq.getError().getExtension() instanceof PayloadRequired);
    }
View Full Code Here

        localSocks5Server.allowedAddresses.add(hash);

        try {
            // 5.3.1 Requester Initiates S5B Negotiation
            // 6.3.1 Requester Initiates S5B Negotiation
            IQ result = xmppSession.query(new IQ(target, IQ.Type.SET, new Socks5ByteStream(sessionId, streamHosts, hash)));

            // 5.3.3 Target Acknowledges Bytestream
            // 6.3.3 Target Acknowledges Bytestream
            Socks5ByteStream socks5ByteStream = result.getExtension(Socks5ByteStream.class);
            StreamHost usedStreamHost = null;
            for (StreamHost streamHost : streamHosts) {
                if (socks5ByteStream.getStreamHostUsed() != null && socks5ByteStream.getStreamHostUsed().equals(streamHost.getJid())) {
                    usedStreamHost = streamHost;
                    break;
                }
            }

            if (usedStreamHost == null) {
                throw new IOException("Target did not respond with a stream host.");
            }

            Socket socket;
            if (!usedStreamHost.getJid().equals(requester)) {
                // 6.3.4 Requester Establishes SOCKS5 Connection with StreamHost
                socket = new Socket();
                socket.connect(new InetSocketAddress(usedStreamHost.getHost(), usedStreamHost.getPort()));
                Socks5Protocol.establishClientConnection(socket, hash, 0);

                // 6.3.5 Activation of Bytestream
                xmppSession.query(new IQ(usedStreamHost.getJid(), IQ.Type.SET, Socks5ByteStream.activate(sessionId, target)));
            } else {
                socket = localSocks5Server.getSocket(hash);
            }
            if (socket == null) {
                throw new IOException("Not connected to stream host");
View Full Code Here

        // Listen for "un/block pushes"
        xmppSession.addIQListener(new IQListener() {
            @Override
            public void handle(IQEvent e) {
                IQ iq = e.getIQ();
                if (e.isIncoming() && !e.isConsumed() && iq.getType() == IQ.Type.SET && (iq.getFrom() == null || iq.getFrom().equals(xmppSession.getConnectedResource().asBareJid()))) {
                    Block block = iq.getExtension(Block.class);
                    if (block != null) {
                        List<Jid> pushedContacts = new ArrayList<>();
                        synchronized (blockedContacts) {
                            for (Jid item : block.getItems()) {
                                blockedContacts.add(item);
                                pushedContacts.add(item);
                            }
                        }
                        xmppSession.send(iq.createResult());
                        e.consume();
                        notifyListeners(pushedContacts, Collections.<Jid>emptyList());
                    } else {
                        Unblock unblock = iq.getExtension(Unblock.class);
                        if (unblock != null) {
                            List<Jid> pushedContacts = new ArrayList<>();
                            synchronized (blockedContacts) {
                                if (unblock.getItems().isEmpty()) {
                                    // Empty means, the user has unblocked communications with all contacts.
                                    pushedContacts.addAll(blockedContacts);
                                    blockedContacts.clear();
                                } else {
                                    for (Jid item : unblock.getItems()) {
                                        blockedContacts.remove(item);
                                        pushedContacts.add(item);
                                    }
                                }
                            }
                            xmppSession.send(iq.createResult());
                            e.consume();
                            notifyListeners(Collections.<Jid>emptyList(), pushedContacts);
                        }
                    }
                }
View Full Code Here

                "  <error type='modify'>\n" +
                "    <bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>\n" +
                "    <item-forbidden xmlns='http://jabber.org/protocol/pubsub#errors'/>\n" +
                "  </error>\n" +
                "</iq>\n";
        IQ iq = unmarshal(xml, IQ.class);
        Assert.assertTrue(iq.getError().getExtension() instanceof ItemForbidden);
    }
View Full Code Here

TOP

Related Classes of rocks.xmpp.core.stanza.model.client.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.