Java Code Examples for org.jivesoftware.smackx.disco.ServiceDiscoveryManager#discoverInfo()

The following examples show how to use org.jivesoftware.smackx.disco.ServiceDiscoveryManager#discoverInfo() . 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: ConferenceServiceBrowser.java    From Spark with Apache License 2.0 6 votes vote down vote up
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 2
Source File: ConferenceUtils.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
 * 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 3
Source File: BookmarksUI.java    From Spark with Apache License 2.0 6 votes vote down vote up
private Collection<DomainBareJid> getConferenceServices(DomainBareJid server) throws Exception {
    List<DomainBareJid> answer = new ArrayList<>();
    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());
    DiscoverItems items = discoManager.discoverItems(server);
    for (DiscoverItems.Item item : items.getItems()) {
        DomainBareJid entityID = item.getEntityID().asDomainBareJid();
        // TODO: We should not simply assumet that this is MUC service just because it starts with a given prefix.
        if (entityID.toString().startsWith("conference") || entityID.toString().startsWith("private")) {
            answer.add(entityID);
        }
        else {
            try {
                DiscoverInfo info = discoManager.discoverInfo(item.getEntityID());
                if (info.containsFeature("http://jabber.org/protocol/muc")) {
                    answer.add(entityID);
                }
            }
            catch (XMPPException | SmackException e) {
                Log.error("Problem when loading conference service.", e);
            }
        }
    }
    return answer;
}
 
Example 4
Source File: Enterprise.java    From Spark with Apache License 2.0 6 votes vote down vote up
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: PrivacyManager.java    From Spark with Apache License 2.0 6 votes vote down vote up
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 6
Source File: TransportUtils.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the user is registered with a gateway.
 *
 * @param con       the XMPPConnection.
 * @param transport the transport.
 * @return true if the user is registered with the transport.
 */
public static boolean isRegistered(XMPPConnection con, Transport transport) {
    if (!con.isConnected()) {
        return false;
    }

    ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(con);
    try {
        Jid jid = JidCreate.from(transport.getXMPPServiceDomain());
        DiscoverInfo info = discoveryManager.discoverInfo(jid);
        return info.containsFeature("jabber:iq:registered");
    }
    catch (XMPPException | SmackException | XmppStringprepException | InterruptedException e) {
        Log.error(e);
    }
    return false;
}
 
Example 7
Source File: ServiceDiscovery.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
@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 8
Source File: FeatureDiscovery.java    From desktopclient-java with GNU General Public License v3.0 5 votes vote down vote up
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 9
Source File: Workgroup.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * 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 10
Source File: Socks5BytestreamManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * 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 11
Source File: EntityCapsManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public DiscoverInfo getDiscoverInfoByUser(ServiceDiscoveryManager serviceDiscoveryManager, Jid jid) {
    DiscoverInfo info = EntityCapsManager.getDiscoverInfoByUser(jid);
    if (info != null) {
        return info;
    }

    NodeVerHash nodeVerHash = getNodeVerHashByJid(jid);
    if (nodeVerHash == null) {
        return null;
    }

    try {
        info = serviceDiscoveryManager.discoverInfo(jid, nodeVerHash.getNodeVer());
    } catch (NoResponseException | XMPPErrorException | NotConnectedException | InterruptedException e) {
        // TODO log
        return null;
    }

    if (verifyDiscoverInfoVersion(nodeVerHash.getVer(), nodeVerHash.getHash(), info)) {
        addDiscoverInfoByNode(nodeVerHash.getNodeVer(), info);
    } else {
        // TODO log
    }

    return info;
}
 
Example 12
Source File: RTPBridge.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
     * 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;
    }
 
Example 13
Source File: STUN.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * 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 14
Source File: ConferenceUtils.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * 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 15
Source File: GroupChatParticipantList.java    From Spark with Apache License 2.0 4 votes vote down vote up
public void setChatRoom(final ChatRoom chatRoom) {
	this.groupChatRoom = (GroupChatRoom) chatRoom;

	chat = groupChatRoom.getMultiUserChat();

	chat.addInvitationRejectionListener( ( jid1, reason, message, rejection ) -> {
    String nickname = userManager.getUserNicknameFromJID( jid1.toString() );

    userHasLeft(nickname);

    chatRoom.getTranscriptWindow().insertNotificationMessage(
        nickname + " has rejected the invitation.",
        ChatManager.NOTIFICATION_COLOR);
    } );

	listener = p -> SwingUtilities.invokeLater( () -> {
if (p.getError() != null) {
if (p.getError()
.getCondition()
.equals(StanzaError.Condition.conflict
.toString())) {
return;
}
}
final EntityFullJid userid = p.getFrom().asEntityFullJidOrThrow();

Resourcepart displayName = userid.getResourcepart();
userMap.put(displayName, userid);

if (p.getType() == Presence.Type.available) {
addParticipant(userid, p);
agentInfoPanel.setVisible(true);
	groupChatRoom.validate();
} else {
removeUser(displayName);
}

// When joining a room, check if the current user is an owner/admin. If so, the UI should allow the current
// user to change settings of this MUC.
final MUCUser mucUserEx = p.getExtension( MUCUser.ELEMENT, MUCUser.NAMESPACE );
if (mucUserEx != null && mucUserEx.getStatus().contains( MUCUser.Status.create( 110 ) ) ) // 110 = Inform user that presence refers to itself
{
final MUCItem item = mucUserEx.getItem();
if ( item != null )
{
if ( item.getAffiliation() == MUCAffiliation.admin || item.getAffiliation() == MUCAffiliation.owner )
{
groupChatRoom.notifySettingsAccessRight();
}
}
}
} );

	chat.addParticipantListener(listener);

	ServiceDiscoveryManager disco = ServiceDiscoveryManager
		.getInstanceFor(SparkManager.getConnection());
	try {
	    roomInformation = disco.discoverInfo(chat.getRoom());
	} catch (XMPPException | SmackException | InterruptedException e) {
	    Log.debug("Unable to retrieve room information for "
		    + chat.getRoom());
	}
    }
 
Example 16
Source File: PubSubManager.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the supported features of the servers pubsub implementation
 * as a standard {@link DiscoverInfo} instance.
 *
 * @return The supported features
 * @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 DiscoverInfo getSupportedFeatures() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    ServiceDiscoveryManager mgr = ServiceDiscoveryManager.getInstanceFor(connection());
    return mgr.discoverInfo(pubSubService);
}