Java Code Examples for org.jivesoftware.smackx.disco.ServiceDiscoveryManager#getInstanceFor()

The following examples show how to use org.jivesoftware.smackx.disco.ServiceDiscoveryManager#getInstanceFor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransportUtils.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the user is registered with a gateway.
 *
 * @param con       the XMPPConnection.
 * @param transport the transport.
 * @return true if the user is registered with the transport.
 */
public static boolean isRegistered(XMPPConnection con, Transport transport) {
    if (!con.isConnected()) {
        return false;
    }

    ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(con);
    try {
        Jid jid = JidCreate.from(transport.getXMPPServiceDomain());
        DiscoverInfo info = discoveryManager.discoverInfo(jid);
        return info.containsFeature("jabber:iq:registered");
    }
    catch (XMPPException | SmackException | XmppStringprepException | InterruptedException e) {
        Log.error(e);
    }
    return false;
}
 
Example 2
Source File: BoBManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
private BoBManager(XMPPConnection connection) {
    super(connection);
    ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
    serviceDiscoveryManager.addFeature(NAMESPACE);

    connection.registerIQRequestHandler(
            new AbstractIqRequestHandler(BoBIQ.ELEMENT, BoBIQ.NAMESPACE, Type.get, Mode.async) {
                @Override
                public IQ handleIQRequest(IQ iqRequest) {
                    BoBIQ bobIQRequest = (BoBIQ) iqRequest;

                    BoBInfo bobInfo = bobs.get(bobIQRequest.getBoBHash());
                    if (bobInfo == null) {
                        // TODO return item-not-found
                        return null;
                    }

                    BoBData bobData = bobInfo.getData();
                    BoBIQ responseBoBIQ = new BoBIQ(bobIQRequest.getBoBHash(), bobData);
                    responseBoBIQ.setType(Type.result);
                    responseBoBIQ.setTo(bobIQRequest.getFrom());
                    return responseBoBIQ;
                }
            });
}
 
Example 3
Source File: Enterprise.java    From Spark with Apache License 2.0 6 votes vote down vote up
private void populateFeatureSet() {
    final ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());
    final DiscoverItems items = SparkManager.getSessionManager().getDiscoveredItems();
    for (DiscoverItems.Item item : items.getItems() ) {
        String entity = item.getEntityID().toString();
        if (entity != null) {
            if (entity.startsWith("manager.")) {
                sparkManagerInstalled = true;

                // Populate with feature sets.
                try {
                    featureInfo = disco.discoverInfo(item.getEntityID());
                }
                catch (XMPPException | SmackException | InterruptedException e) {
                    Log.error("Error while retrieving feature list for SparkManager.", e);
                }

            }
        }
    }
}
 
Example 4
Source File: FileTransferNegotiator.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Checks to see if all file transfer related services are enabled on the
 * connection.
 *
 * @param connection The connection to check
 * @return True if all related services are enabled, false if they are not.
 */
public static boolean isServiceEnabled(final XMPPConnection connection) {
    ServiceDiscoveryManager manager = ServiceDiscoveryManager
            .getInstanceFor(connection);

    List<String> namespaces = new ArrayList<>();
    namespaces.addAll(Arrays.asList(NAMESPACE));
    namespaces.add(DataPacketExtension.NAMESPACE);
    if (!IBB_ONLY) {
        namespaces.add(Bytestream.NAMESPACE);
    }

    for (String namespace : namespaces) {
        if (!manager.includesFeature(namespace)) {
            return false;
        }
    }
    return true;
}
 
Example 5
Source File: Socks5ByteStreamManagerTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example 6
Source File: SparkManager.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a feature that can be discovered through Disco.
 *
 * @param namespace the namespace of the feature.
 */
public static void addFeature(String namespace) {
    // Obtain the ServiceDiscoveryManager associated with my XMPPConnection
    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(getConnection());

    // Register that a new feature is supported by this XMPP entity
    discoManager.addFeature(namespace);
}
 
Example 7
Source File: Workgroup.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 8
Source File: EntityTimeManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
public synchronized void enable() {
    if (enabled)
        return;
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection());
    sdm.addFeature(Time.NAMESPACE);
    enabled = true;
}
 
Example 9
Source File: ConferenceUtils.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the room requires a password.
 *
 * @param roomJID the JID of the room.
 * @return true if the room requires a password.
 */
