Search in sources :

Example 11 with ServiceDiscoveryManager

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

the class JabberBrowser method browseItem.

private void browseItem(DiscoverItems.Item discoveredItem) {
    addAddress(discoveredItem.getEntityID());
    browsePanel.removeAll();
    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(con);
    DiscoverItems result;
    try {
        result = discoManager.discoverItems(discoveredItem.getEntityID());
    } catch (XMPPException | SmackException 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();
}
Also used : SmackException(org.jivesoftware.smack.SmackException) ArrayList(java.util.ArrayList) JComponent(javax.swing.JComponent) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) XMPPException(org.jivesoftware.smack.XMPPException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 12 with ServiceDiscoveryManager

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

the class JabberBrowser method browse.

private void browse(String serviceName) {
    browsePanel.removeAll();
    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(con);
    DiscoverItems result;
    try {
        result = discoManager.discoverItems(serviceName);
    } catch (XMPPException | SmackException e) {
        Log.error(e);
        return;
    }
    addAddress(serviceName);
    for (DiscoverItems.Item item : result.getItems()) {
        Entity entity = new Entity(item);
        browsePanel.add(entity);
    }
    browsePanel.invalidate();
    browsePanel.validate();
    browsePanel.repaint();
}
Also used : SmackException(org.jivesoftware.smack.SmackException) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) XMPPException(org.jivesoftware.smack.XMPPException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 13 with ServiceDiscoveryManager

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

the class JinglePlugin method getPhoneActions.

public Collection<Action> getPhoneActions(final String jid) {
    // Do not even disco gateway clients.
    if (TransportUtils.isFromGateway(jid) || jingleManager == null) {
        return Collections.emptyList();
    }
    Boolean supportsJingle = jingleFeature.get(XmppStringUtils.parseBareJid(jid));
    if (supportsJingle == null) {
        // Disco for event.
        // Obtain the ServiceDiscoveryManager associated with my XMPPConnection
        ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());
        String fullJID = PresenceManager.getFullyQualifiedJID(jid);
        // Get the items of a given XMPP entity
        DiscoverInfo discoverInfo = null;
        try {
            discoverInfo = discoManager.discoverInfo(fullJID);
        } catch (XMPPException | SmackException e) {
            Log.debug("Unable to disco " + fullJID);
        }
        if (discoverInfo != null) {
            // Get the discovered items of the queried XMPP entity
            supportsJingle = discoverInfo.containsFeature(JINGLE_NAMESPACE);
            jingleFeature.put(jid, supportsJingle);
        } else {
            jingleFeature.put(jid, false);
            supportsJingle = false;
        }
    }
    if (!supportsJingle) {
        return Collections.emptyList();
    }
    final List<Action> actions = new ArrayList<>();
    Action action = new AbstractAction() {

        private static final long serialVersionUID = 1467355627829748086L;

        public void actionPerformed(ActionEvent e) {
            try {
                placeCall(jid);
            } catch (SmackException e1) {
                Log.warning("Unable to place call to " + jid, e1);
            }
        }
    };
    action.putValue(Action.NAME, "<html><b>" + JingleResources.getString("label.computer.to.computer") + "</b></html>");
    action.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.COMPUTER_IMAGE_16x16));
    actions.add(action);
    return actions;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) ActionEvent(java.awt.event.ActionEvent) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 14 with ServiceDiscoveryManager

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

the class SparkManager method removeFeature.

/**
 * Removes a feature that can be discovered through Disco.
 *
 * @param namespace the namespace to remove.
 */
public static void removeFeature(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.removeFeature(namespace);
}
Also used : ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 15 with ServiceDiscoveryManager

use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager in project Zom-Android by zom.

the class XmppConnection method initServiceDiscovery.

/*
    @Override
    public void handle(Callback[] arg0) throws IOException {

        for (Callback cb : arg0) {
            debug(TAG, cb.toString());
        }

    }*/
/*
    public class MySASLDigestMD5Mechanism extends SASLMechanism
    {

        public MySASLDigestMD5Mechanism(SASLAuthentication saslAuthentication)
        {
            super(saslAuthentication);
        }

        protected void authenticate()
            throws IOException, XMPPException
        {
            String mechanisms[] = {
                getName()
            };
            java.util.Map props = new HashMap();
            sc = Sasl.createSaslClient(mechanisms, null, "xmpp", hostname, props, this);
            super.authenticate();
        }

        public void authenticate(String username, String host, String password)
            throws IOException, XMPPException
        {
            authenticationId = username;
            this.password = password;
            hostname = host;
            String mechanisms[] = {
                getName()
            };
            java.util.Map props = new HashMap();
            sc = Sasl.createSaslClient(mechanisms, null, "xmpp", host, props, this);
            super.authenticate();
        }

        public void authenticate(String username, String host, CallbackHandler cbh)
            throws IOException, XMPPException
        {
            String mechanisms[] = {
                getName()
            };
            java.util.Map props = new HashMap();
            sc = Sasl.createSaslClient(mechanisms, null, "xmpp", host, props, cbh);
            super.authenticate();
        }

        protected String getName()
        {
            return "DIGEST-MD5";
        }

        public void challengeReceived(String challenge)
            throws IOException
        {
            //StringBuilder stanza = new StringBuilder();
            byte response[];
            if(challenge != null)
                response = sc.evaluateChallenge(Base64.decode(challenge));
            else
                //response = sc.evaluateChallenge(null);
                response = sc.evaluateChallenge(new byte[0]);
            //String authenticationText = "";
            Packet responseStanza;
            //if(response != null)
            //{
                //authenticationText = Base64.encodeBytes(response, 8);
                //if(authenticationText.equals(""))
                    //authenticationText = "=";

                if (response == null){
                    responseStanza = new Response();
                } else {
                    responseStanza = new Response(Base64.encodeBytes(response,Base64.DONT_BREAK_LINES));
                }
            //}
            //stanza.append("<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
            //stanza.append(authenticationText);
            //stanza.append("</response>");
            //getSASLAuthentication().send(stanza.toString());
            getSASLAuthentication().send(responseStanza);
        }
    }
     */
private void initServiceDiscovery() {
    debug(TAG, "init service discovery");
    // register connection features
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mConnection);
    if (!sdm.includesFeature(DISCO_FEATURE))
        sdm.addFeature(DISCO_FEATURE);
    if (!sdm.includesFeature(DeliveryReceipt.NAMESPACE))
        sdm.addFeature(DeliveryReceipt.NAMESPACE);
    sdm.addFeature(HttpFileUploadManager.NAMESPACE);
    DeliveryReceiptManager.getInstanceFor(mConnection).autoAddDeliveryReceiptRequests();
    DeliveryReceiptManager.getInstanceFor(mConnection).setAutoReceiptMode(DeliveryReceiptManager.AutoReceiptMode.disabled);
}
Also used : 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