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

The following examples show how to use org.jivesoftware.smackx.disco.ServiceDiscoveryManager#discoverItems() . 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: ConferenceServiceBrowser.java    From Spark with Apache License 2.0 6 votes vote down vote up
public Collection<String> getConferenceServices(String serverString) throws Exception {
    Jid server = JidCreate.from(serverString);
    List<String> answer = new ArrayList<>();
    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());
    DiscoverItems items = discoManager.discoverItems(server);
    for (DiscoverItems.Item item : items.getItems() ) {
        if (item.getEntityID().toString().startsWith("conference") || item.getEntityID().toString().startsWith("private")) {
            answer.add(item.getEntityID().toString());
        }
        else {
            try {
                DiscoverInfo info = discoManager.discoverInfo(item.getEntityID());
                if (info.containsFeature("http://jabber.org/protocol/muc")) {
                    answer.add(item.getEntityID().toString());
                }
            }
            catch (XMPPException | SmackException e) {
                // Nothing to do
            }
        }
    }
    return answer;
}
 
Example 2
Source File: BookmarksUI.java    From Spark with Apache License 2.0 6 votes vote down vote up
private Collection<DomainBareJid> getConferenceServices(DomainBareJid server) throws Exception {
    List<DomainBareJid> answer = new ArrayList<>();
    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());
    DiscoverItems items = discoManager.discoverItems(server);
    for (DiscoverItems.Item item : items.getItems()) {
        DomainBareJid entityID = item.getEntityID().asDomainBareJid();
        // TODO: We should not simply assumet that this is MUC service just because it starts with a given prefix.
        if (entityID.toString().startsWith("conference") || entityID.toString().startsWith("private")) {
            answer.add(entityID);
        }
        else {
            try {
                DiscoverInfo info = discoManager.discoverInfo(item.getEntityID());
                if (info.containsFeature("http://jabber.org/protocol/muc")) {
                    answer.add(entityID);
                }
            }
            catch (XMPPException | SmackException e) {
                Log.error("Problem when loading conference service.", e);
            }
        }
    }
    return answer;
}
 
Example 3
Source File: SipAccountPacket.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
 * Does a service discovery on the server to see if a SIPpark Manager is
 * enabled.
 *
 * @param con the XMPPConnection to use.
 * @return true if SIPpark Manager is available.
 */
public static boolean isSoftPhonePluginInstalled(XMPPConnection con) {
    if (!con.isConnected()) {
        return false;
    }

    ServiceDiscoveryManager disco = ServiceDiscoveryManager
            .getInstanceFor(con);
    try {
        DiscoverItems items = disco.discoverItems(con.getXMPPServiceDomain());
        for ( DiscoverItems.Item item : items.getItems() ) {
            if ("SIP Controller".equals(item.getName())) {
                Log.debug("SIP Controller Found");
                return true;
            }
        }
    }
    catch (XMPPException | SmackException e) {
        Log.error("isSparkPluginInstalled", e);
    }

    return false;

}
 
Example 4
Source File: ServiceDiscovery.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
    String entID = sampler.getPropertyAsString(ENTITY_ID);
    res.setSamplerData("Entity ID: " + entID);
    ServiceDiscoveryManager discoMgr = ServiceDiscoveryManager.getInstanceFor(sampler.getXMPPConnection());
    IQ info;
    if (Type.valueOf(sampler.getPropertyAsString(TYPE)) == Type.info) {
        info = discoMgr.discoverInfo(entID);
    } else {
        info = discoMgr.discoverItems(entID);
    }
    res.setResponseData(info.toXML().toString().getBytes());
    return res;
}
 
Example 5
Source File: FeatureDiscovery.java    From desktopclient-java with GNU General Public License v3.0 5 votes vote down vote up
private EnumMap<Feature, JID> discover(JID entity, boolean withItems) {
    // NOTE: smack automatically creates instances of SDM and CapsM and connects them
    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(mConn);

    // 1. get features from server
    EnumMap<Feature, JID> features = discover(discoManager, entity);
    if (features == null)
        return new EnumMap<>(FeatureDiscovery.Feature.class);

    if (!withItems)
        return features;

    // 2. get server items
    DiscoverItems items;
    try {
        items = discoManager.discoverItems(entity.toBareSmack());
    } catch (SmackException.NoResponseException |
            XMPPException.XMPPErrorException |
            SmackException.NotConnectedException |
            InterruptedException ex) {
        LOGGER.log(Level.WARNING, "can't get service discovery items", ex);
        return features;
    }

    // 3. get features from server items
    for (DiscoverItems.Item item: items.getItems()) {
        EnumMap<Feature, JID> itemFeatures = discover(discoManager, JID.fromSmack(item.getEntityID()));
        if (itemFeatures != null)
            features.putAll(itemFeatures);
    }

    LOGGER.info("supported server features: "+features);
    return features;
}
 
