Search in sources :

Example 71 with IQ

use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.

the class RSMSetProviderTest method testRsmSetProvider.

@Test
public void testRsmSetProvider() throws Exception {
    // @formatter:off
    final String rsmset = "<iq type='get' id='iqget'>" + "<pubsub xmlns='http://jabber.org/protocol/pubsub'>" + "<set xmlns='http://jabber.org/protocol/rsm'>" + "<after>aftervalue</after>" + "<before>beforevalue</before>" + "<count>1</count>" + "<first index='2'>foo@bar.com</first>" + "<index>3</index>" + "<last>lastvalue</last>" + "<max>4</max>" + "</set>" + "</pubsub>" + "</iq>";
    // @formatter:on
    IQ iqWithRsm = (IQ) PacketParserUtils.parseStanza(rsmset);
    RSMSet rsm = (RSMSet) iqWithRsm.getExtension(RSMSet.ELEMENT, RSMSet.NAMESPACE);
    assertNotNull(rsm);
    assertEquals("aftervalue", rsm.getAfter());
    assertEquals("beforevalue", rsm.getBefore());
    assertEquals(1, rsm.getCount());
    assertEquals(2, rsm.getFirstIndex());
    assertEquals("foo@bar.com", rsm.getFirst());
    assertEquals(3, rsm.getIndex());
    assertEquals("lastvalue", rsm.getLast());
    assertEquals(4, rsm.getMax());
}
Also used : RSMSet(org.jivesoftware.smackx.rsm.packet.RSMSet) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.Test)

Example 72 with IQ

use of org.jivesoftware.smack.packet.IQ in project Openfire by igniterealtime.

the class JingleChannelIQ method createIQ.

public static IQ createIQ(String ID, String to, String from, IQ.Type type) {
    IQ iqPacket = new IQ() {

        public String getChildElementXML() {
            return null;
        }
    };
    iqPacket.setPacketID(ID);
    iqPacket.setTo(to);
    iqPacket.setFrom(from);
    iqPacket.setType(type);
    return iqPacket;
}
Also used : IQ(org.jivesoftware.smack.packet.IQ)

Example 73 with IQ

use of org.jivesoftware.smack.packet.IQ in project Openfire by igniterealtime.

the class ThrottleTestWriter method main.

/**
     * Starts the throttle test write client.
     *
     * @param args application arguments.
     */
