Search in sources :

Example 6 with DiscoverInfo

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

the class ServiceDiscoveryManager method findService.

public DomainBareJid findService(String feature, boolean useCache, String category, String type) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    List<DiscoverInfo> services = findServicesDiscoverInfo(feature, true, useCache);
    if (services.isEmpty()) {
        return null;
    }
    DiscoverInfo info = services.get(0);
    if (category != null && type != null) {
        if (!info.hasIdentity(category, type)) {
            return null;
        }
    } else if (category != null || type != null) {
        throw new IllegalArgumentException("Must specify either both, category and type, or none");
    }
    return info.getFrom().asDomainBareJid();
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo)

Example 7 with DiscoverInfo

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

the class ServiceDiscoveryManager method discoverInfo.

/**
     * Returns the discovered information of a given XMPP entity addressed by its JID.
     * Use null as entityID to query the server
     * 
     * @param entityID the address of the XMPP entity or null.
     * @return the discovered information.
     * @throws XMPPErrorException 
     * @throws NoResponseException 
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public DiscoverInfo discoverInfo(Jid entityID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    if (entityID == null)
        return discoverInfo(null, null);
    // Check if the have it cached in the Entity Capabilities Manager
    DiscoverInfo info = EntityCapsManager.getDiscoverInfoByUser(entityID);
    if (info != null) {
        // avoided a disco request, hurray!
        return info;
    }
    // Try to get the newest node#version if it's known, otherwise null is
    // returned
    EntityCapsManager.NodeVerHash nvh = EntityCapsManager.getNodeVerHashByJid(entityID);
    // Discover by requesting the information from the remote entity
    // Note that wee need to use NodeVer as argument for Node if it exists
    info = discoverInfo(entityID, nvh != null ? nvh.getNodeVer() : null);
    // If the node version is known, store the new entry.
    if (nvh != null) {
        if (EntityCapsManager.verifyDiscoverInfoVersion(nvh.getVer(), nvh.getHash(), info))
            EntityCapsManager.addDiscoverInfoByNode(nvh.getNodeVer(), info);
    }
    return info;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) EntityCapsManager(org.jivesoftware.smackx.caps.EntityCapsManager)

Example 8 with DiscoverInfo

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

the class ServiceDiscoveryManager method discoverInfo.

/**
     * Returns the discovered information of a given XMPP entity addressed by its JID and
     * note attribute. Use this message only when trying to query information which is not 
     * directly addressable.
     * 
     * @see <a href="http://xmpp.org/extensions/xep-0030.html#info-basic">XEP-30 Basic Protocol</a>
     * @see <a href="http://xmpp.org/extensions/xep-0030.html#info-nodes">XEP-30 Info Nodes</a>
     * 
     * @param entityID the address of the XMPP entity.
     * @param node the optional attribute that supplements the 'jid' attribute.
     * @return the discovered information.
     * @throws XMPPErrorException if the operation failed for some reason.
     * @throws NoResponseException if there was no response from the server.
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public DiscoverInfo discoverInfo(Jid entityID, String node) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    // Discover the entity's info
    DiscoverInfo disco = new DiscoverInfo();
    disco.setType(IQ.Type.get);
    disco.setTo(entityID);
    disco.setNode(node);
    Stanza result = connection().createStanzaCollectorAndSend(disco).nextResultOrThrow();
    return (DiscoverInfo) result;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) Stanza(org.jivesoftware.smack.packet.Stanza)

Example 9 with DiscoverInfo

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

the class SimpleDirectoryPersistentCache method lookup.

@Override
public DiscoverInfo lookup(String nodeVer) {
    File nodeFile = getFileFor(nodeVer);
    if (!nodeFile.isFile()) {
        return null;
    }
    DiscoverInfo info = null;
    try {
        info = restoreInfoFromFile(nodeFile);
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Coud not restore info from file", e);
    }
    return info;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) File(java.io.File) IOException(java.io.IOException)

Example 10 with DiscoverInfo

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

the class RTPBridge method serviceAvailable.

/**
     * Check if the server support RTPBridge Service.
     *
     * @param connection
     * @return true if the server supports the RTPBridge service
     * @throws XMPPErrorException 
     * @throws NoResponseException 
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public static boolean serviceAvailable(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    if (!connection.isConnected()) {
        return false;
    }
    LOGGER.fine("Service listing");
    ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(connection);
    //            DiscoverItems items = disco.discoverItems(connection.getXMPPServiceDomain());
    //            Iterator iter = items.getItems();
    //            while (iter.hasNext()) {
    //                DiscoverItems.Item item = (DiscoverItems.Item) iter.next();
    //                if (item.getEntityID().startsWith("rtpbridge.")) {
    //                    return true;
    //                }
    //            }
    DiscoverInfo discoInfo = disco.discoverInfo(connection.getXMPPServiceDomain());
    for (DiscoverInfo.Identity identity : discoInfo.getIdentities()) {
        if ((identity.getName() != null) && (identity.getName().startsWith("rtpbridge"))) {
            return true;
        }
    }
    return false;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Aggregations

DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)53 Test (org.junit.Test)18 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)12 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 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 ArrayList (java.util.ArrayList)4 ThreadedDummyConnection (org.jivesoftware.smack.ThreadedDummyConnection)4