Search in sources :

Example 36 with ServiceDiscoveryManager

use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager 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 if the calling thread was interrupted.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @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 37 with ServiceDiscoveryManager

use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager 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 if there was no response from the remote entity.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @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 38 with ServiceDiscoveryManager

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

the class MoodIntegrationTest method registerListenerAndWait.

/**
 * Registers a listener for User Tune data. This implicitly publishes a CAPS update to include a notification
 * filter for the mood node. This method blocks until the server has indicated that this update has been
 * received.
 *
 * @param moodManager The MoodManager instance for the connection that is expected to receive data.
 * @param discoManager The ServiceDiscoveryManager instance for the connection that is expected to publish data.
 * @param listener A listener instance for Mood data that is to be registered.
 *
 * @throws Exception if the test fails
 */
public void registerListenerAndWait(MoodManager moodManager, ServiceDiscoveryManager discoManager, PepEventListener<MoodElement> listener) throws Exception {
    final SimpleResultSyncPoint notificationFilterReceived = new SimpleResultSyncPoint();
    final EntityCapabilitiesChangedListener notificationFilterReceivedListener = info -> {
        if (info.containsFeature(MoodManager.MOOD_NODE + "+notify")) {
            notificationFilterReceived.signal();
        }
    };
    discoManager.addEntityCapabilitiesChangedListener(notificationFilterReceivedListener);
    try {
        moodManager.addMoodListener(listener);
        notificationFilterReceived.waitForResult(timeout);
    } finally {
        discoManager.removeEntityCapabilitiesChangedListener(notificationFilterReceivedListener);
    }
}
Also used : SmackException(org.jivesoftware.smack.SmackException) SmackIntegrationTestEnvironment(org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment) AfterClass(org.igniterealtime.smack.inttest.annotations.AfterClass) EntityCapabilitiesChangedListener(org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager) TimeoutException(java.util.concurrent.TimeoutException) MoodElement(org.jivesoftware.smackx.mood.element.MoodElement) PepEventListener(org.jivesoftware.smackx.pep.PepEventListener) Assertions(org.junit.jupiter.api.Assertions) IntegrationTestRosterUtil(org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest) XMPPException(org.jivesoftware.smack.XMPPException) EntityCapabilitiesChangedListener(org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)

Example 39 with ServiceDiscoveryManager

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

the class EntityCapsTest method addFeatureAndWaitForPresence.

/**
 * Adds 'feature' to conB and waits until conA observes a presence form conB.
 *
 * @param conA the connection to observe the presence on.
 * @param conB the connection to add the feature to.
 * @param feature the feature to add.
 * @throws Exception in case of an exception.
 */
private void addFeatureAndWaitForPresence(XMPPConnection conA, XMPPConnection conB, String feature) throws Exception {
    final ServiceDiscoveryManager sdmB = ServiceDiscoveryManager.getInstanceFor(conB);
    ThrowingRunnable action = new ThrowingRunnable() {

        @Override
        public void runOrThrow() throws Exception {
            sdmB.addFeature(feature);
        }
    };
    performActionAndWaitForPresence(conA, conB, action);
}
Also used : ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager) ThrowingRunnable(org.jivesoftware.smack.util.Async.ThrowingRunnable)

Example 40 with ServiceDiscoveryManager

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

the class GeolocationIntegrationTest method publishAndWait.

/**
 * Publish data using PEP, and block until the server has echoed the publication back to the publishing user.
 *
 * @param geoManager The GeoLocationManager instance for the connection that is expected to publish data.
 * @param discoManager The ServiceDiscoveryManager instance for the connection that is expected to publish data.
 * @param data The data to be published.
 *
 * @throws Exception if the test fails
 */
public void publishAndWait(GeoLocationManager geoManager, ServiceDiscoveryManager discoManager, GeoLocation data) throws Exception {
    final SimpleResultSyncPoint publicationEchoReceived = new SimpleResultSyncPoint();
    final PepEventListener<GeoLocation> publicationEchoListener = (jid, geoLocation, id, message) -> {
        if (geoLocation.equals(data)) {
            publicationEchoReceived.signal();
        }
    };
    try {
        registerListenerAndWait(geoManager, discoManager, publicationEchoListener);
        geoManager.addGeoLocationListener(publicationEchoListener);
        geoManager.publishGeoLocation(data);
    } finally {
        geoManager.removeGeoLocationListener(publicationEchoListener);
    }
}
Also used : SmackIntegrationTestEnvironment(org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment) GeoLocation(org.jivesoftware.smackx.geoloc.packet.GeoLocation) AfterClass(org.igniterealtime.smack.inttest.annotations.AfterClass) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) EntityCapabilitiesChangedListener(org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) NotLoggedInException(org.jivesoftware.smack.SmackException.NotLoggedInException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager) TimeoutException(java.util.concurrent.TimeoutException) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) GeoLocationManager(org.jivesoftware.smackx.geoloc.GeoLocationManager) PepEventListener(org.jivesoftware.smackx.pep.PepEventListener) Assertions(org.junit.jupiter.api.Assertions) IntegrationTestRosterUtil(org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil) XmppDateTime(org.jxmpp.util.XmppDateTime) URI(java.net.URI) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest) GeoLocation(org.jivesoftware.smackx.geoloc.packet.GeoLocation) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)

Aggregations

ServiceDiscoveryManager (org.jivesoftware.smackx.disco.ServiceDiscoveryManager)46 XMPPException (org.jivesoftware.smack.XMPPException)15 SmackException (org.jivesoftware.smack.SmackException)14 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)14 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)10 AfterClass (org.igniterealtime.smack.inttest.annotations.AfterClass)7 XMPPConnection (org.jivesoftware.smack.XMPPConnection)7 ArrayList (java.util.ArrayList)6 TimeoutException (java.util.concurrent.TimeoutException)6 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)6 SmackIntegrationTestEnvironment (org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment)6 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)6 IntegrationTestRosterUtil (org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil)6 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)6 EntityCapabilitiesChangedListener (org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener)6 PepEventListener (org.jivesoftware.smackx.pep.PepEventListener)6 Assertions (org.junit.jupiter.api.Assertions)6 URI (java.net.URI)4 NotLoggedInException (org.jivesoftware.smack.SmackException.NotLoggedInException)4 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)3