public static void main(String[] args) {
    if (args.length != 3) {
        System.out.println("Usage: java ThrottleTestWriter [server] [username] [password]");
        System.exit(0);
    }
    String server = args[0];
    String username = args[1];
    String password = args[2];
    try {
        // Connect to the server, without TLS encryption.
        ConnectionConfiguration config = new ConnectionConfiguration(server);
        config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
        final XMPPConnection con = new XMPPConnection(config);
        System.out.print("Connecting to " + server + "... ");
        con.connect();
        con.login(username, password, "writer");
        System.out.print("success.");
        System.out.println("");
        // Get the "real" server address.
        server = con.getServiceName();
        String writerAddress = username + "@" + server + "/writer";
        final String readerAddress = username + "@" + server + "/reader";
        System.out.println("Registered as " + writerAddress);
        // Look for the reader process.
        System.out.print("Looking for " + readerAddress + "...");
        while (true) {
            IQ testIQ = new Time();
            testIQ.setType(IQ.Type.GET);
            testIQ.setTo(readerAddress);
            PacketCollector collector = con.createPacketCollector(new PacketIDFilter(testIQ.getPacketID()));
            con.sendPacket(testIQ);
            // Wait 5 seconds.
            long start = System.currentTimeMillis();
            Packet result = collector.nextResult(5000);
            collector.cancel();
            // If we got a result, continue.
            if (result != null && result.getError() == null) {
                System.out.println(" found reader. Starting packet flood.");
                break;
            }
            System.out.print(".");
            long end = System.currentTimeMillis();
            if (end - start < 5000) {
                try {
                    Thread.sleep(5000 - (end - start));
                } catch (Exception e) {
                // ignore.
                }
            }
        }
        // Create a process to log how many packets we're writing out.
        Runnable statsRunnable = new Runnable() {

            public void run() {
                while (!done) {
                    try {
                        Thread.sleep(5000);
                    } catch (Exception e) {
                    /* ignore */
                    }
                    int count = packetCount.getAndSet(0);
                    System.out.println("Packets per second: " + (count / 5));
                }
            }
        };
        Thread statsThread = new Thread(statsRunnable);
        statsThread.setDaemon(true);
        statsThread.start();
        // Now start flooding packets.
        Message testMessage = new Message(readerAddress);
        testMessage.setBody("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
        while (!done) {
            con.sendPacket(testMessage);
            packetCount.getAndIncrement();
        }
    } catch (Exception e) {
        System.out.println("\nError: " + e.getMessage());
        e.printStackTrace();
    }
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) Message(org.jivesoftware.smack.packet.Message) IQ(org.jivesoftware.smack.packet.IQ) Time(org.jivesoftware.smackx.packet.Time) XMPPConnection(org.jivesoftware.smack.XMPPConnection) ConnectionConfiguration(org.jivesoftware.smack.ConnectionConfiguration) PacketCollector(org.jivesoftware.smack.PacketCollector) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 74 with IQ

use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.

the class UserSearch method sendSearchForm.

/**
     * Sends the filled out answer form to be sent and queried by the search service.
     *
     * @param con           the current XMPPConnection.
     * @param searchForm    the <code>Form</code> to send for querying.
     * @param searchService the search service to use. (ex. search.jivesoftware.com)
     * @return ReportedData the data found from the query.
     * @throws XMPPErrorException 
     * @throws NoResponseException 
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public ReportedData sendSearchForm(XMPPConnection con, Form searchForm, DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    UserSearch search = new UserSearch();
    search.setType(IQ.Type.set);
    search.setTo(searchService);
    search.addExtension(searchForm.getDataFormToSend());
    IQ response = (IQ) con.createStanzaCollectorAndSend(search).nextResultOrThrow();
    return ReportedData.getReportedDataFrom(response);
}
Also used : SimpleIQ(org.jivesoftware.smack.packet.SimpleIQ) IQ(org.jivesoftware.smack.packet.IQ)

Example 75 with IQ

use of org.jivesoftware.smack.packet.IQ in project intellij-plugins by JetBrains.

the class JabberFacadeImpl method setVCardInfo.

public void setVCardInfo(String nickName, String firstName, String lastName) throws XMPPException {
    assert isConnectedAndAuthenticated() : "Not connected or authenticated";
    VCard vCard = new VCard();
    vCard.setFirstName(firstName);
    vCard.setLastName(lastName);
    vCard.setNickName(nickName);
    PacketCollector collector = myConnection.createPacketCollector(new PacketIDFilter(vCard.getPacketID()));
    vCard.save(myConnection);
    IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from the server.");
    } else // If the server replied with an error, throw an exception.
    if (response.getType() == IQ.Type.ERROR) {
        throw new XMPPException(response.getError());
    }
}
Also used : IQ(org.jivesoftware.smack.packet.IQ) VCard(org.jivesoftware.smackx.packet.VCard) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Aggregations

IQ (org.jivesoftware.smack.packet.IQ)138 Test (org.junit.Test)57 ErrorIQ (org.jivesoftware.smack.packet.ErrorIQ)12 Stanza (org.jivesoftware.smack.packet.Stanza)12 InputStream (java.io.InputStream)11 StanzaListener (org.jivesoftware.smack.StanzaListener)10 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)10 Data (org.jivesoftware.smackx.bytestreams.ibb.packet.Data)10 DataPacketExtension (org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension)10 OutputStream (java.io.OutputStream)9 ArrayList (java.util.ArrayList)9 Bytestream (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream)8 XMPPError (org.jivesoftware.smack.packet.XMPPError)7 Jid (org.jxmpp.jid.Jid)7 NetworkException (com.xabber.android.data.NetworkException)6 OnResponseListener (com.xabber.android.data.connection.OnResponseListener)6 IOException (java.io.IOException)6 XMPPConnection (org.jivesoftware.smack.XMPPConnection)6 EmptyResultIQ (org.jivesoftware.smack.packet.EmptyResultIQ)6 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)6