public static boolean isPasswordRequired(EntityBareJid roomJID) {
    // Check to see if the room is password protected
	ServiceDiscoveryManager discover = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());

    try {
        DiscoverInfo info = discover.discoverInfo(roomJID);
        return info.containsFeature("muc_passwordprotected");
    }
    catch (XMPPException | SmackException | InterruptedException e) {
        Log.error(e);
    }
    return false;
}
 
Example 10
Source File: RTPBridge.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
     * Check if the server support RTPBridge Service.
     *
     * @param connection TODO javadoc me please
     * @return true if the server supports the RTPBridge service
     * @throws XMPPErrorException if there was an XMPP error returned.
     * @throws NoResponseException if there was no response from the remote entity.
     * @throws NotConnectedException if the XMPP connection is not connected.
     * @throws InterruptedException if the calling thread was interrupted.
     */
    public static boolean serviceAvailable(XMPPConnection connection) throws NoResponseException,
                    XMPPErrorException, NotConnectedException, InterruptedException {

        if (!connection.isConnected()) {
            return false;
        }

        LOGGER.fine("Service listing");

        ServiceDiscoveryManager disco = ServiceDiscoveryManager
                .getInstanceFor(connection);
//            DiscoverItems items = disco.discoverItems(connection.getXMPPServiceDomain());
//            Iterator iter = items.getItems();
//            while (iter.hasNext()) {
//                DiscoverItems.Item item = (DiscoverItems.Item) iter.next();
//                if (item.getEntityID().startsWith("rtpbridge.")) {
//                    return true;
//                }
//            }

        DiscoverInfo discoInfo = disco.discoverInfo(connection.getXMPPServiceDomain());
        for (DiscoverInfo.Identity identity : discoInfo.getIdentities()) {
            if (identity.getName() != null && identity.getName().startsWith("rtpbridge")) {
                return true;
            }
        }

        return false;
    }
 
Example 11
Source File: XDataValidationManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Override
public void connectionCreated(XMPPConnection connection) {
    ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
    serviceDiscoveryManager.addFeature(ValidateElement.NAMESPACE);
}
 
Example 12
Source File: DnsOverXmppManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
private DnsOverXmppManager(XMPPConnection connection) {
    super(connection);
    this.serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
}
 
Example 13
Source File: MamManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
private MamManager(XMPPConnection connection, Jid archiveAddress) {
    super(connection);
    this.archiveAddress = archiveAddress;
    serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
    adHocCommandManager = AdHocCommandManager.getAddHocCommandsManager(connection);
}
 
Example 14
Source File: MessageFasteningManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
/**
 * Announce support for Message Fastening via Service Discovery.
 */
public void announceSupport() {
    ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(connection());
    discoveryManager.addFeature(NAMESPACE);
}
 
Example 15
Source File: Socks5BytestreamManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
/**
 * Adds the SOCKS5 Bytestream feature to the service discovery.
 */
private void enableService() {
    ServiceDiscoveryManager manager = ServiceDiscoveryManager.getInstanceFor(connection());
    manager.addFeature(Bytestream.NAMESPACE);
}
 
Example 16
Source File: OfflineMessageManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
private OfflineMessageManager(XMPPConnection connection) {
    super(connection);
    this.serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
}
 
Example 17
Source File: XDataLayoutManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Override
public void connectionCreated(XMPPConnection connection) {
    ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
    serviceDiscoveryManager.addFeature(DataLayout.NAMESPACE);
}
 
Example 18
Source File: XDataManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
private XDataManager(XMPPConnection connection) {
    super(connection);
    ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
    serviceDiscoveryManager.addFeature(NAMESPACE);
}
 
Example 19
Source File: SpoilerManager.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * Create a new SpoilerManager and add Spoiler to disco features.
 *
 * @param connection xmpp connection
 */
private SpoilerManager(XMPPConnection connection) {
    super(connection);
    serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
}
 
Example 20
Source File: PubSubManager.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the supported features of the servers pubsub implementation
 * as a standard {@link DiscoverInfo} instance.
 *
 * @return The supported features
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public DiscoverInfo getSupportedFeatures() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    ServiceDiscoveryManager mgr = ServiceDiscoveryManager.getInstanceFor(connection());
    return mgr.discoverInfo(pubSubService);
}