use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.
the class RSMSetProviderTest method testRsmSetProvider.
@Test
public void testRsmSetProvider() throws Exception {
// @formatter:off
final String rsmset = "<iq type='get' id='iqget'>" + "<pubsub xmlns='http://jabber.org/protocol/pubsub'>" + "<set xmlns='http://jabber.org/protocol/rsm'>" + "<after>aftervalue</after>" + "<before>beforevalue</before>" + "<count>1</count>" + "<first index='2'>foo@bar.com</first>" + "<index>3</index>" + "<last>lastvalue</last>" + "<max>4</max>" + "</set>" + "</pubsub>" + "</iq>";
// @formatter:on
IQ iqWithRsm = (IQ) PacketParserUtils.parseStanza(rsmset);
RSMSet rsm = (RSMSet) iqWithRsm.getExtension(RSMSet.ELEMENT, RSMSet.NAMESPACE);
assertNotNull(rsm);
assertEquals("aftervalue", rsm.getAfter());
assertEquals("beforevalue", rsm.getBefore());
assertEquals(1, rsm.getCount());
assertEquals(2, rsm.getFirstIndex());
assertEquals("foo@bar.com", rsm.getFirst());
assertEquals(3, rsm.getIndex());
assertEquals("lastvalue", rsm.getLast());
assertEquals(4, rsm.getMax());
}
use of org.jivesoftware.smack.packet.IQ in project Openfire by igniterealtime.
the class JingleChannelIQ method createIQ.
public static IQ createIQ(String ID, String to, String from, IQ.Type type) {
IQ iqPacket = new IQ() {
public String getChildElementXML() {
return null;
}
};
iqPacket.setPacketID(ID);
iqPacket.setTo(to);
iqPacket.setFrom(from);
iqPacket.setType(type);
return iqPacket;
}
use of org.jivesoftware.smack.packet.IQ in project Openfire by igniterealtime.
the class ThrottleTestWriter method main.
/**
* Starts the throttle test write client.
*
* @param args application arguments.
*/
public static void main(String[] args) {
if (args.length != 3) {
System.out.println("Usage: java ThrottleTestWriter [server] [username] [password]");
System.exit(0);
}
String server = args[0];
String username = args[1];
String password = args[2];
try {
// Connect to the server, without TLS encryption.
ConnectionConfiguration config = new ConnectionConfiguration(server);
config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
final XMPPConnection con = new XMPPConnection(config);
System.out.print("Connecting to " + server + "... ");
con.connect();
con.login(username, password, "writer");
System.out.print("success.");
System.out.println("");
// Get the "real" server address.
server = con.getServiceName();
String writerAddress = username + "@" + server + "/writer";
final String readerAddress = username + "@" + server + "/reader";
System.out.println("Registered as " + writerAddress);
// Look for the reader process.
System.out.print("Looking for " + readerAddress + "...");
while (true) {
IQ testIQ = new Time();
testIQ.setType(IQ.Type.GET);
testIQ.setTo(readerAddress);
PacketCollector collector = con.createPacketCollector(new PacketIDFilter(testIQ.getPacketID()));
con.sendPacket(testIQ);
// Wait 5 seconds.
long start = System.currentTimeMillis();
Packet result = collector.nextResult(5000);
collector.cancel();
// If we got a result, continue.
if (result != null && result.getError() == null) {
System.out.println(" found reader. Starting packet flood.");
break;
}
System.out.print(".");
long end = System.currentTimeMillis();
if (end - start < 5000) {
try {
Thread.sleep(5000 - (end - start));
} catch (Exception e) {
// ignore.
}
}
}
// Create a process to log how many packets we're writing out.
Runnable statsRunnable = new Runnable() {
public void run() {
while (!done) {
try {
Thread.sleep(5000);
} catch (Exception e) {
/* ignore */
}
int count = packetCount.getAndSet(0);
System.out.println("Packets per second: " + (count / 5));
}
}
};
Thread statsThread = new Thread(statsRunnable);
statsThread.setDaemon(true);
statsThread.start();
// Now start flooding packets.
Message testMessage = new Message(readerAddress);
testMessage.setBody("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
while (!done) {
con.sendPacket(testMessage);
packetCount.getAndIncrement();
}
} catch (Exception e) {
System.out.println("\nError: " + e.getMessage());
e.printStackTrace();
}
}
use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.
the class UserSearch method sendSearchForm.
/**
* Sends the filled out answer form to be sent and queried by the search service.
*
* @param con the current XMPPConnection.
* @param searchForm the <code>Form</code> to send for querying.
* @param searchService the search service to use. (ex. search.jivesoftware.com)
* @return ReportedData the data found from the query.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public ReportedData sendSearchForm(XMPPConnection con, Form searchForm, DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
UserSearch search = new UserSearch();
search.setType(IQ.Type.set);
search.setTo(searchService);
search.addExtension(searchForm.getDataFormToSend());
IQ response = (IQ) con.createStanzaCollectorAndSend(search).nextResultOrThrow();
return ReportedData.getReportedDataFrom(response);
}
use of org.jivesoftware.smack.packet.IQ in project intellij-plugins by JetBrains.
the class JabberFacadeImpl method setVCardInfo.
public void setVCardInfo(String nickName, String firstName, String lastName) throws XMPPException {
assert isConnectedAndAuthenticated() : "Not connected or authenticated";
VCard vCard = new VCard();
vCard.setFirstName(firstName);
vCard.setLastName(lastName);
vCard.setNickName(nickName);
PacketCollector collector = myConnection.createPacketCollector(new PacketIDFilter(vCard.getPacketID()));
vCard.save(myConnection);
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
collector.cancel();
if (response == null) {
throw new XMPPException("No response from the server.");
} else // If the server replied with an error, throw an exception.
if (response.getType() == IQ.Type.ERROR) {
throw new XMPPException(response.getError());
}
}
Aggregations