Example 6
Source File: Socks5BytestreamManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a list of JIDs of SOCKS5 proxies by querying the XMPP server. The SOCKS5 proxies are
 * in the same order as returned by the XMPP server.
 *
 * @return list of JIDs of SOCKS5 proxies
 * @throws XMPPErrorException if there was an error querying the XMPP server for SOCKS5 proxies
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public List<Jid> determineProxies() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    XMPPConnection connection = connection();
    ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);

    List<Jid> proxies = new ArrayList<>();

    // get all items from XMPP server
    DiscoverItems discoverItems = serviceDiscoveryManager.discoverItems(connection.getXMPPServiceDomain());

    // query all items if they are SOCKS5 proxies
    for (Item item : discoverItems.getItems()) {
        // skip blacklisted servers
        if (this.proxyBlacklist.contains(item.getEntityID())) {
            continue;
        }

        DiscoverInfo proxyInfo;
        try {
            proxyInfo = serviceDiscoveryManager.discoverInfo(item.getEntityID());
        }
        catch (NoResponseException | XMPPErrorException e) {
            // blacklist errornous server
            proxyBlacklist.add(item.getEntityID());
            continue;
        }

        if (proxyInfo.hasIdentity("proxy", "bytestreams")) {
            proxies.add(item.getEntityID());
        } else {
            /*
             * server is not a SOCKS5 proxy, blacklist server to skip next time a Socks5
             * bytestream should be established
             */
            this.proxyBlacklist.add(item.getEntityID());
        }
    }

    return proxies;
}
 
Example 7
Source File: STUN.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Check if the server support STUN Service.
 *
 * @param connection the connection
 * @return true if the server support STUN
 * @throws SmackException if Smack detected an exceptional situation.
 * @throws XMPPException if an XMPP protocol error was received.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public static boolean serviceAvailable(XMPPConnection connection) throws XMPPException, SmackException, InterruptedException {

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

    LOGGER.fine("Service listing");

    ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(connection);
    DiscoverItems items = disco.discoverItems(connection.getXMPPServiceDomain());

    for (DiscoverItems.Item item : items.getItems()) {
        DiscoverInfo info = disco.discoverInfo(item.getEntityID());

        for (DiscoverInfo.Identity identity : info.getIdentities()) {
            if (identity.getCategory().equals("proxy") && identity.getType().equals("stun"))
                if (info.containsFeature(NAMESPACE))
                    return true;
        }

        LOGGER.fine(item.getName() + "-" + info.getType());

    }

    return false;
}
 
Example 8
Source File: RoomBrowser.java    From Spark with Apache License 2.0 5 votes vote down vote up
public void displayRoomInformation(final EntityBareJid roomJID) {
     SwingWorker worker = new SwingWorker() {
         RoomInfo roomInfo = null;
         DiscoverItems items = null;

         @Override
public Object construct() {
             try {
                 roomInfo = MultiUserChatManager.getInstanceFor( SparkManager.getConnection() ).getRoomInfo( roomJID );


                 ServiceDiscoveryManager manager = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());
                 items = manager.discoverItems(roomJID);
             }
             catch (XMPPException | SmackException | InterruptedException e) {
                 Log.error(e);
             }
             return "ok";
         }

         @Override
public void finished() {
             setupRoomInformationUI(roomJID, roomInfo, items);
         }
     };

     worker.start();
 }
 
Example 9
Source File: JabberBrowser.java    From Spark with Apache License 2.0 5 votes vote down vote up
private void browseItem(DiscoverItems.Item discoveredItem) {
    addAddress(discoveredItem.getEntityID().toString());
    browsePanel.removeAll();
    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(con);
    DiscoverItems result;
    try {
        result = discoManager.discoverItems(discoveredItem.getEntityID());
    }
    catch (XMPPException | SmackException | InterruptedException e) {
        browsePanel.invalidate();
        browsePanel.validate();
        browsePanel.repaint();
        return;
    }

    List<Entity> list = new ArrayList<>();
    for (DiscoverItems.Item item : result.getItems() ) {
        Entity entity = new Entity(item);
        browsePanel.add(entity);
        list.add(entity);
    }

    GraphicUtils.makeSameSize((JComponent[])list.toArray(new JComponent[list.size()]));

    browsePanel.invalidate();
    browsePanel.validate();
    browsePanel.repaint();
}