providerMgr.addIQProvider("query", UserCheck.NAMESPACE, new UserCheck.Provider());
providerMgr.addIQProvider("query", PluginVersion.NAMESPACE, new PluginVersion.Provider());
XMPPConnection connection = new XMPPConnection(connConfig);
try {
connection.connect();
connection.login("admin", "admin");
String username="demo";
String pw="test";
String email="test@test.ch";
String fullName="gregor grunz";
int i = 7;
List packets = new ArrayList();
// for (int j = 1; j < 300; j++) {
// packets.add(new UserDelete(username+j));
//
// }
//packets.add(new UserCreate(username, pw, email, fullName));
packets.add(new UserCheck("administrator"));
packets.add(new UserCheck("author"));
//packets.add(new UserCheck("demo3"));
//packets.add(new UserCheck("demo4"));
//packets.add(new UserCheck("demo5"));
//packets.add(new PluginVersion());
//packets.add(new GroupCreate("testgroup","testgroup bla", "this is the testgroup"));
//packets.add(new GroupCreate("testgroup","testgroup bla", "this is the testgroup"));
//packets.add(new AddUserToGroup(username+i, "testgroup"));
//packets.add(new AddUserToGroup("admin", "testgroup"));
//packets.add(new RemoveUserFromGroup(username+i, "testgroup"));
//packets.add(new GroupDelete("testgroup"));
//packets.add(new GroupDelete("testgroup"));
//packets.add(new UserDelete(username+i));
//packets.add(new SessionCount());
//packets.add(new SessionItems());
Thread.sleep(1000);
long start = System.currentTimeMillis();
for (Iterator iterator = packets.iterator(); iterator.hasNext();) {
IQ iqPacket = (IQ) iterator.next();
iqPacket.setFrom(connection.getUser());
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(iqPacket.getPacketID()));
connection.sendPacket(iqPacket);
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server on status set.");
}
if (response.getError() != null) {
throw new XMPPException("Error . Cause: "+response.getError().getMessage());
} else if (response.getType() == IQ.Type.ERROR) {
System.out.println("could not create user....");
throw new XMPPException("Error . Cause: "+response.getError().getMessage());
}
if (response instanceof SessionCount) {
SessionCount sCount = (SessionCount) response;
System.out.println("number of sessions: "+sCount.getNumberOfSessions());
}
if (response instanceof IMSessionItems) {
IMSessionItems items = (IMSessionItems) response;
List<IMSessionItems.Item> l = items.getItems();
for (Iterator iterator2 = l.iterator(); iterator2.hasNext();) {
IMSessionItems.Item item = (IMSessionItems.Item) iterator2.next();
System.out.println("username: "+item.getUsername() );
System.out.println("presence msg: "+item.getPresenceMsg() );
System.out.println("status: "+item.getPresenceStatus() );
System.out.println("last acivity: "+item.getLastActivity() );
System.out.println("logintime: "+item.getLoginTime() );
}
}
if (response instanceof UserCheck) {
UserCheck check = (UserCheck) response;
System.out.println("has account responses: "+check.hasAccount());
}
if (response instanceof PluginVersion) {
PluginVersion version = (PluginVersion) response;
System.out.println("plugin version is: "+version.getVersion());
}
}
long stop = System.currentTimeMillis();
System.out.println("time..."+(stop-start));
Thread.sleep(1000);
connection.disconnect();
Thread.sleep(10000);
System.exit(0);
} catch (XMPPException e) {
System.out.println("error occured 1: "+e);