Search in sources :

Example 26 with IQ

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

the class MUCLightBlockingTest method checkGetBlockingListResponse.

@Test
public void checkGetBlockingListResponse() throws Exception {
    IQ iqInfoResult = (IQ) PacketParserUtils.parseStanza(getBlockingListIQResponse);
    MUCLightBlockingIQ mucLightBlockingIQ = (MUCLightBlockingIQ) iqInfoResult;
    Assert.assertEquals(2, mucLightBlockingIQ.getRooms().size());
    Assert.assertEquals(1, mucLightBlockingIQ.getUsers().size());
    Assert.assertEquals(false, mucLightBlockingIQ.getRooms().get(JidCreate.from("coven@muclight.shakespeare.lit")));
    Assert.assertEquals(false, mucLightBlockingIQ.getRooms().get(JidCreate.from("sarasa@muclight.shakespeare.lit")));
    Assert.assertEquals(false, mucLightBlockingIQ.getUsers().get(JidCreate.from("hag77@shakespeare.lit")));
}
Also used : MUCLightBlockingIQ(org.jivesoftware.smackx.muclight.element.MUCLightBlockingIQ) MUCLightBlockingIQ(org.jivesoftware.smackx.muclight.element.MUCLightBlockingIQ) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.Test)

Example 27 with IQ

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

the class HttpOverXmppReqProviderTest method parseReq.

private static HttpOverXmppReq parseReq(String string) throws Exception {
    HttpOverXmppReqProvider provider = new HttpOverXmppReqProvider();
    XmlPullParser parser = PacketParserUtils.getParserFor(string);
    IQ iq = provider.parse(parser);
    assertTrue(iq instanceof HttpOverXmppReq);
    HttpOverXmppReq castedIq = (HttpOverXmppReq) iq;
    return castedIq;
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) IQ(org.jivesoftware.smack.packet.IQ) HttpOverXmppReq(org.jivesoftware.smackx.hoxt.packet.HttpOverXmppReq)

Example 28 with IQ

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

the class CompressionTest method testSuccessCompression.

/**
     * Test that stream compression works fine. It is assumed that the server supports and has
     * stream compression enabled.
     */
public void testSuccessCompression() throws XMPPException {
    // Create the configuration for this new connection
    ConnectionConfiguration config = new ConnectionConfiguration(getHost(), getPort());
    config.setCompressionEnabled(true);
    config.setSASLAuthenticationEnabled(true);
    XMPPTCPConnection connection = new XMPPConnection(config);
    connection.connect();
    // Login with the test account
    connection.login("user0", "user0");
    assertTrue("XMPPConnection is not using stream compression", connection.isUsingCompression());
    // Request the version of the server
    Version version = new Version();
    version.setType(IQ.Type.get);
    version.setTo(getXMPPServiceDomain());
    // Create a packet collector to listen for a response.
    StanzaCollector collector = connection.createStanzaCollector(new PacketIDFilter(version.getStanzaId()));
    connection.sendStanza(version);
    // Wait up to 5 seconds for a result.
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Close the collector
    collector.cancel();
    assertNotNull("No reply was received from the server", result);
    assertEquals("Incorrect IQ type from server", IQ.Type.result, result.getType());
    // Close connection
    connection.disconnect();
}
Also used : Version(org.jivesoftware.smackx.packet.Version) IQ(org.jivesoftware.smack.packet.IQ) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 29 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 30 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)

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