Search in sources :

Example 46 with XMPPConnection

use of org.jivesoftware.smack.XMPPConnection in project Smack by igniterealtime.

the class RosterExchangeManager method send.

/**
     * Sends a roster to userID. All the entries of the roster will be sent to the
     * target user.
     * 
     * @param roster the roster to send
     * @param targetUserID the user that will receive the roster entries
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public void send(Roster roster, Jid targetUserID) throws NotConnectedException, InterruptedException {
    // Create a new message to send the roster
    Message msg = new Message(targetUserID);
    // Create a RosterExchange Package and add it to the message
    RosterExchange rosterExchange = new RosterExchange(roster);
    msg.addExtension(rosterExchange);
    XMPPConnection connection = weakRefConnection.get();
    // Send the message that contains the roster
    connection.sendStanza(msg);
}
Also used : RosterExchange(org.jivesoftware.smackx.xroster.packet.RosterExchange) Message(org.jivesoftware.smack.packet.Message) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

Example 47 with XMPPConnection

use of org.jivesoftware.smack.XMPPConnection in project Smack by igniterealtime.

the class RosterExchangeManager method send.

/**
     * Sends a roster group to userID. All the entries of the group will be sent to the 
     * target user.
     * 
     * @param rosterGroup the roster group to send
     * @param targetUserID the user that will receive the roster entries
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public void send(RosterGroup rosterGroup, Jid targetUserID) throws NotConnectedException, InterruptedException {
    // Create a new message to send the roster
    Message msg = new Message(targetUserID);
    // Create a RosterExchange Package and add it to the message
    RosterExchange rosterExchange = new RosterExchange();
    for (RosterEntry entry : rosterGroup.getEntries()) {
        rosterExchange.addRosterEntry(entry);
    }
    msg.addExtension(rosterExchange);
    XMPPConnection connection = weakRefConnection.get();
    // Send the message that contains the roster
    connection.sendStanza(msg);
}
Also used : RosterExchange(org.jivesoftware.smackx.xroster.packet.RosterExchange) Message(org.jivesoftware.smack.packet.Message) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

Example 48 with XMPPConnection

use of org.jivesoftware.smack.XMPPConnection in project Smack by igniterealtime.

the class IoTDiscoveryManager method registerThing.

public ThingState registerThing(Jid registry, Thing thing) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException, IoTClaimedException {
    final XMPPConnection connection = connection();
    IoTRegister iotRegister = new IoTRegister(thing.getMetaTags(), thing.getNodeInfo(), thing.isSelfOwened());
    iotRegister.setTo(registry);
    IQ result = connection.createStanzaCollectorAndSend(iotRegister).nextResultOrThrow();
    if (result instanceof IoTClaimed) {
        IoTClaimed iotClaimedResult = (IoTClaimed) result;
        throw new IoTClaimedException(iotClaimedResult);
    }
    ThingState state = getStateFor(thing.getNodeInfo());
    state.setRegistry(registry.asBareJid());
    interactWithRegistry(registry);
    IoTDataManager.getInstanceFor(connection).installThing(thing);
    IoTControlManager.getInstanceFor(connection).installThing(thing);
    return state;
}
Also used : IQ(org.jivesoftware.smack.packet.IQ) IoTClaimed(org.jivesoftware.smackx.iot.discovery.element.IoTClaimed) XMPPConnection(org.jivesoftware.smack.XMPPConnection) IoTRegister(org.jivesoftware.smackx.iot.discovery.element.IoTRegister)

Example 49 with XMPPConnection

use of org.jivesoftware.smack.XMPPConnection in project Smack by igniterealtime.

the class IoTDiscoveryManager method findRegistry.

/**
     * Try to find an XMPP IoT registry.
     *
     * @return the JID of a Thing Registry if one could be found, <code>null</code> otherwise.
     * @throws InterruptedException
     * @throws NotConnectedException
     * @throws XMPPErrorException
     * @throws NoResponseException
     * @see <a href="http://xmpp.org/extensions/xep-0347.html#findingregistry">XEP-0347 § 3.5 Finding Thing Registry</a>
     */
public Jid findRegistry() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    if (preconfiguredRegistry != null) {
        return preconfiguredRegistry;
    }
    final XMPPConnection connection = connection();
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
    List<DiscoverInfo> discoverInfos = sdm.findServicesDiscoverInfo(Constants.IOT_DISCOVERY_NAMESPACE, true, true);
    if (!discoverInfos.isEmpty()) {
        return discoverInfos.get(0).getFrom();
    }
    return null;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) XMPPConnection(org.jivesoftware.smack.XMPPConnection) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 50 with XMPPConnection

use of org.jivesoftware.smack.XMPPConnection in project Smack by igniterealtime.

the class IoTProvisioningManager method findProvisioningServerComponent.

/**
     * Try to find a provisioning server component.
     * 
     * @return the XMPP address of the provisioning server component if one was found.
     * @throws NoResponseException
     * @throws XMPPErrorException
     * @throws NotConnectedException
     * @throws InterruptedException
     * @see <a href="http://xmpp.org/extensions/xep-0324.html#servercomponent">XEP-0324 § 3.1.2 Provisioning Server as a server component</a>
     */
public DomainBareJid findProvisioningServerComponent() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    final XMPPConnection connection = connection();
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
    List<DiscoverInfo> discoverInfos = sdm.findServicesDiscoverInfo(Constants.IOT_PROVISIONING_NAMESPACE, true, true);
    if (discoverInfos.isEmpty()) {
        return null;
    }
    Jid jid = discoverInfos.get(0).getFrom();
    assert (jid.isDomainBareJid());
    return jid.asDomainBareJid();
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) DomainBareJid(org.jxmpp.jid.DomainBareJid) Jid(org.jxmpp.jid.Jid) BareJid(org.jxmpp.jid.BareJid) XMPPConnection(org.jivesoftware.smack.XMPPConnection) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Aggregations

XMPPConnection (org.jivesoftware.smack.XMPPConnection)64 XMPPException (org.jivesoftware.smack.XMPPException)14 Message (org.jivesoftware.smack.packet.Message)9 SmackException (org.jivesoftware.smack.SmackException)7 IQ (org.jivesoftware.smack.packet.IQ)7 InputStream (java.io.InputStream)6 OutputStream (java.io.OutputStream)6 ArrayList (java.util.ArrayList)6 SynchronousQueue (java.util.concurrent.SynchronousQueue)6 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)6 ServiceDiscoveryManager (org.jivesoftware.smackx.disco.ServiceDiscoveryManager)6 TimeoutException (java.util.concurrent.TimeoutException)5 StanzaCollector (org.jivesoftware.smack.StanzaCollector)5 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)5 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)5 ConnectionThread (com.xabber.android.data.connection.ConnectionThread)4 ConnectionConfiguration (org.jivesoftware.smack.ConnectionConfiguration)4 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)4 Packet (org.jivesoftware.smack.packet.Packet)4 Jid (org.jxmpp.jid.Jid)4