org.jivesoftware.smackx.disco.ServiceDiscoveryManager Java Examples
The following examples show how to use
org.jivesoftware.smackx.disco.ServiceDiscoveryManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SipAccountPacket.java From Spark with Apache License 2.0 | 6 votes |
/** * Does a service discovery on the server to see if a SIPpark Manager is * enabled. * * @param con the XMPPConnection to use. * @return true if SIPpark Manager is available. */ public static boolean isSoftPhonePluginInstalled(XMPPConnection con) { if (!con.isConnected()) { return false; } ServiceDiscoveryManager disco = ServiceDiscoveryManager .getInstanceFor(con); try { DiscoverItems items = disco.discoverItems(con.getXMPPServiceDomain()); for ( DiscoverItems.Item item : items.getItems() ) { if ("SIP Controller".equals(item.getName())) { Log.debug("SIP Controller Found"); return true; } } } catch (XMPPException | SmackException e) { Log.error("isSparkPluginInstalled", e); } return false; }
Example #2
Source File: FileTransferNegotiator.java From Smack with Apache License 2.0 | 6 votes |
/** * Checks to see if all file transfer related services are enabled on the * connection. * * @param connection The connection to check * @return True if all related services are enabled, false if they are not. */ public static boolean isServiceEnabled(final XMPPConnection connection) { ServiceDiscoveryManager manager = ServiceDiscoveryManager .getInstanceFor(connection); List<String> namespaces = new ArrayList<>(); namespaces.addAll(Arrays.asList(NAMESPACE)); namespaces.add(DataPacketExtension.NAMESPACE); if (!IBB_ONLY) { namespaces.add(Bytestream.NAMESPACE); } for (String namespace : namespaces) { if (!manager.includesFeature(namespace)) { return false; } } return true; }
Example #3
Source File: InitiationListenerTest.java From Smack with Apache License 2.0 | 6 votes |
/** * Initialize fields used in the tests. */ @BeforeEach public void setup() { // mock connection connection = mock(XMPPConnection.class); // create service discovery manager for mocked connection ServiceDiscoveryManager.getInstanceFor(connection); // initialize Socks5ByteStreamManager to get the InitiationListener byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection); // get the InitiationListener from Socks5ByteStreamManager initiationListener = Whitebox.getInternalState(byteStreamManager, "initiationListener", InitiationListener.class); // create a SOCKS5 Bytestream initiation packet initBytestream = Socks5PacketUtils.createBytestreamInitiation(initiatorJID, targetJID, sessionID); initBytestream.addStreamHost(proxyJID, proxyAddress, 7777); }
Example #4
Source File: Enterprise.java From Spark with Apache License 2.0 | 6 votes |
private void populateFeatureSet() { final ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection()); final DiscoverItems items = SparkManager.getSessionManager().getDiscoveredItems(); for (DiscoverItems.Item item : items.getItems() ) { String entity = item.getEntityID().toString(); if (entity != null) { if (entity.startsWith("manager.")) { sparkManagerInstalled = true; // Populate with feature sets. try { featureInfo = disco.discoverInfo(item.getEntityID()); } catch (XMPPException | SmackException | InterruptedException e) { Log.error("Error while retrieving feature list for SparkManager.", e); } } } } }
Example #5
Source File: AccountManager.java From Smack with Apache License 2.0 | 6 votes |
public boolean isSupported() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { XMPPConnection connection = connection(); ExtensionElement extensionElement = connection.getFeature(Registration.Feature.ELEMENT, Registration.Feature.NAMESPACE); if (extensionElement != null) { return true; } // Fallback to disco#info only if this connection is authenticated, as otherwise we won't have an full JID and // won't be able to do IQs. if (connection.isAuthenticated()) { return ServiceDiscoveryManager.getInstanceFor(connection).serverSupportsFeature(Registration.NAMESPACE); } return false; }
Example #6
Source File: ConferenceUtils.java From Spark with Apache License 2.0 | 6 votes |
/** * Retrieve the date (in yyyyMMdd) format of the time the room was created. * * @param roomJID the jid of the room. * @return the formatted date. * @throws Exception throws an exception if we are unable to retrieve the date. */ public static String getCreationDate(EntityBareJid roomJID) throws Exception { ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection()); final DateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss"); DiscoverInfo infoResult = discoManager.discoverInfo(roomJID); DataForm dataForm = infoResult.getExtension("x", "jabber:x:data"); if (dataForm == null) { return "Not available"; } String creationDate = ""; for ( final FormField field : dataForm.getFields() ) { String label = field.getLabel(); if (label != null && "Creation date".equalsIgnoreCase(label)) { for ( CharSequence value : field.getValues() ) { creationDate = value.toString(); Date date = dateFormatter.parse(creationDate); creationDate = DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.MEDIUM).format(date); } } } return creationDate; }
Example #7
Source File: Socks5ByteStreamManagerTest.java From Smack with Apache License 2.0 | 6 votes |
/** * Test that {@link Socks5BytestreamManager#getBytestreamManager(XMPPConnection)} returns one * bytestream manager for every connection. */ @Test public void shouldHaveOneManagerForEveryConnection() { // mock two connections XMPPConnection connection1 = mock(XMPPConnection.class); XMPPConnection connection2 = mock(XMPPConnection.class); /* * create service discovery managers for the connections because the * ConnectionCreationListener is not called when creating mocked connections */ ServiceDiscoveryManager.getInstanceFor(connection1); ServiceDiscoveryManager.getInstanceFor(connection2); // get bytestream manager for the first connection twice Socks5BytestreamManager conn1ByteStreamManager1 = Socks5BytestreamManager.getBytestreamManager(connection1); Socks5BytestreamManager conn1ByteStreamManager2 = Socks5BytestreamManager.getBytestreamManager(connection1); // get bytestream manager for second connection Socks5BytestreamManager conn2ByteStreamManager1 = Socks5BytestreamManager.getBytestreamManager(connection2); // assertions assertEquals(conn1ByteStreamManager1, conn1ByteStreamManager2); assertNotSame(conn1ByteStreamManager1, conn2ByteStreamManager1); }
Example #8
Source File: HttpFileUploadManager.java From Smack with Apache License 2.0 | 6 votes |
/** * Discover upload service. * * Called automatically when connection is authenticated. * * Note that this is a synchronous call -- Smack must wait for the server response. * * @return true if upload service was discovered * @throws XMPPException.XMPPErrorException if there was an XMPP error returned. * @throws SmackException.NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. * @throws SmackException.NoResponseException if there was no response from the remote entity. */ public boolean discoverUploadService() throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException { ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection()); List<DiscoverInfo> servicesDiscoverInfo = sdm .findServicesDiscoverInfo(NAMESPACE, true, true); if (servicesDiscoverInfo.isEmpty()) { servicesDiscoverInfo = sdm.findServicesDiscoverInfo(NAMESPACE_0_2, true, true); if (servicesDiscoverInfo.isEmpty()) { return false; } } DiscoverInfo discoverInfo = servicesDiscoverInfo.get(0); defaultUploadService = uploadServiceFrom(discoverInfo); return true; }
Example #9
Source File: IoTDiscoveryManager.java From Smack with Apache License 2.0 | 6 votes |
/** * 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 if the calling thread was interrupted. * @throws NotConnectedException if the XMPP connection is not connected. * @throws XMPPErrorException if there was an XMPP error returned. * @throws NoResponseException if there was no response from the remote entity. * @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; }
Example #10
Source File: PrivacyManager.java From Spark with Apache License 2.0 | 6 votes |
private boolean checkIfPrivacyIsSupported(XMPPConnection conn) { ServiceDiscoveryManager servDisc = ServiceDiscoveryManager.getInstanceFor(conn); DiscoverInfo info = null; try { info = servDisc.discoverInfo(conn.getXMPPServiceDomain()); } catch (XMPPException | SmackException | InterruptedException e) { // We could not query the server } if (info != null) { for ( final Feature feature : info.getFeatures() ) { if (feature.getVar().contains("jabber:iq:privacy")) { return true; } } } return false; }
Example #11
Source File: ConferenceServiceBrowser.java From Spark with Apache License 2.0 | 6 votes |
public Collection<String> getConferenceServices(String serverString) throws Exception { Jid server = JidCreate.from(serverString); List<String> answer = new ArrayList<>(); ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection()); DiscoverItems items = discoManager.discoverItems(server); for (DiscoverItems.Item item : items.getItems() ) { if (item.getEntityID().toString().startsWith("conference") || item.getEntityID().toString().startsWith("private")) { answer.add(item.getEntityID().toString()); } else { try { DiscoverInfo info = discoManager.discoverInfo(item.getEntityID()); if (info.containsFeature("http://jabber.org/protocol/muc")) { answer.add(item.getEntityID().toString()); } } catch (XMPPException | SmackException e) { // Nothing to do } } } return answer; }
Example #12
Source File: MultiUserChat.java From Smack with Apache License 2.0 | 6 votes |
/** * Returns the reserved room nickname for the user in the room. A user may have a reserved * nickname, for example through explicit room registration or database integration. In such * cases it may be desirable for the user to discover the reserved nickname before attempting * to enter the room. * * @return the reserved room nickname or <code>null</code> if none. * @throws SmackException if there was no response from the server. * @throws InterruptedException if the calling thread was interrupted. */ public String getReservedNickname() throws SmackException, InterruptedException { try { DiscoverInfo result = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo( room, "x-roomuser-item"); // Look for an Identity that holds the reserved nickname and return its name for (DiscoverInfo.Identity identity : result.getIdentities()) { return identity.getName(); } } catch (XMPPException e) { LOGGER.log(Level.SEVERE, "Error retrieving room nickname", e); } // If no Identity was found then the user does not have a reserved room nickname return null; }
Example #13
Source File: ServiceDiscovery.java From jmeter-bzm-plugins with Apache License 2.0 | 5 votes |
@Override public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception { String entID = sampler.getPropertyAsString(ENTITY_ID); res.setSamplerData("Entity ID: " + entID); ServiceDiscoveryManager discoMgr = ServiceDiscoveryManager.getInstanceFor(sampler.getXMPPConnection()); IQ info; if (Type.valueOf(sampler.getPropertyAsString(TYPE)) == Type.info) { info = discoMgr.discoverInfo(entID); } else { info = discoMgr.discoverItems(entID); } res.setResponseData(info.toXML().toString().getBytes()); return res; }
Example #14
Source File: AMPManager.java From Smack with Apache License 2.0 | 5 votes |
/** * Enables or disables the AMP support on a given connection.<p> * * Before starting to send AMP messages to a user, check that the user can handle XHTML * messages. Enable the AMP support to indicate that this client handles XHTML messages. * * @param connection the connection where the service will be enabled or disabled * @param enabled indicates if the service will be enabled or disabled */ public static synchronized void setServiceEnabled(XMPPConnection connection, boolean enabled) { if (isServiceEnabled(connection) == enabled) return; if (enabled) { ServiceDiscoveryManager.getInstanceFor(connection).addFeature(AMPExtension.NAMESPACE); } else { ServiceDiscoveryManager.getInstanceFor(connection).removeFeature(AMPExtension.NAMESPACE); } }
Example #15
Source File: MultiUserChatLightManager.java From Smack with Apache License 2.0 | 5 votes |
/** * Returns a List of the rooms the user occupies. * * @param mucLightService TODO javadoc me please * @return a List of the rooms the user occupies. * @throws XMPPErrorException if there was an XMPP error returned. * @throws NoResponseException if there was no response from the remote entity. * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. */ public List<Jid> getOccupiedRooms(DomainBareJid mucLightService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { DiscoverItems result = ServiceDiscoveryManager.getInstanceFor(connection()).discoverItems(mucLightService); List<DiscoverItems.Item> items = result.getItems(); List<Jid> answer = new ArrayList<>(items.size()); for (DiscoverItems.Item item : items) { Jid mucLight = item.getEntityID(); answer.add(mucLight); } return answer; }
Example #16
Source File: PepManager.java From Smack with Apache License 2.0 | 5 votes |
public boolean isSupported() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { XMPPConnection connection = connection(); ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection); BareJid localBareJid = connection.getUser().asBareJid(); return serviceDiscoveryManager.supportsFeatures(localBareJid, REQUIRED_FEATURES); }
Example #17
Source File: STUN.java From Smack with Apache License 2.0 | 5 votes |
/** * Check if the server support STUN Service. * * @param connection the connection * @return true if the server support STUN * @throws SmackException if Smack detected an exceptional situation. * @throws XMPPException if an XMPP protocol error was received. * @throws InterruptedException if the calling thread was interrupted. */ public static boolean serviceAvailable(XMPPConnection connection) throws XMPPException, SmackException, InterruptedException { if (!connection.isConnected()) { return false; } LOGGER.fine("Service listing"); ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(connection); DiscoverItems items = disco.discoverItems(connection.getXMPPServiceDomain()); for (DiscoverItems.Item item : items.getItems()) { DiscoverInfo info = disco.discoverInfo(item.getEntityID()); for (DiscoverInfo.Identity identity : info.getIdentities()) { if (identity.getCategory().equals("proxy") && identity.getType().equals("stun")) if (info.containsFeature(NAMESPACE)) return true; } LOGGER.fine(item.getName() + "-" + info.getType()); } return false; }
Example #18
Source File: FeatureDiscovery.java From desktopclient-java with GNU General Public License v3.0 | 5 votes |
private EnumMap<Feature, JID> discover(JID entity, boolean withItems) { // NOTE: smack automatically creates instances of SDM and CapsM and connects them ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(mConn); // 1. get features from server EnumMap<Feature, JID> features = discover(discoManager, entity); if (features == null) return new EnumMap<>(FeatureDiscovery.Feature.class); if (!withItems) return features; // 2. get server items DiscoverItems items; try { items = discoManager.discoverItems(entity.toBareSmack()); } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException ex) { LOGGER.log(Level.WARNING, "can't get service discovery items", ex); return features; } // 3. get features from server items for (DiscoverItems.Item item: items.getItems()) { EnumMap<Feature, JID> itemFeatures = discover(discoManager, JID.fromSmack(item.getEntityID())); if (itemFeatures != null) features.putAll(itemFeatures); } LOGGER.info("supported server features: "+features); return features; }
Example #19
Source File: FeatureDiscovery.java From desktopclient-java with GNU General Public License v3.0 | 5 votes |
private static EnumMap<Feature, JID> discover(ServiceDiscoveryManager dm, JID entity) { DiscoverInfo info; try { // blocking // NOTE: null parameter does not work info = dm.discoverInfo(entity.toSmack()); } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException ex) { // not supported by all servers/server not reachable, we only know after trying //LOGGER.log(Level.WARNING, "can't get service discovery info", ex); LOGGER.warning("can't get info for " + entity + " " + ex.getMessage()); return null; } EnumMap<Feature, JID> features = new EnumMap<>(FeatureDiscovery.Feature.class); for (DiscoverInfo.Feature feature: info.getFeatures()) { String var = feature.getVar(); if (FEATURE_MAP.containsKey(var)) { features.put(FEATURE_MAP.get(var), entity); } } List<DiscoverInfo.Identity> identities = info.getIdentities(); LOGGER.config("entity: " + entity + " identities: " + identities.stream() .map(DiscoverInfo.Identity::toXML).collect(Collectors.toList()) + " features: " + info.getFeatures().stream() .map(DiscoverInfo.Feature::getVar).collect(Collectors.toList())); return features; }
Example #20
Source File: HashManager.java From Smack with Apache License 2.0 | 5 votes |
/** * Constructor of the HashManager. * * @param connection connection */ private HashManager(XMPPConnection connection) { super(connection); ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); sdm.addFeature(NAMESPACE.V2.toString()); addAlgorithmsToFeatures(RECOMMENDED); }
Example #21
Source File: Socks5ByteStreamManagerTest.java From Smack with Apache License 2.0 | 5 votes |
/** * The SOCKS5 Bytestream feature should be removed form the service discovery manager if Socks5 * bytestream feature is disabled. * * @throws InterruptedException if the calling thread was interrupted. * @throws SmackException if Smack detected an exceptional situation. * @throws XMPPErrorException if there was an XMPP error returned. */ @Test public void shouldDisableService() throws XMPPErrorException, SmackException, InterruptedException { final Protocol protocol = new Protocol(); final XMPPConnection connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID); Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection); ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(connection); assertTrue(discoveryManager.includesFeature(Bytestream.NAMESPACE)); byteStreamManager.disableService(); assertFalse(discoveryManager.includesFeature(Bytestream.NAMESPACE)); }
Example #22
Source File: Socks5BytestreamManager.java From Smack with Apache License 2.0 | 5 votes |
/** * Returns a list of JIDs of SOCKS5 proxies by querying the XMPP server. The SOCKS5 proxies are * in the same order as returned by the XMPP server. * * @return list of JIDs of SOCKS5 proxies * @throws XMPPErrorException if there was an error querying the XMPP server for SOCKS5 proxies * @throws NoResponseException if there was no response from the server. * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. */ public List<Jid> determineProxies() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { XMPPConnection connection = connection(); ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection); List<Jid> proxies = new ArrayList<>(); // get all items from XMPP server DiscoverItems discoverItems = serviceDiscoveryManager.discoverItems(connection.getXMPPServiceDomain()); // query all items if they are SOCKS5 proxies for (Item item : discoverItems.getItems()) { // skip blacklisted servers if (this.proxyBlacklist.contains(item.getEntityID())) { continue; } DiscoverInfo proxyInfo; try { proxyInfo = serviceDiscoveryManager.discoverInfo(item.getEntityID()); } catch (NoResponseException | XMPPErrorException e) { // blacklist errornous server proxyBlacklist.add(item.getEntityID()); continue; } if (proxyInfo.hasIdentity("proxy", "bytestreams")) { proxies.add(item.getEntityID()); } else { /* * server is not a SOCKS5 proxy, blacklist server to skip next time a Socks5 * bytestream should be established */ this.proxyBlacklist.add(item.getEntityID()); } } return proxies; }
Example #23
Source File: Socks5BytestreamManager.java From Smack with Apache License 2.0 | 5 votes |
/** * Disables the SOCKS5 Bytestream manager by removing the SOCKS5 Bytestream feature from the * service discovery, disabling the listener for SOCKS5 Bytestream initiation requests and * resetting its internal state, which includes removing this instance from the managers map. * <p> * To re-enable the SOCKS5 Bytestream feature invoke {@link #getBytestreamManager(XMPPConnection)}. * Using the file transfer API will automatically re-enable the SOCKS5 Bytestream feature. */ public synchronized void disableService() { XMPPConnection connection = connection(); // remove initiation packet listener connection.unregisterIQRequestHandler(initiationListener); // shutdown threads this.initiationListener.shutdown(); // clear listeners this.allRequestListeners.clear(); this.userListeners.clear(); // reset internal state this.lastWorkingProxy = null; this.proxyBlacklist.clear(); this.ignoredBytestreamRequests.clear(); // remove manager from static managers map managers.remove(connection); // shutdown local SOCKS5 proxy if there are no more managers for other connections if (managers.size() == 0) { Socks5Proxy.getSocks5Proxy().stop(); } // remove feature from service discovery ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection); // check if service discovery is not already disposed by connection shutdown if (serviceDiscoveryManager != null) { serviceDiscoveryManager.removeFeature(Bytestream.NAMESPACE); } }
Example #24
Source File: EntityTimeManager.java From Smack with Apache License 2.0 | 5 votes |
public synchronized void disable() { if (!enabled) return; ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection()); sdm.removeFeature(Time.NAMESPACE); enabled = false; }
Example #25
Source File: Workgroup.java From Smack with Apache License 2.0 | 5 votes |
/** * The workgroup service may be configured to send email. This queries the Workgroup Service * to see if the email service has been configured and is available. * * @return true if the email service is available, otherwise return false. * @throws SmackException if Smack detected an exceptional situation. * @throws InterruptedException if the calling thread was interrupted. */ public boolean isEmailAvailable() throws SmackException, InterruptedException { ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection); try { DomainBareJid workgroupService = workgroupJID.asDomainBareJid(); DiscoverInfo infoResult = discoManager.discoverInfo(workgroupService); return infoResult.containsFeature("jive:email:provider"); } catch (XMPPException e) { return false; } }
Example #26
Source File: RoomBrowser.java From Spark with Apache License 2.0 | 5 votes |
public void displayRoomInformation(final EntityBareJid roomJID) { SwingWorker worker = new SwingWorker() { RoomInfo roomInfo = null; DiscoverItems items = null; @Override public Object construct() { try { roomInfo = MultiUserChatManager.getInstanceFor( SparkManager.getConnection() ).getRoomInfo( roomJID ); ServiceDiscoveryManager manager = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection()); items = manager.discoverItems(roomJID); } catch (XMPPException | SmackException | InterruptedException e) { Log.error(e); } return "ok"; } @Override public void finished() { setupRoomInformationUI(roomJID, roomInfo, items); } }; worker.start(); }
Example #27
Source File: ConferenceUtils.java From Spark with Apache License 2.0 | 5 votes |
/** * Returns true if the room requires a password. * * @param roomJID the JID of the room. * @return true if the room requires a password. */ public static boolean isPasswordRequired(EntityBareJid roomJID) { // Check to see if the room is password protected ServiceDiscoveryManager discover = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection()); try { DiscoverInfo info = discover.discoverInfo(roomJID); return info.containsFeature("muc_passwordprotected"); } catch (XMPPException | SmackException | InterruptedException e) { Log.error(e); } return false; }
Example #28
Source File: EntityCapsTest.java From Smack with Apache License 2.0 | 5 votes |
/** * Adds 'feature' to conB and waits until conA observes a presence form conB. * * @param conA the connection to observe the presence on. * @param conB the connection to add the feature to. * @param feature the feature to add. * @throws Exception in case of an exception. */ private void addFeatureAndWaitForPresence(XMPPConnection conA, XMPPConnection conB, String feature) throws Exception { final ServiceDiscoveryManager sdmB = ServiceDiscoveryManager.getInstanceFor(conB); ThrowingRunnable action = new ThrowingRunnable() { @Override public void runOrThrow() throws Exception { sdmB.addFeature(feature); } }; performActionAndWaitForPresence(conA, conB, action); }
Example #29
Source File: FileTransferNegotiatorTest.java From Smack with Apache License 2.0 | 5 votes |
@BeforeEach public void setUp() throws Exception { connection = new DummyConnection(); connection.connect(); connection.login(); ServiceDiscoveryManager.getInstanceFor(connection); }
Example #30
Source File: RTPBridge.java From Smack with Apache License 2.0 | 5 votes |
/** * Check if the server support RTPBridge Service. * * @param connection TODO javadoc me please * @return true if the server supports the RTPBridge service * @throws XMPPErrorException if there was an XMPP error returned. * @throws NoResponseException if there was no response from the remote entity. * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. */ public static boolean serviceAvailable(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { if (!connection.isConnected()) { return false; } LOGGER.fine("Service listing"); ServiceDiscoveryManager disco = ServiceDiscoveryManager .getInstanceFor(connection); // DiscoverItems items = disco.discoverItems(connection.getXMPPServiceDomain()); // Iterator iter = items.getItems(); // while (iter.hasNext()) { // DiscoverItems.Item item = (DiscoverItems.Item) iter.next(); // if (item.getEntityID().startsWith("rtpbridge.")) { // return true; // } // } DiscoverInfo discoInfo = disco.discoverInfo(connection.getXMPPServiceDomain()); for (DiscoverInfo.Identity identity : discoInfo.getIdentities()) { if (identity.getName() != null && identity.getName().startsWith("rtpbridge")) { return true; } } return false; }