Search in sources :

Example 1 with IoTClaimed

use of org.jivesoftware.smackx.iot.discovery.element.IoTClaimed in project Smack by igniterealtime.

the class IoTDiscoveryIntegrationTest method registerClaimAndUnregisterThing.

@SmackIntegrationTest
public void registerClaimAndUnregisterThing() throws XMPPErrorException, InterruptedException, SmackException {
    final String key = StringUtils.randomString(12);
    final String sn = StringUtils.randomString(12);
    final Thing thing = Thing.builder().setKey(key).setSerialNumber(sn).setManufacturer("Ignite Realtime").setModel("Smack").setVersion("0.1").build();
    registerThing(discoveryManagerOne, thing);
    IoTClaimed iotClaimed = discoveryManagerTwo.claimThing(thing.getMetaTags());
    assertEquals(conOne.getUser().asBareJid(), iotClaimed.getJid());
    discoveryManagerTwo.disownThing(iotClaimed.getJid());
    discoveryManagerOne.unregister();
}
Also used : IoTClaimed(org.jivesoftware.smackx.iot.discovery.element.IoTClaimed) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 2 with IoTClaimed

use of org.jivesoftware.smackx.iot.discovery.element.IoTClaimed in project Smack by igniterealtime.

the class IoTClaimedProvider method parse.

@Override
public IoTClaimed parse(XmlPullParser parser, int initialDepth) throws Exception {
    Jid jid = ParserUtils.getJidAttribute(parser);
    NodeInfo nodeInfo = NodeInfoParser.parse(parser);
    return new IoTClaimed(jid, nodeInfo);
}
Also used : Jid(org.jxmpp.jid.Jid) NodeInfo(org.jivesoftware.smackx.iot.element.NodeInfo) IoTClaimed(org.jivesoftware.smackx.iot.discovery.element.IoTClaimed)

Example 3 with IoTClaimed

use of org.jivesoftware.smackx.iot.discovery.element.IoTClaimed 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.sendIqRequestAndWaitForResponse(iotRegister);
    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 4 with IoTClaimed

use of org.jivesoftware.smackx.iot.discovery.element.IoTClaimed in project Smack by igniterealtime.

the class IoTDiscoveryManager method claimThing.

/**
 * Claim a thing by providing a collection of meta tags. If the claim was successful, then a {@link IoTClaimed}
 * instance will be returned, which contains the XMPP address of the thing. Use {@link IoTClaimed#getJid()} to
 * retrieve this address.
 *
 * @param registry the registry use to claim the thing.
 * @param metaTags a collection of meta tags used to identify the thing.
 * @param publicThing if this is a public thing.
 * @return a {@link IoTClaimed} if successful.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public IoTClaimed claimThing(Jid registry, Collection<Tag> metaTags, boolean publicThing) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    interactWithRegistry(registry);
    IoTMine iotMine = new IoTMine(metaTags, publicThing);
    iotMine.setTo(registry);
    IoTClaimed iotClaimed = connection().sendIqRequestAndWaitForResponse(iotMine);
    // The 'jid' attribute of the <claimed/> response now represents the XMPP address of the thing we just successfully claimed.
    Jid thing = iotClaimed.getJid();
    IoTProvisioningManager.getInstanceFor(connection()).sendFriendshipRequest(thing.asBareJid());
    return iotClaimed;
}
Also used : IoTMine(org.jivesoftware.smackx.iot.discovery.element.IoTMine) Jid(org.jxmpp.jid.Jid) BareJid(org.jxmpp.jid.BareJid) IoTClaimed(org.jivesoftware.smackx.iot.discovery.element.IoTClaimed)

Example 5 with IoTClaimed

use of org.jivesoftware.smackx.iot.discovery.element.IoTClaimed in project Smack by igniterealtime.

the class IoTClaimedProvider method parse.

@Override
public IoTClaimed parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmppStringprepException {
    Jid jid = ParserUtils.getJidAttribute(parser);
    NodeInfo nodeInfo = NodeInfoParser.parse(parser);
    return new IoTClaimed(jid, nodeInfo);
}
Also used : Jid(org.jxmpp.jid.Jid) NodeInfo(org.jivesoftware.smackx.iot.element.NodeInfo) IoTClaimed(org.jivesoftware.smackx.iot.discovery.element.IoTClaimed)

Aggregations

IoTClaimed (org.jivesoftware.smackx.iot.discovery.element.IoTClaimed)5 Jid (org.jxmpp.jid.Jid)3 NodeInfo (org.jivesoftware.smackx.iot.element.NodeInfo)2 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)1 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 IQ (org.jivesoftware.smack.packet.IQ)1 IoTMine (org.jivesoftware.smackx.iot.discovery.element.IoTMine)1 IoTRegister (org.jivesoftware.smackx.iot.discovery.element.IoTRegister)1 BareJid (org.jxmpp.jid.BareJid)1