@Test public void getConfigFormWithInsufficientPriviliges() throws XMPPException, SmackException, IOException { ThreadedDummyConnection con = ThreadedDummyConnection.newInstance(); PubSubManager mgr = new PubSubManager(con); DiscoverInfo info = new DiscoverInfo(); Identity ident = new Identity("pubsub", null, "leaf"); info.addIdentity(ident); con.addIQReply(info); Node node = mgr.getNode("princely_musings"); PubSub errorIq = new PubSub(); XMPPError error = new XMPPError(Condition.forbidden); errorIq.setError(error); con.addIQReply(errorIq); try { node.getNodeConfiguration(); } catch (XMPPErrorException e) { Assert.assertEquals(XMPPError.Type.AUTH, e.getXMPPError().getType()); } }
@Test (expected=SmackException.class) public void getConfigFormWithTimeout() throws XMPPException, SmackException { ThreadedDummyConnection con = new ThreadedDummyConnection(); PubSubManager mgr = new PubSubManager(con); DiscoverInfo info = new DiscoverInfo(); Identity ident = new Identity("pubsub", null, "leaf"); info.addIdentity(ident); con.addIQReply(info); Node node = mgr.getNode("princely_musings"); SmackConfiguration.setDefaultPacketReplyTimeout(100); con.setTimeout(); node.getNodeConfiguration(); }
private void checkFeatures(ServiceDiscoveryManager discoManager, String uri) throws SmackException, XMPPErrorException { // Get the information of a given XMPP entity System.out.println("Discover: " + uri); // This gets the information of the component DiscoverInfo discoInfo = discoManager.discoverInfo(uri); // Get the discovered identities of the remote XMPP entity List<Identity> identities = discoInfo.getIdentities(); // Display the identities of the remote XMPP entity for(Identity identity : identities) { System.out.println(identity.getName()); System.out.println(identity.getType()); System.out.println(identity.getCategory()); } // Check if component supports rest if(discoInfo.containsFeature(XwadlIQ.NAMESPACE)) System.out.println("XWADL is supported"); else throw new SmackException("XWADL is not supported"); if(discoInfo.containsFeature(RestIQ.NAMESPACE)) System.out.println("REST is supported"); else throw new SmackException("REST is not supported"); }
/** * Sets the default identity the client will report. * * @param identity */ public synchronized void setIdentity(Identity identity) { this.identity = Objects.requireNonNull(identity, "Identity can not be null"); // Notify others of a state change of SDM. In order to keep the state consistent, this // method is synchronized renewEntityCapsVersion(); }
/** * Add an further identity to the client. * * @param identity */ public synchronized void addIdentity(DiscoverInfo.Identity identity) { identities.add(identity); // Notify others of a state change of SDM. In order to keep the state consistent, this // method is synchronized renewEntityCapsVersion(); }
/** * Remove an identity from the client. Note that the client needs at least one identity, the default identity, which * can not be removed. * * @param identity * @return true, if successful. Otherwise the default identity was given. */ public synchronized boolean removeIdentity(DiscoverInfo.Identity identity) { if (identity.equals(this.identity)) return false; identities.remove(identity); // Notify others of a state change of SDM. In order to keep the state consistent, this // method is synchronized renewEntityCapsVersion(); return true; }
/** * Returns all identities of this client as unmodifiable Collection * * @return all identies as set */ public Set<DiscoverInfo.Identity> getIdentities() { Set<Identity> res = new HashSet<Identity>(identities); // Add the default identity that must exist res.add(defaultIdentity); return Collections.unmodifiableSet(res); }
/** * Updates the local user Entity Caps information with the data provided * * If we are connected and there was already a presence send, another * presence is send to inform others about your new Entity Caps node string. * */ public void updateLocalEntityCaps() { XMPPConnection connection = connection(); DiscoverInfo discoverInfo = new DiscoverInfo(); discoverInfo.setType(IQ.Type.result); sdm.addDiscoverInfoTo(discoverInfo); // getLocalNodeVer() will return a result only after currentCapsVersion is set. Therefore // set it first and then call getLocalNodeVer() currentCapsVersion = generateVerificationString(discoverInfo); final String localNodeVer = getLocalNodeVer(); discoverInfo.setNode(localNodeVer); addDiscoverInfoByNode(localNodeVer, discoverInfo); if (lastLocalCapsVersions.size() > 10) { CapsVersionAndHash oldCapsVersion = lastLocalCapsVersions.poll(); sdm.removeNodeInformationProvider(entityNode + '#' + oldCapsVersion.version); } lastLocalCapsVersions.add(currentCapsVersion); if (connection != null) JID_TO_NODEVER_CACHE.put(connection.getUser(), new NodeVerHash(entityNode, currentCapsVersion)); final List<Identity> identities = new LinkedList<Identity>(ServiceDiscoveryManager.getInstanceFor(connection).getIdentities()); sdm.setNodeInformationProvider(localNodeVer, new AbstractNodeInformationProvider() { List<String> features = sdm.getFeatures(); List<ExtensionElement> packetExtensions = sdm.getExtendedInfoAsList(); @Override public List<String> getNodeFeatures() { return features; } @Override public List<Identity> getNodeIdentities() { return identities; } @Override public List<ExtensionElement> getNodePacketExtensions() { return packetExtensions; } }); // Re-send the last sent presence, and let the stanza interceptor // add a <c/> node to it. // See http://xmpp.org/extensions/xep-0115.html#advertise // We only send a presence packet if there was already one send // to respect ConnectionConfiguration.isSendPresence() if (connection != null && connection.isAuthenticated() && presenceSend != null) { try { connection.sendStanza(presenceSend.cloneWithNewId()); } catch (NotConnectedException e) { LOGGER.log(Level.WARNING, "Could could not update presence with caps info", e); } } }
/** * Set the default identity all new connections will have. If unchanged the default identity is an * identity where category is set to 'client', type is set to 'pc' and name is set to 'Smack'. * * @param identity */ public static void setDefaultIdentity(DiscoverInfo.Identity identity) { defaultIdentity = identity; }
/** * Return the default identity of the client. * * @return the default identity. */ public Identity getIdentity() { return identity; }