Smack API 抛出 item-not-found(404) 异常
Smack API throws item-not-found(404) exception
这是代码
Iterator i = MultiUserChat.getJoinedRooms(connectionManager.getXMPPConnection(), "test123@dulanjaya-pc");
while(i.hasNext()) {
System.out.println(i.next());
}
想通了。
需要将服务设置为 /Smack
Iterator i = MultiUserChat.getJoinedRooms(connectionManager.getXMPPConnection(), "test123@dulanjaya-pc/Smack");
也许这段代码对您有帮助。
boolean supports = MultiUserChat.isServiceEnabled(connection,"test3@pc2010102716/spark");
if(supports) {
Iterator<String> joinedRooms = MultiUserChat.getJoinedRooms(connection,"test3@pc2010102716/spark");
while(joinedRooms.hasNext()) {
System.out.println("test3 has joined Room " + joinedRooms.next());
}
}
getJoinedRooms 的源代码如下所示,告诉我们该方法的第二个参数需要一个完全限定的xmpp ID。它显示的 ID 示例不完整,完整的 ID 应包含资源名称,例如 /smack、/spark 和 /android.
/**
* Returns an Iterator on the rooms where the requested user has joined. The Iterator will
* contain Strings where each String represents a room (e.g. room@muc.jabber.org).
*
* @param connection the connection to use to perform the service discovery.
* @param user the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com.
* @return an Iterator on the rooms where the requested user has joined.
*/
public static Iterator<String> getJoinedRooms(Connection connection, String user) {
try {
ArrayList<String> answer = new ArrayList<String>();
// Send the disco packet to the user
DiscoverItems result =
ServiceDiscoveryManager.getInstanceFor(connection).discoverItems(user, discoNode);
// Collect the entityID for each returned item
for (Iterator<DiscoverItems.Item> items=result.getItems(); items.hasNext();) {
answer.add(items.next().getEntityID());
}
return answer.iterator();
}
catch (XMPPException e) {
e.printStackTrace();
// Return an iterator on an empty collection
return new ArrayList<String>().iterator();
}
}
这是代码
Iterator i = MultiUserChat.getJoinedRooms(connectionManager.getXMPPConnection(), "test123@dulanjaya-pc");
while(i.hasNext()) {
System.out.println(i.next());
}
想通了。 需要将服务设置为 /Smack
Iterator i = MultiUserChat.getJoinedRooms(connectionManager.getXMPPConnection(), "test123@dulanjaya-pc/Smack");
也许这段代码对您有帮助。
boolean supports = MultiUserChat.isServiceEnabled(connection,"test3@pc2010102716/spark");
if(supports) {
Iterator<String> joinedRooms = MultiUserChat.getJoinedRooms(connection,"test3@pc2010102716/spark");
while(joinedRooms.hasNext()) {
System.out.println("test3 has joined Room " + joinedRooms.next());
}
}
getJoinedRooms 的源代码如下所示,告诉我们该方法的第二个参数需要一个完全限定的xmpp ID。它显示的 ID 示例不完整,完整的 ID 应包含资源名称,例如 /smack、/spark 和 /android.
/**
* Returns an Iterator on the rooms where the requested user has joined. The Iterator will
* contain Strings where each String represents a room (e.g. room@muc.jabber.org).
*
* @param connection the connection to use to perform the service discovery.
* @param user the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com.
* @return an Iterator on the rooms where the requested user has joined.
*/
public static Iterator<String> getJoinedRooms(Connection connection, String user) {
try {
ArrayList<String> answer = new ArrayList<String>();
// Send the disco packet to the user
DiscoverItems result =
ServiceDiscoveryManager.getInstanceFor(connection).discoverItems(user, discoNode);
// Collect the entityID for each returned item
for (Iterator<DiscoverItems.Item> items=result.getItems(); items.hasNext();) {
answer.add(items.next().getEntityID());
}
return answer.iterator();
}
catch (XMPPException e) {
e.printStackTrace();
// Return an iterator on an empty collection
return new ArrayList<String>().iterator();
}
}