/** * 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<DiscoverInfo> findServicesDiscoverInfo(String feature, boolean stopOnFirst, boolean useCache) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return findServicesDiscoverInfo(feature, stopOnFirst, useCache, null); }
/** * 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; }
/** * Discover upload service. * * Called automatically when connection is authenticated. * * Note that this is a synchronous call -- Smack must wait for the server response. * * @return true if upload service was discovered * @throws XMPPException.XMPPErrorException * @throws SmackException.NotConnectedException * @throws InterruptedException * @throws SmackException.NoResponseException */ public boolean discoverUploadService() throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException { ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection()); List<DiscoverInfo> servicesDiscoverInfo = sdm .findServicesDiscoverInfo(NAMESPACE, true, true); if (servicesDiscoverInfo.isEmpty()) { servicesDiscoverInfo = sdm.findServicesDiscoverInfo(NAMESPACE_0_2, true, true); if (servicesDiscoverInfo.isEmpty()) { return false; } } DiscoverInfo discoverInfo = servicesDiscoverInfo.get(0); defaultUploadService = uploadServiceFrom(discoverInfo); return true; }
/** * 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 * @param encounteredExceptions an optional map which will be filled with the exceptions encountered * @return a possible empty list of services providing the given feature * @throws NoResponseException * @throws XMPPErrorException * @throws NotConnectedException * @throws InterruptedException * @since 4.2.2 */ public List<DiscoverInfo> findServicesDiscoverInfo(String feature, boolean stopOnFirst, boolean useCache, Map<? super Jid, Exception> encounteredExceptions) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { DomainBareJid serviceName = connection().getXMPPServiceDomain(); return findServicesDiscoverInfo(serviceName, feature, stopOnFirst, useCache, encounteredExceptions); }
/** * 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; }
/** * 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(); }
public DomainBareJid findService(String feature, boolean useCache, String category, String type) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { boolean noCategory = StringUtils.isNullOrEmpty(category); boolean noType = StringUtils.isNullOrEmpty(type); if (noType != noCategory) { throw new IllegalArgumentException("Must specify either both, category and type, or none"); } List<DiscoverInfo> services = findServicesDiscoverInfo(feature, false, useCache); if (services.isEmpty()) { return null; } if (!noCategory && !noType) { for (DiscoverInfo info : services) { if (info.hasIdentity(category, type)) { return info.getFrom().asDomainBareJid(); } } } return services.get(0).getFrom().asDomainBareJid(); }
/** * Discover upload service. * * Called automatically when connection is authenticated. * * Note that this is a synchronous call -- Smack must wait for the server response. * * @return true if upload service was discovered * @throws XMPPException.XMPPErrorException * @throws SmackException.NotConnectedException * @throws InterruptedException * @throws SmackException.NoResponseException */ public boolean discoverUploadService() throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException { ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection()); List<DiscoverInfo> servicesDiscoverInfo = sdm .findServicesDiscoverInfo(NAMESPACE, true, true); if (servicesDiscoverInfo.isEmpty()) { servicesDiscoverInfo = sdm.findServicesDiscoverInfo(NAMESPACE_0_2, true, true); if (servicesDiscoverInfo.isEmpty()) { return false; } } DiscoverInfo discoverInfo = servicesDiscoverInfo.get(0); defaultUploadService = uploadServiceFrom(discoverInfo); return true; }
/** * 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; }
/** * 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(); }