Search in sources :

Example 41 with ServiceDiscoveryManager

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

the class GeolocationIntegrationTest method registerListenerAndWait.

/**
 * Registers a listener for GeoLocation data. This implicitly publishes a CAPS update to include a notification
 * filter for the geolocation node. This method blocks until the server has indicated that this update has been
 * received.
 *
 * @param geoManager The GeoLocationManager 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 GeoLocation data that is to be registered.
 *
 * @throws Exception if the test fails
 */
public void registerListenerAndWait(GeoLocationManager geoManager, ServiceDiscoveryManager discoManager, PepEventListener<GeoLocation> listener) throws Exception {
    final SimpleResultSyncPoint notificationFilterReceived = new SimpleResultSyncPoint();
    final EntityCapabilitiesChangedListener notificationFilterReceivedListener = info -> {
        if (info.containsFeature(GeoLocationManager.GEOLOCATION_NODE + "+notify")) {
            notificationFilterReceived.signal();
        }
    };
    discoManager.addEntityCapabilitiesChangedListener(notificationFilterReceivedListener);
    try {
        geoManager.addGeoLocationListener(listener);
        notificationFilterReceived.waitForResult(timeout);
    } finally {
        discoManager.removeEntityCapabilitiesChangedListener(notificationFilterReceivedListener);
    }
}
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) EntityCapabilitiesChangedListener(org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)

Example 42 with ServiceDiscoveryManager

use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager 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 if Smack detected an exceptional situation.
 * @throws InterruptedException if the calling thread was interrupted.
 */
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 43 with ServiceDiscoveryManager

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

the class HttpFileUploadManager method discoverUploadService.

/**
 * 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 if there was an XMPP error returned.
 * @throws SmackException.NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws SmackException.NoResponseException if there was no response from the remote entity.
 */
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;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 44 with ServiceDiscoveryManager

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

the class Socks5ByteStreamManagerTest method shouldDisableService.

/**
 * The SOCKS5 Bytestream feature should be removed form the service discovery manager if Socks5
 * bytestream feature is disabled.
 *
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws SmackException if Smack detected an exceptional situation.
 * @throws XMPPErrorException if there was an XMPP error returned.
 */
@Test
public void shouldDisableService() throws XMPPErrorException, SmackException, InterruptedException {
    final Protocol protocol = new Protocol();
    final XMPPConnection connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID);
    Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
    ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
    assertTrue(discoveryManager.includesFeature(Bytestream.NAMESPACE));
    byteStreamManager.disableService();
    assertFalse(discoveryManager.includesFeature(Bytestream.NAMESPACE));
}
Also used : XMPPConnection(org.jivesoftware.smack.XMPPConnection) Protocol(org.jivesoftware.util.Protocol) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager) Test(org.junit.jupiter.api.Test)

Example 45 with ServiceDiscoveryManager

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

the class PepManager method isSupported.

public boolean isSupported() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    XMPPConnection connection = connection();
    ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
    BareJid localBareJid = connection.getUser().asBareJid();
    return serviceDiscoveryManager.supportsFeatures(localBareJid, REQUIRED_FEATURES);
}
Also used : EntityBareJid(org.jxmpp.jid.EntityBareJid) BareJid(org.jxmpp.jid.BareJid) XMPPConnection(org.jivesoftware.smack.XMPPConnection) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

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