Search in sources :

Example 91 with IQ

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

the class MultiUserChat method getRegistrationForm.

/**
     * Returns the room's registration form that an unaffiliated user, can use to become a member
     * of the room or <tt>null</tt> if no registration is possible. Some rooms may restrict the
     * privilege to register members and allow only room admins to add new members.<p>
     *
     * If the user requesting registration requirements is not allowed to register with the room
     * (e.g. because that privilege has been restricted), the room will return a "Not Allowed"
     * error to the user (error code 405).
     *
     * @return the registration Form that contains the fields to complete together with the
     * instrucions or <tt>null</tt> if no registration is possible.
     * @throws XMPPErrorException if an error occurs asking the registration form for the room or a
     * 405 error if the user is not allowed to register with the room.
     * @throws NoResponseException if there was no response from the server.
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public Form getRegistrationForm() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.get);
    reg.setTo(room);
    IQ result = connection.createStanzaCollectorAndSend(reg).nextResultOrThrow();
    return Form.getFormFrom(result);
}
Also used : Registration(org.jivesoftware.smackx.iqregister.packet.Registration) IQ(org.jivesoftware.smack.packet.IQ)

Example 92 with IQ

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

the class MultiUserChat method getConfigurationForm.

/**
     * Returns the room's configuration form that the room's owner can use or <tt>null</tt> if
     * no configuration is possible. The configuration form allows to set the room's language,
     * enable logging, specify room's type, etc..
     *
     * @return the Form that contains the fields to complete together with the instrucions or
     * <tt>null</tt> if no configuration is possible.
     * @throws XMPPErrorException if an error occurs asking the configuration form for the room.
     * @throws NoResponseException if there was no response from the server.
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public Form getConfigurationForm() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.get);
    IQ answer = connection.createStanzaCollectorAndSend(iq).nextResultOrThrow();
    return Form.getFormFrom(answer);
}
Also used : IQ(org.jivesoftware.smack.packet.IQ) MUCOwner(org.jivesoftware.smackx.muc.packet.MUCOwner)

Example 93 with IQ

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

the class UserSearch method getSearchForm.

/**
     * Returns the form for all search fields supported by the search service.
     *
     * @param con           the current XMPPConnection.
     * @param searchService the search service to use. (ex. search.jivesoftware.com)
     * @return the search form received by the server.
     * @throws XMPPErrorException 
     * @throws NoResponseException 
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public Form getSearchForm(XMPPConnection con, DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    UserSearch search = new UserSearch();
    search.setType(IQ.Type.get);
    search.setTo(searchService);
    IQ response = (IQ) con.createStanzaCollectorAndSend(search).nextResultOrThrow();
    return Form.getFormFrom(response);
}
Also used : SimpleIQ(org.jivesoftware.smack.packet.SimpleIQ) IQ(org.jivesoftware.smack.packet.IQ)

Example 94 with IQ

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

the class RosterTest method testEmptyGroupRosterPush.

/**
     * Test processing a roster push with an empty group is equivalent with providing
     * no group.
     * 
     * @see <a href="http://www.igniterealtime.org/issues/browse/SMACK-294">SMACK-294</a>
     */
@Test
public void testEmptyGroupRosterPush() throws Throwable {
    final BareJid contactJID = JidCreate.entityBareFrom("nurse@example.com");
    assertNotNull("Can't get the roster from the provided connection!", roster);
    final StringBuilder sb = new StringBuilder();
    sb.append("<iq id=\"rostertest2\" type=\"set\" ").append("to=\"").append(connection.getUser()).append("\">").append("<query xmlns=\"jabber:iq:roster\">").append("<item jid=\"").append(contactJID).append("\">").append("<group></group>").append("</item>").append("</query>").append("</iq>");
    final XmlPullParser parser = TestUtils.getIQParser(sb.toString());
    final IQ rosterPush = PacketParserUtils.parseIQ(parser);
    initRoster();
    rosterListener.reset();
    // Simulate receiving the roster push
    connection.processStanza(rosterPush);
    rosterListener.waitUntilInvocationOrTimeout();
    // Verify the roster entry of the new contact
    final RosterEntry addedEntry = roster.getEntry(contactJID);
    assertNotNull("The new contact wasn't added to the roster!", addedEntry);
    assertTrue("The roster listener wasn't invoked for the new contact!", rosterListener.getAddedAddresses().contains(contactJID));
    assertSame("Setup wrong default subscription status!", ItemType.none, addedEntry.getType());
    assertSame("The new contact shouldn't be member of any group!", 0, addedEntry.getGroups().size());
    // Verify the unchanged roster items
    verifyRomeosEntry(roster.getEntry(JidCreate.entityBareFrom("romeo@example.net")));
    verifyMercutiosEntry(roster.getEntry(JidCreate.entityBareFrom("mercutio@example.com")));
    verifyBenvoliosEntry(roster.getEntry(JidCreate.entityBareFrom("benvolio@example.net")));
    assertSame("Wrong number of roster entries.", 4, roster.getEntries().size());
}
Also used : BareJid(org.jxmpp.jid.BareJid) XmlPullParser(org.xmlpull.v1.XmlPullParser) ErrorIQ(org.jivesoftware.smack.packet.ErrorIQ) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.Test)

Example 95 with IQ

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

the class RosterTest method testSimpleRosterPush.

/**
     * Test a simple roster push according to the example in
     * <a href="http://xmpp.org/internet-drafts/draft-ietf-xmpp-3921bis-03.html#roster-syntax-actions-push"
     *     >RFC3921bis-03: Roster Push</a>.
     */
@Test
public void testSimpleRosterPush() throws Throwable {
    final BareJid contactJID = JidCreate.entityBareFrom("nurse@example.com");
    assertNotNull("Can't get the roster from the provided connection!", roster);
    final StringBuilder sb = new StringBuilder();
    sb.append("<iq id=\"rostertest1\" type=\"set\" ").append("to=\"").append(connection.getUser()).append("\">").append("<query xmlns=\"jabber:iq:roster\">").append("<item jid=\"").append(contactJID).append("\"/>").append("</query>").append("</iq>");
    final XmlPullParser parser = TestUtils.getIQParser(sb.toString());
    final IQ rosterPush = PacketParserUtils.parseIQ(parser);
    initRoster();
    rosterListener.reset();
    // Simulate receiving the roster push
    connection.processStanza(rosterPush);
    rosterListener.waitUntilInvocationOrTimeout();
    // Verify the roster entry of the new contact
    final RosterEntry addedEntry = roster.getEntry(contactJID);
    assertNotNull("The new contact wasn't added to the roster!", addedEntry);
    assertTrue("The roster listener wasn't invoked for the new contact!", rosterListener.getAddedAddresses().contains(contactJID));
    assertSame("Setup wrong default subscription status!", ItemType.none, addedEntry.getType());
    assertSame("The new contact shouldn't be member of any group!", 0, addedEntry.getGroups().size());
    // Verify the unchanged roster items
    verifyRomeosEntry(roster.getEntry(JidCreate.entityBareFrom("romeo@example.net")));
    verifyMercutiosEntry(roster.getEntry(JidCreate.entityBareFrom("mercutio@example.com")));
    verifyBenvoliosEntry(roster.getEntry(JidCreate.entityBareFrom("benvolio@example.net")));
    assertSame("Wrong number of roster entries.", 4, roster.getEntries().size());
}
Also used : BareJid(org.jxmpp.jid.BareJid) XmlPullParser(org.xmlpull.v1.XmlPullParser) ErrorIQ(org.jivesoftware.smack.packet.ErrorIQ) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.Test)

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