Search in sources :

Example 41 with DiscoverInfo

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

the class Workgroup method isEmailAvailable.

/**
     * The workgroup service may be configured to send email. This queries the Workgroup Service
     * to see if the email service has been configured and is available.
     *
     * @return true if the email service is available, otherwise return false.
     * @throws SmackException 
     * @throws InterruptedException 
     */
public boolean isEmailAvailable() throws SmackException, InterruptedException {
    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
    try {
        DomainBareJid workgroupService = workgroupJID.asDomainBareJid();
        DiscoverInfo infoResult = discoManager.discoverInfo(workgroupService);
        return infoResult.containsFeature("jive:email:provider");
    } catch (XMPPException e) {
        return false;
    }
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) XMPPException(org.jivesoftware.smack.XMPPException) DomainBareJid(org.jxmpp.jid.DomainBareJid) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 42 with DiscoverInfo

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

the class IoTDiscoveryManager method findRegistry.

/**
     * Try to find an XMPP IoT registry.
     *
     * @return the JID of a Thing Registry if one could be found, <code>null</code> otherwise.
     * @throws InterruptedException
     * @throws NotConnectedException
     * @throws XMPPErrorException
     * @throws NoResponseException
     * @see <a href="http://xmpp.org/extensions/xep-0347.html#findingregistry">XEP-0347 § 3.5 Finding Thing Registry</a>
     */
public Jid findRegistry() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    if (preconfiguredRegistry != null) {
        return preconfiguredRegistry;
    }
    final XMPPConnection connection = connection();
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
    List<DiscoverInfo> discoverInfos = sdm.findServicesDiscoverInfo(Constants.IOT_DISCOVERY_NAMESPACE, true, true);
    if (!discoverInfos.isEmpty()) {
        return discoverInfos.get(0).getFrom();
    }
    return null;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) XMPPConnection(org.jivesoftware.smack.XMPPConnection) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 43 with DiscoverInfo

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

the class IoTProvisioningManager method findProvisioningServerComponent.

/**
     * Try to find a provisioning server component.
     * 
     * @return the XMPP address of the provisioning server component if one was found.
     * @throws NoResponseException
     * @throws XMPPErrorException
     * @throws NotConnectedException
     * @throws InterruptedException
     * @see <a href="http://xmpp.org/extensions/xep-0324.html#servercomponent">XEP-0324 § 3.1.2 Provisioning Server as a server component</a>
     */
public DomainBareJid findProvisioningServerComponent() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    final XMPPConnection connection = connection();
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
    List<DiscoverInfo> discoverInfos = sdm.findServicesDiscoverInfo(Constants.IOT_PROVISIONING_NAMESPACE, true, true);
    if (discoverInfos.isEmpty()) {
        return null;
    }
    Jid jid = discoverInfos.get(0).getFrom();
    assert (jid.isDomainBareJid());
    return jid.asDomainBareJid();
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) DomainBareJid(org.jxmpp.jid.DomainBareJid) Jid(org.jxmpp.jid.Jid) BareJid(org.jxmpp.jid.BareJid) XMPPConnection(org.jivesoftware.smack.XMPPConnection) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 44 with DiscoverInfo

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

the class ServiceDiscoveryManager method findServices.

/**
     * Find all services under the users service that provide a given feature.
     * 
     * @param feature the feature to search for
     * @param stopOnFirst if true, stop searching after the first service was found
     * @param useCache if true, query a cache first to avoid network I/O
     * @return a possible empty list of services providing the given feature
     * @throws NoResponseException
     * @throws XMPPErrorException
     * @throws NotConnectedException
     * @throws InterruptedException 
     */
public List<DomainBareJid> findServices(String feature, boolean stopOnFirst, boolean useCache) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    List<DiscoverInfo> services = findServicesDiscoverInfo(feature, stopOnFirst, useCache);
    List<DomainBareJid> res = new ArrayList<>(services.size());
    for (DiscoverInfo info : services) {
        res.add(info.getFrom().asDomainBareJid());
    }
    return res;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) ArrayList(java.util.ArrayList) DomainBareJid(org.jxmpp.jid.DomainBareJid)

Example 45 with DiscoverInfo

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

the class EntityCapsManager method updateLocalEntityCaps.

/**
     * Updates the local user Entity Caps information with the data provided
     *
     * If we are connected and there was already a presence send, another
     * presence is send to inform others about your new Entity Caps node string.
     *
     */
public void updateLocalEntityCaps() {
    XMPPConnection connection = connection();
    DiscoverInfo discoverInfo = new DiscoverInfo();
    discoverInfo.setType(IQ.Type.result);
    sdm.addDiscoverInfoTo(discoverInfo);
    // getLocalNodeVer() will return a result only after currentCapsVersion is set. Therefore
    // set it first and then call getLocalNodeVer()
    currentCapsVersion = generateVerificationString(discoverInfo);
    final String localNodeVer = getLocalNodeVer();
    discoverInfo.setNode(localNodeVer);
    addDiscoverInfoByNode(localNodeVer, discoverInfo);
    if (lastLocalCapsVersions.size() > 10) {
        CapsVersionAndHash oldCapsVersion = lastLocalCapsVersions.poll();
        sdm.removeNodeInformationProvider(entityNode + '#' + oldCapsVersion.version);
    }
    lastLocalCapsVersions.add(currentCapsVersion);
    if (connection != null)
        JID_TO_NODEVER_CACHE.put(connection.getUser(), new NodeVerHash(entityNode, currentCapsVersion));
    final List<Identity> identities = new LinkedList<Identity>(ServiceDiscoveryManager.getInstanceFor(connection).getIdentities());
    sdm.setNodeInformationProvider(localNodeVer, new AbstractNodeInformationProvider() {

        List<String> features = sdm.getFeatures();

        List<ExtensionElement> packetExtensions = sdm.getExtendedInfoAsList();

        @Override
        public List<String> getNodeFeatures() {
            return features;
        }

        @Override
        public List<Identity> getNodeIdentities() {
            return identities;
        }

        @Override
        public List<ExtensionElement> getNodePacketExtensions() {
            return packetExtensions;
        }
    });
    // to respect ConnectionConfiguration.isSendPresence()
    if (connection != null && connection.isAuthenticated() && presenceSend != null) {
        try {
            connection.sendStanza(presenceSend.cloneWithNewId());
        } catch (InterruptedException | NotConnectedException e) {
            LOGGER.log(Level.WARNING, "Could could not update presence with caps info", e);
        }
    }
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) AbstractNodeInformationProvider(org.jivesoftware.smackx.disco.AbstractNodeInformationProvider) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) XMPPConnection(org.jivesoftware.smack.XMPPConnection) LinkedList(java.util.LinkedList) List(java.util.List) LinkedList(java.util.LinkedList) Identity(org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)

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