本文整理汇总了Java中org.jivesoftware.smackx.disco.ServiceDiscoveryManager.discoverItems方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceDiscoveryManager.discoverItems方法的具体用法?Java ServiceDiscoveryManager.discoverItems怎么用?Java ServiceDiscoveryManager.discoverItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jivesoftware.smackx.disco.ServiceDiscoveryManager
的用法示例。
在下文中一共展示了ServiceDiscoveryManager.discoverItems方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: discoverItemsByFeature
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; //导入方法依赖的package包/类
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;
}
示例2: perform
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; //导入方法依赖的package包/类
@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;
}
示例3: getHostedRooms
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; //导入方法依赖的package包/类
/**
* 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;
}
示例4: determineProxies
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; //导入方法依赖的package包/类
/**
* 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;
}
示例5: serviceAvailable
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; //导入方法依赖的package包/类
/**
* 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;
}
示例6: discover
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; //导入方法依赖的package包/类
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);
}
}
示例7: discover
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; //导入方法依赖的package包/类
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;
}