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();
}
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);
}
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;
}
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;
}
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);
}
Aggregations