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;
}
}
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;
}
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();
}
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;
}
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);
}
}
}
Aggregations