protected EntityViewActivity doInBackground(EntityViewActivity... activity) { // Get the XMMPConnection from the manager AbstractXMPPConnection conn = XMPPConnectionManager.getConnection(); // Obtain the ServiceDiscoveryManager associated with my XMPP connection this.discoManager = ServiceDiscoveryManager.getInstanceFor(conn); Entity entity = activity[0].myEntity; try { if ( entity.getNode() != null && entity.getNode() != "" ) { activity[0].myLeafInfo = discoManager.discoverInfo( entity.getJid() , entity.getNode() ); } else { activity[0].myLeafInfo = discoManager.discoverInfo( entity.getJid() ); } Log.d(LOGTAG, "Got Info!"); } catch (Exception ex) { Log.w(LOGTAG, "XMPP Disco error " + ex); errorMessage = ex.toString() ; } return activity[0]; }
/** * 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 <tt>null</tt> if none. * @throws SmackException if there was no response from the server. */ public String getReservedNickname() throws SmackException { 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; }
/** * Enable the Jabber services related to file transfer on the particular * connection. * * @param connection The connection on which to enable or disable the services. * @param isEnabled True to enable, false to disable. */ private static void setServiceEnabled(final XMPPConnection connection, final boolean isEnabled) { ServiceDiscoveryManager manager = ServiceDiscoveryManager .getInstanceFor(connection); List<String> namespaces = new ArrayList<String>(); namespaces.addAll(Arrays.asList(NAMESPACE)); namespaces.add(DataPacketExtension.NAMESPACE); if (!IBB_ONLY) { namespaces.add(Bytestream.NAMESPACE); } for (String namespace : namespaces) { if (isEnabled) { manager.addFeature(namespace); } else { manager.removeFeature(namespace); } } }
/** * 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<String>(); 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; }
private VersionManager(final XMPPConnection connection) { super(connection); ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); sdm.addFeature(Version.NAMESPACE); connection.registerIQRequestHandler(new AbstractIqRequestHandler(Version.ELEMENT, Version.NAMESPACE, IQ.Type.get, Mode.async) { @Override public IQ handleIQRequest(IQ iqRequest) { if (ourVersion == null) { return IQ.createErrorResponse(iqRequest, new XMPPError(Condition.not_acceptable)); } return Version.createResultFor(iqRequest, ourVersion); } }); }
/** * Initialize fields used in the tests. */ @Before 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.class); // create a SOCKS5 Bytestream initiation packet initBytestream = Socks5PacketUtils.createBytestreamInitiation(initiatorJID, targetJID, sessionID); initBytestream.addStreamHost(proxyJID, proxyAddress, 7777); }
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"); }
private List<String> discoverItemsByFeature(XmppURI uri, List<String> features) throws XMPPException, IOException, SmackException { // discover items ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(this.connectionManager.getConnection()); DiscoverItems discoverItems = discoveryManager.discoverItems(uri.getDomain()); List<DiscoverItems.Item> items = discoverItems.getItems(); List<String> result = new ArrayList<>(); // discover infos per item and check if specified feature set is supported for (DiscoverItems.Item item : items) { DiscoverInfo discoverInfo = discoveryManager.discoverInfo(item.getEntityID()); boolean conatinsAllFeatures = true; for (String feature : features) { if (!discoverInfo.containsFeature(feature)) { conatinsAllFeatures = false; break; } } if (conatinsAllFeatures) { result.add(item.getEntityID()); } else if (logger.isDebugEnabled()) { logger.debug("Entity {} does not support the specified features.", item.getEntityID()); } } return result; }
private void initServiceDiscovery() { debug(TAG, "init service discovery"); // register connection features ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mConnection); if (!sdm.includesFeature(DISCO_FEATURE)) sdm.addFeature(DISCO_FEATURE); if (!sdm.includesFeature(DeliveryReceipt.NAMESPACE)) sdm.addFeature(DeliveryReceipt.NAMESPACE); sdm.addFeature(HttpFileUploadManager.NAMESPACE); DeliveryReceiptManager.getInstanceFor(mConnection).dontAutoAddDeliveryReceiptRequests(); DeliveryReceiptManager.getInstanceFor(mConnection).setAutoReceiptMode(DeliveryReceiptManager.AutoReceiptMode.disabled); }
private final void setPrivacyList(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { List<PrivacyItem> list = new ArrayList<PrivacyItem>(PRIVACY_LIST.size() + 10); list.addAll(PRIVACY_LIST); // Whitelist all JIDs of the own service, e.g. conference.service.com, proxy.service.com for (Item i : ServiceDiscoveryManager.getInstanceFor(connection) .discoverItems(connection.getServiceName()).getItems()) { PrivacyItem allow = new PrivacyItem(Type.jid, i.getEntityID(), true, list.size() + 1); list.add(allow); } // This is an ugly workaround for XMPP servers that apply privacy lists also to stanzas // originating from themselves. For example http://issues.igniterealtime.org/browse/OF-724 // Because there are such services in the wild and XEP-0016 is not clear on that topic, we // explicitly have to add a JID rule that allows stanzas from the service PrivacyItem allowService = new PrivacyItem(Type.jid, connection.getServiceName(), true, list.size() + 1); list.add(allowService); mPrivacyListManager.createPrivacyList(PRIVACY_LIST_NAME, list); mPrivacyListManager.setDefaultListName(PRIVACY_LIST_NAME); }
@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; }
private DisplayedManager(XMPPConnection connection) { super(connection); ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); sdm.addFeature(Displayed.NAMESPACE); connection.addAsyncStanzaListener(packet -> { Displayed receipt = Displayed.from((Message) packet); for (ReceiptReceivedListener listener : receiptReceivedListeners) { listener.onReceiptReceived(packet.getFrom(), packet.getTo(), receipt.getId(), packet); } }, MESSAGES_WITH_DISPLAYED); }
private ReceivedManager(XMPPConnection connection) { super(connection); ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); sdm.addFeature(Received.NAMESPACE); connection.addAsyncStanzaListener(packet -> { Received receipt = Received.from((Message) packet); for (ReceiptReceivedListener listener : receiptReceivedListeners) { listener.onReceiptReceived(packet.getFrom(), packet.getTo(), receipt.getId(), packet); } }, MESSAGES_WITH_RECEIVED); }
private DeliveredReceiptManager(XMPPConnection connection) { super(connection); ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); sdm.addFeature(DeliveredReceipt.NAMESPACE); connection.addAsyncStanzaListener(packet -> { DeliveredReceipt receipt = DeliveredReceipt.from((Message) packet); for (ReceiptReceivedListener listener : receiptReceivedListeners) { listener.onReceiptReceived(packet.getFrom(), packet.getTo(), receipt.getId(), packet); } }, MESSAGES_WITH_DELIVERED_RECEIPT); }
private ReadReceiptManager(XMPPConnection connection) { super(connection); ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); sdm.addFeature(ReadReceipt.NAMESPACE); connection.addAsyncStanzaListener(packet -> { ReadReceipt receipt = ReadReceipt.from((Message) packet); for (ReceiptReceivedListener listener : receiptReceivedListeners) { listener.onReceiptReceived(packet.getFrom(), packet.getTo(), receipt.getId(), packet); } }, MESSAGES_WITH_READ_RECEIPT); }
public DiscoverItems discoverMUCLightItems() { DiscoverItems discoverItems = null; try { discoverItems = ServiceDiscoveryManager.getInstanceFor(mXMPPConnection).discoverItems(JidCreate.from(MUC_LIGHT_SERVICE_NAME)); } catch (Exception e) { e.printStackTrace(); } return discoverItems; }
@Override protected Boolean doInBackground(ArrayList<Entity>... entityList) { Entity entity = null ; Iterator entityIterator = entityList[0].iterator(); // Get the XMMPConnection from the manager AbstractXMPPConnection conn = XMPPConnectionManager.getConnection(); // Obtain the ServiceDiscoveryManager associated with my XMPP connection this.discoManager = ServiceDiscoveryManager.getInstanceFor(conn); while ( entityIterator.hasNext() ) { if (this.isCancelled()) { Log.d(LOGTAG , "Cancelling" ); return null; } Log.d(LOGTAG , "Loading info for icons" ); entity = (Entity) entityIterator.next(); try { if ( entity.getNode() != null && entity.getNode() != "" ) { entityInfo = discoManager.discoverInfo( entity.getJid() , entity.getNode() ); } else { entityInfo = discoManager.discoverInfo( entity.getJid() ); } } catch (Exception ex) { Log.w(LOGTAG, "XMPP Disco error " + ex); errorMessage = ex.toString() ; this.publishProgress( false ); continue; } entity.setIdentities( entityInfo.getIdentities() ); this.publishProgress( true ); } return null ; }
/** * 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 */ public boolean isEmailAvailable() throws SmackException { ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection); try { String workgroupService = XmppStringUtils.parseDomain(workgroupJID); DiscoverInfo infoResult = discoManager.discoverInfo(workgroupService); return infoResult.containsFeature("jive:email:provider"); } catch (XMPPException e) { return false; } }
/** * Enables or disables the XHTML support on a given connection.<p> * * Before starting to send XHTML messages to a user, check that the user can handle XHTML * messages. Enable the XHTML 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 synchronized static void setServiceEnabled(XMPPConnection connection, boolean enabled) { if (isServiceEnabled(connection) == enabled) return; if (enabled) { ServiceDiscoveryManager.getInstanceFor(connection).addFeature(XHTMLExtension.NAMESPACE); } else { ServiceDiscoveryManager.getInstanceFor(connection).removeFeature(XHTMLExtension.NAMESPACE); } }
/** * Returns a List of HostedRooms where each HostedRoom has the XMPP address of the room and the room's name. * Once discovered the rooms hosted by a chat service it is possible to discover more detailed room information or * join the room. * * @param serviceName the service that is hosting the rooms to discover. * @return a collection of HostedRooms. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException */ public List<HostedRoom> getHostedRooms(String serviceName) throws NoResponseException, XMPPErrorException, NotConnectedException { ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection()); DiscoverItems discoverItems = discoManager.discoverItems(serviceName); List<DiscoverItems.Item> items = discoverItems.getItems(); List<HostedRoom> answer = new ArrayList<HostedRoom>(items.size()); for (DiscoverItems.Item item : items) { answer.add(new HostedRoom(item)); } return answer; }
/** * 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 synchronized static 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); } }
public synchronized void enable() { if (enabled) return; ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection()); sdm.addFeature(Time.NAMESPACE); enabled = true; }
public synchronized void disable() { if (!enabled) return; ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection()); sdm.removeFeature(Time.NAMESPACE); enabled = false; }
/** * 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); } }
/** * 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 */ private List<String> determineProxies() throws NoResponseException, XMPPErrorException, NotConnectedException { XMPPConnection connection = connection(); ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection); List<String> proxies = new ArrayList<String>(); // get all items from XMPP server DiscoverItems discoverItems = serviceDiscoveryManager.discoverItems(connection.getServiceName()); // 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; }
private ChatStateManager(XMPPConnection connection) { super(connection); chatManager = ChatManager.getInstanceFor(connection); chatManager.addOutgoingMessageInterceptor(outgoingInterceptor, filter); chatManager.addChatListener(incomingInterceptor); ServiceDiscoveryManager.getInstanceFor(connection).addFeature(NAMESPACE); INSTANCES.put(connection, this); }
/** * Returns the number of offline messages for the user of the connection. * * @return the number of offline messages for the user of the connection. * @throws XMPPErrorException If the user is not allowed to make this request or the server does * not support offline message retrieval. * @throws NoResponseException if there was no response from the server. * @throws NotConnectedException */ public int getMessageCount() throws NoResponseException, XMPPErrorException, NotConnectedException { DiscoverInfo info = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(null, namespace); Form extendedInfo = Form.getFormFrom(info); if (extendedInfo != null) { String value = extendedInfo.getField("number_of_messages").getValues().get(0); return Integer.parseInt(value); } return 0; }
/** * 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); }
/** * The SOCKS5 Bytestream feature should be removed form the service discovery manager if Socks5 * bytestream feature is disabled. */ @Test public void shouldDisableService() { Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection); ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(connection); assertTrue(discoveryManager.includesFeature(Bytestream.NAMESPACE)); byteStreamManager.disableService(); assertFalse(discoveryManager.includesFeature(Bytestream.NAMESPACE)); }
@Before public void setUp() throws Exception { // Uncomment this to enable debug output // SmackConfiguration.DEBUG = true; connection = new DummyConnection(); connection.connect(); connection.login(); ServiceDiscoveryManager.getInstanceFor(connection); }
/** * Check if the server support RTPBridge Service. * * @param connection * @return true if the server supports the RTPBridge service * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException */ public static boolean serviceAvailable(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException { if (!connection.isConnected()) { return false; } LOGGER.fine("Service listing"); ServiceDiscoveryManager disco = ServiceDiscoveryManager .getInstanceFor(connection); // DiscoverItems items = disco.discoverItems(connection.getServiceName()); // 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.getServiceName()); for (DiscoverInfo.Identity identity : discoInfo.getIdentities()) { if ((identity.getName() != null) && (identity.getName().startsWith("rtpbridge"))) { return true; } } return false; }
/** * Check if the server support STUN Service. * * @param connection the connection * @return true if the server support STUN * @throws SmackException * @throws XMPPException */ public static boolean serviceAvailable(XMPPConnection connection) throws XMPPException, SmackException { if (!connection.isConnected()) { return false; } LOGGER.fine("Service listing"); ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(connection); DiscoverItems items = disco.discoverItems(connection.getServiceName()); 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; }
private void discover() throws XMPPErrorException, URISyntaxException, SmackException, XmlException { System.out.println("discover root services"); // Obtain the ServiceDiscoveryManager associated with my XMPPConnection ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection); // Get the items of a given XMPP entity // This gets the items associated with online catalog service DiscoverItems discoItems = discoManager.discoverItems(TEST_DOMAIN); // Get the discovered items of the queried XMPP entity List<Item> items = discoItems.getItems(); // set exchange and root server for(Item item : items) { System.out.println(item.getEntityID()); if(ServiceNames.RootComponentName.equals(item.getName())) rootURI = item.getEntityID(); else if(ServiceNames.ExchangeComponentName.equals(item.getName())) exchangeURI = item.getEntityID(); } // discover root features if(rootURI != null) { checkFeatures(discoManager, rootURI); } // discover exchange features if(exchangeURI != null) { checkFeatures(discoManager, exchangeURI); } }
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; }
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; }
private void receiveBlogPosts() { PEPManager pepManager = PEPManager.getInstanceFor(mXMPPConnection); pepManager.addPEPListener(new PEPListener() { @Override public void eventReceived(EntityBareJid entityBareJid, EventElement eventElement, Message message) { if (EventElementType.items == eventElement.getEventType()) { ItemsExtension itemsExtension = (ItemsExtension) eventElement.getExtensions().get(0); PayloadItem payloadItem = (PayloadItem) itemsExtension.getItems().get(0); PostEntryExtension postEntryExtension = (PostEntryExtension) payloadItem.getPayload(); String id = postEntryExtension.getId(); String jid = entityBareJid.toString(); String title = postEntryExtension.getTitle(); Date published = postEntryExtension.getPublished(); Date updated = postEntryExtension.getUpdated(); BlogPost blogPost = new BlogPost(id, jid, null, title, published, updated); RealmManager.getInstance().saveBlogPost(blogPost); String commentsNode = PublishCommentExtension.NODE + "/" + id; ServiceDiscoveryManager.getInstanceFor(mXMPPConnection).addFeature(commentsNode + "+notify"); notifyNewBlogPost(); } } private void notifyNewBlogPost() { MangostaApplication mangostaApplication = MangostaApplication.getInstance(); if (mangostaApplication.isClosed()) { BlogPostNotifications.newBlogPostNotification(); } else { mangostaApplication.getCurrentActivity().runOnUiThread(new Runnable() { @Override public void run() { new Event(Event.Type.BLOG_POST_CREATED).post(); } }); } } }); }
protected CollectionViewActivity doInBackground(CollectionViewActivity... activity) { // Get the XMMPConnection from the manager AbstractXMPPConnection conn = XMPPConnectionManager.getConnection(); // Obtain the ServiceDiscoveryManager associated with my XMPP connection this.discoManager = ServiceDiscoveryManager.getInstanceFor(conn); DiscoverItems discoItems; // This example gets the items associated with online catalog service try { discoItems = this.discoManager.discoverItems( activity[0].currentEntity.getJid() , activity[0].currentEntity.getNode() ); } catch (Exception ex) { Log.w(LOGTAG, "XMPP Disco error " + ex); errorMessage = ex.getMessage() ; return activity[0]; } // Get the discovered items of the queried XMPP entity Iterator it = discoItems.getItems().iterator(); Log.i(LOGTAG, "Got items:" + it.toString()); this.entityList = new ArrayList<>(); this.entityList.clear(); // Display the items of the remote XMPP entity int id = 0; while (it.hasNext()) { DiscoverItems.Item item = (DiscoverItems.Item) it.next(); Entity entity = new Entity(item.getEntityID(), item.getNode() , item.getName() ); Log.i(LOGTAG, "Got item:" + item.getName() + " : " + item.getEntityID()); entity.setId(id); entity.setName(item.getName()); this.entityList.add(entity); id++; } Collections.sort(this.entityList); return activity[0]; }
@Override public void connectionCreated(XMPPConnection connection) { ServiceDiscoveryManager.getInstanceFor(connection).addFeature(NAMESPACE); }
private AdHocCommandManager(XMPPConnection connection) { super(connection); this.serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection); // Add the feature to the service discovery manage to show that this // connection supports the AdHoc-Commands protocol. // This information will be used when another client tries to // discover whether this client supports AdHoc-Commands or not. ServiceDiscoveryManager.getInstanceFor(connection).addFeature( NAMESPACE); // Set the NodeInformationProvider that will provide information about // which AdHoc-Commands are registered, whenever a disco request is // received ServiceDiscoveryManager.getInstanceFor(connection) .setNodeInformationProvider(NAMESPACE, new AbstractNodeInformationProvider() { @Override public List<DiscoverItems.Item> getNodeItems() { List<DiscoverItems.Item> answer = new ArrayList<DiscoverItems.Item>(); Collection<AdHocCommandInfo> commandsList = getRegisteredCommands(); for (AdHocCommandInfo info : commandsList) { DiscoverItems.Item item = new DiscoverItems.Item( info.getOwnerJID()); item.setName(info.getName()); item.setNode(info.getNode()); answer.add(item); } return answer; } }); // The packet listener and the filter for processing some AdHoc Commands // Packets connection.registerIQRequestHandler(new AbstractIqRequestHandler(AdHocCommandData.ELEMENT, AdHocCommandData.NAMESPACE, IQ.Type.set, Mode.async) { @Override public IQ handleIQRequest(IQ iqRequest) { AdHocCommandData requestData = (AdHocCommandData) iqRequest; try { return processAdHocCommand(requestData); } catch (NoResponseException | NotConnectedException e) { LOGGER.log(Level.INFO, "processAdHocCommand threw exceptino", e); return null; } } }); sessionsSweeper = null; }