Package org.jivesoftware.smackx

Examples of org.jivesoftware.smackx.ServiceDiscoveryManager


            if (!BuddyList.getInstance().checkConnection()) {
                BuddyList.getInstance().connectionError();
                return;
            }

            ServiceDiscoveryManager manager = new ServiceDiscoveryManager(
                    BuddyList.getInstance().getConnection());

            // get the discover items for the server
            try {
                DiscoverItems items = manager.discoverItems(serverField.getText());
                Iterator i = items.getItems();

                String top[] = new String[]{serverField.getText(),
                        serverField.getText(), "", "", ""};
                discoItems.add(top);
                tableModel.addItem(top);

                while (i.hasNext()) {
                    DiscoverItems.Item item = (DiscoverItems.Item) i.next();
                    if (stopped) {
                        return;
                    }

                    final String[] entry = new String[]{item.getName(),
                            item.getEntityID(), "", ""};
                    discoItems.add(entry);

                    SwingUtilities.invokeLater(
                        new Runnable() {
                            public void run() {
                                tableModel.addItem(entry);
                            }
                        });
                }

                for (int icount = 0; icount < discoItems.size(); icount++) {
                    String[] entry = (String[]) discoItems.get(icount);
                    final String id = entry[1];

                    status.setText(resources.getString("status") + ": "
                             + resources.getString("gettingFeatures") + " ("
                             + id + ") ...");

                    // get the discover info about each item
                    DiscoverInfo info = null;

                    try {
                        info = manager.discoverInfo(id);
                    } catch (XMPPException e) {
                    }

                    // if the service discovery has been aborted, bail out
                    if (stopped) {
View Full Code Here


     * @param jid the full JID to retrieve the commands for.
     * @return the discovered items.
     * @throws XMPPException if the operation failed for some reason.
     */
    public DiscoverItems discoverCommands(String jid) throws XMPPException {
        ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager
                .getInstanceFor(connection);
        return serviceDiscoveryManager.discoverItems(jid, discoNode);
    }
View Full Code Here

     *
     * @param jid the full JID to publish the commands to.
     * @throws XMPPException if the operation failed for some reason.
     */
    public void publishCommands(String jid) throws XMPPException {
        ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager
                .getInstanceFor(connection);

        // Collects the commands to publish as items
        DiscoverItems discoverItems = new DiscoverItems();
        Collection<AdHocCommandInfo> xCommandsList = getRegisteredCommands();

        for (AdHocCommandInfo info : xCommandsList) {
            DiscoverItems.Item item = new DiscoverItems.Item(info.getOwnerJID());
            item.setName(info.getName());
            item.setNode(info.getNode());
            discoverItems.addItem(item);
        }

        serviceDiscoveryManager.publishItems(jid, discoNode, discoverItems);
    }
View Full Code Here

     * @return a Collection of search services found on the server.
     * @throws XMPPException thrown if a server error has occurred.
     */
    public Collection getSearchServices() throws XMPPException {
        final List<String> searchServices = new ArrayList<String>();
        ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(con);
        DiscoverItems items = discoManager.discoverItems(con.getServiceName());
        Iterator<DiscoverItems.Item> iter = items.getItems();
        while (iter.hasNext()) {
            DiscoverItems.Item item = iter.next();
            try {
                DiscoverInfo info;
                try {
                    info = discoManager.discoverInfo(item.getEntityID());
                }
                catch (XMPPException e) {
                    // Ignore Case
                    continue;
                }
View Full Code Here

        // mock nextResult method
        when(collector.nextResult(anyInt())).thenAnswer(answer);
        when(collector.nextResult()).thenAnswer(answer);

        // initialize service discovery manager for this connection
        new ServiceDiscoveryManager(connection);

        return connection;
    }
View Full Code Here

        // mock connection
        connection = mock(Connection.class);

        // create service discovery manager for mocked connection
        new ServiceDiscoveryManager(connection);

        // initialize Socks5ByteStreamManager to get the InitiationListener
        byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);

        // get the InitiationListener from Socks5ByteStreamManager
View Full Code Here

        if (managers.size() == 0) {
            Socks5Proxy.getSocks5Proxy().stop();
        }

        // remove feature from service discovery
        ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(this.connection);

        // check if service discovery is not already disposed by connection shutdown
        if (serviceDiscoveryManager != null) {
            serviceDiscoveryManager.removeFeature(NAMESPACE);
        }

    }
View Full Code Here

     * @return <code>true</code> if the given target JID supports feature SOCKS5 Bytestream
     *         otherwise <code>false</code>
     * @throws XMPPException if there was an error querying target for supported features
     */
    private boolean supportsSocks5(String targetJID) throws XMPPException {
        ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(this.connection);
        DiscoverInfo discoverInfo = serviceDiscoveryManager.discoverInfo(targetJID);
        return discoverInfo.containsFeature(NAMESPACE);
    }
View Full Code Here

     *
     * @return list of JIDs of SOCKS5 proxies
     * @throws XMPPException if there was an error querying the XMPP server for SOCKS5 proxies
     */
    private List<String> determineProxies() throws XMPPException {
        ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(this.connection);

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

        // get all items form XMPP server
        DiscoverItems discoverItems = serviceDiscoveryManager.discoverItems(this.connection.getServiceName());
        Iterator<Item> itemIterator = discoverItems.getItems();

        // query all items if they are SOCKS5 proxies
        while (itemIterator.hasNext()) {
            Item item = itemIterator.next();

            // skip blacklisted servers
            if (this.proxyBlacklist.contains(item.getEntityID())) {
                continue;
            }

            try {
                DiscoverInfo proxyInfo;
                proxyInfo = serviceDiscoveryManager.discoverInfo(item.getEntityID());
                Iterator<Identity> identities = proxyInfo.getIdentities();

                // item must have category "proxy" and type "bytestream"
                while (identities.hasNext()) {
                    Identity identity = identities.next();
View Full Code Here

    /**
     * Adds the SOCKS5 Bytestream feature to the service discovery.
     */
    private void enableService() {
        ServiceDiscoveryManager manager = ServiceDiscoveryManager.getInstanceFor(this.connection);
        if (!manager.includesFeature(NAMESPACE)) {
            manager.addFeature(NAMESPACE);
        }
    }
View Full Code Here

TOP

Related Classes of org.jivesoftware.smackx.ServiceDiscoveryManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.