Search in sources :

Example 36 with DiscoverInfo

use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project Smack by igniterealtime.

the class OfflineMessageManager method getMessageCount.

/**
     * Returns the number of offline messages for the user of the connection.
     *
     * @return the number of offline messages for the user of the connection.
     * @throws XMPPErrorException If the user is not allowed to make this request or the server does
     *                       not support offline message retrieval.
     * @throws NoResponseException if there was no response from the server.
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public int getMessageCount() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    DiscoverInfo info = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(null, namespace);
    Form extendedInfo = Form.getFormFrom(info);
    if (extendedInfo != null) {
        String value = extendedInfo.getField("number_of_messages").getValues().get(0);
        return Integer.parseInt(value);
    }
    return 0;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) Form(org.jivesoftware.smackx.xdata.Form)

Example 37 with DiscoverInfo

use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project Smack by igniterealtime.

the class ConfigureFormTest method getConfigFormWithTimeout.

@Test(expected = SmackException.class)
public void getConfigFormWithTimeout() throws XMPPException, SmackException, InterruptedException {
    ThreadedDummyConnection con = new ThreadedDummyConnection();
    PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE);
    DiscoverInfo info = new DiscoverInfo();
    Identity ident = new Identity("pubsub", null, "leaf");
    info.addIdentity(ident);
    con.addIQReply(info);
    Node node = mgr.getNode("princely_musings");
    SmackConfiguration.setDefaultReplyTimeout(100);
    con.setTimeout();
    node.getNodeConfiguration();
}
Also used : ThreadedDummyConnection(org.jivesoftware.smack.ThreadedDummyConnection) DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) Identity(org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity) Test(org.junit.Test)

Example 38 with DiscoverInfo

use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project Smack by igniterealtime.

the class ConfigureFormTest method getConfigFormWithInsufficientPriviliges.

@Test
public void getConfigFormWithInsufficientPriviliges() throws XMPPException, SmackException, IOException, InterruptedException {
    ThreadedDummyConnection con = ThreadedDummyConnection.newInstance();
    PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE);
    DiscoverInfo info = new DiscoverInfo();
    Identity ident = new Identity("pubsub", null, "leaf");
    info.addIdentity(ident);
    con.addIQReply(info);
    Node node = mgr.getNode("princely_musings");
    PubSub errorIq = new PubSub();
    XMPPError.Builder error = XMPPError.getBuilder(Condition.forbidden);
    errorIq.setError(error);
    con.addIQReply(errorIq);
    try {
        node.getNodeConfiguration();
    } catch (XMPPErrorException e) {
        Assert.assertEquals(XMPPError.Type.AUTH, e.getXMPPError().getType());
    }
}
Also used : ThreadedDummyConnection(org.jivesoftware.smack.ThreadedDummyConnection) DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) XMPPError(org.jivesoftware.smack.packet.XMPPError) Identity(org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity) Test(org.junit.Test)

Example 39 with DiscoverInfo

use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project Smack by igniterealtime.

the class RoomInfoTest method validateRoomWithForm.

@Test
public void validateRoomWithForm() {
    DataForm dataForm = new DataForm(DataForm.Type.result);
    FormField desc = new FormField("muc#roominfo_description");
    desc.addValue("The place for all good witches!");
    dataForm.addField(desc);
    FormField subject = new FormField("muc#roominfo_subject");
    subject.addValue("Spells");
    dataForm.addField(subject);
    FormField occupants = new FormField("muc#roominfo_occupants");
    occupants.addValue("3");
    dataForm.addField(occupants);
    DiscoverInfo discoInfo = new DiscoverInfo();
    discoInfo.addExtension(dataForm);
    RoomInfo roomInfo = new RoomInfo(discoInfo);
    assertEquals("The place for all good witches!", roomInfo.getDescription());
    assertEquals("Spells", roomInfo.getSubject());
    assertEquals(3, roomInfo.getOccupantsCount());
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) FormField(org.jivesoftware.smackx.xdata.FormField) Test(org.junit.Test)

Example 40 with DiscoverInfo

use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project Smack by igniterealtime.

the class PingTest method checkUnuccessfulDiscoRequest.

@Test
public void checkUnuccessfulDiscoRequest() throws Exception {
    ThreadedDummyConnection con = getAuthentiactedDummyConnection();
    DiscoverInfo info = new DiscoverInfo();
    info.addFeature(Ping.NAMESPACE);
    //@formatter:off
    String reply = "<iq type='result' id='qrzSp-16' to='test@myserver.com'>" + "<query xmlns='http://jabber.org/protocol/disco#info'><identity category='client' type='pc' name='Pidgin'/>" + "<feature var='urn:xmpp:noping'/>" + "</query></iq>";
    //@formatter:on
    IQ discoReply = (IQ) PacketParserUtils.parseStanza(reply);
    con.addIQReply(discoReply);
    PingManager pinger = PingManager.getInstanceFor(con);
    boolean pingSupported = pinger.isPingSupported(DUMMY_AT_EXAMPLE_ORG);
    assertFalse(pingSupported);
}
Also used : ThreadedDummyConnection(org.jivesoftware.smack.ThreadedDummyConnection) DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.Test)

Aggregations

DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)58 Test (org.junit.Test)18 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)13 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)11 Identity (org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)11 IOException (java.io.IOException)8 SmackException (org.jivesoftware.smack.SmackException)8 XMPPException (org.jivesoftware.smack.XMPPException)8 Item (org.jivesoftware.smackx.disco.packet.DiscoverItems.Item)8 ConnectException (java.net.ConnectException)7 FeatureNotSupportedException (org.jivesoftware.smack.SmackException.FeatureNotSupportedException)7 ServiceDiscoveryManager (org.jivesoftware.smackx.disco.ServiceDiscoveryManager)7 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)7 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)7 ArrayList (java.util.ArrayList)6 IQ (org.jivesoftware.smack.packet.IQ)6 Bytestream (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream)6 FormField (org.jivesoftware.smackx.xdata.FormField)6 XMPPConnection (org.jivesoftware.smack.XMPPConnection)5 DomainBareJid (org.jxmpp.jid.DomainBareJid)5