mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-02 06:45:59 +01:00
Improve packet send and result collecting API
Instead of repeating the same pattern, when sending an IQ get/set packet and collecting the response PacketFilter filter = new PacketIDFilter(request.getPacketID()), PacketCollector collector = connection.createPacketCollector(filter); connection.sendPacket(reg); IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Stop queuing results collector.cancel(); if (result == null) { throw new XMPPException("No response from server."); } else if (result.getType() == IQ.Type.ERROR) { throw new XMPPException(result.getError()); } the API got redesigned, so that the above code block can be replaced with Packet result = connection.createPacketCollectorAndSend(request).nextResultOrThrow();
This commit is contained in:
parent
e6d5385129
commit
7bd7b3d24c
50 changed files with 333 additions and 1489 deletions
|
@ -227,19 +227,7 @@ public class AccountManager {
|
||||||
attributes.put("username",username);
|
attributes.put("username",username);
|
||||||
attributes.put("password",password);
|
attributes.put("password",password);
|
||||||
reg.setAttributes(attributes);
|
reg.setAttributes(attributes);
|
||||||
PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
|
connection.createPacketCollectorAndSend(reg).nextResultOrThrow();
|
||||||
new PacketTypeFilter(IQ.class));
|
|
||||||
PacketCollector collector = connection.createPacketCollector(filter);
|
|
||||||
connection.sendPacket(reg);
|
|
||||||
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
collector.cancel();
|
|
||||||
if (result == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (result.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(result.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -262,15 +250,7 @@ public class AccountManager {
|
||||||
new PacketTypeFilter(IQ.class));
|
new PacketTypeFilter(IQ.class));
|
||||||
PacketCollector collector = connection.createPacketCollector(filter);
|
PacketCollector collector = connection.createPacketCollector(filter);
|
||||||
connection.sendPacket(reg);
|
connection.sendPacket(reg);
|
||||||
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
collector.nextResultOrThrow();
|
||||||
// Stop queuing results
|
|
||||||
collector.cancel();
|
|
||||||
if (result == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (result.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(result.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -292,19 +272,7 @@ public class AccountManager {
|
||||||
// To delete an account, we add a single attribute, "remove", that is blank.
|
// To delete an account, we add a single attribute, "remove", that is blank.
|
||||||
attributes.put("remove", "");
|
attributes.put("remove", "");
|
||||||
reg.setAttributes(attributes);
|
reg.setAttributes(attributes);
|
||||||
PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
|
connection.createPacketCollectorAndSend(reg).nextResultOrThrow();
|
||||||
new PacketTypeFilter(IQ.class));
|
|
||||||
PacketCollector collector = connection.createPacketCollector(filter);
|
|
||||||
connection.sendPacket(reg);
|
|
||||||
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
collector.cancel();
|
|
||||||
if (result == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (result.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(result.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -315,21 +283,6 @@ public class AccountManager {
|
||||||
private synchronized void getRegistrationInfo() throws XMPPException {
|
private synchronized void getRegistrationInfo() throws XMPPException {
|
||||||
Registration reg = new Registration();
|
Registration reg = new Registration();
|
||||||
reg.setTo(connection.getServiceName());
|
reg.setTo(connection.getServiceName());
|
||||||
PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
|
info = (Registration) connection.createPacketCollectorAndSend(reg).nextResultOrThrow();
|
||||||
new PacketTypeFilter(IQ.class));
|
|
||||||
PacketCollector collector = connection.createPacketCollector(filter);
|
|
||||||
connection.sendPacket(reg);
|
|
||||||
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
collector.cancel();
|
|
||||||
if (result == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (result.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(result.getError());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
info = (Registration)result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.jivesoftware.smack.compression.XMPPInputOutputStream;
|
||||||
import org.jivesoftware.smack.compression.Java7ZlibInputOutputStream;
|
import org.jivesoftware.smack.compression.Java7ZlibInputOutputStream;
|
||||||
import org.jivesoftware.smack.debugger.SmackDebugger;
|
import org.jivesoftware.smack.debugger.SmackDebugger;
|
||||||
import org.jivesoftware.smack.filter.PacketFilter;
|
import org.jivesoftware.smack.filter.PacketFilter;
|
||||||
|
import org.jivesoftware.smack.filter.PacketIDFilter;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smack.packet.Presence;
|
import org.jivesoftware.smack.packet.Presence;
|
||||||
|
|
||||||
|
@ -172,6 +173,11 @@ public abstract class Connection {
|
||||||
*/
|
*/
|
||||||
private ChatManager chatManager = null;
|
private ChatManager chatManager = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private long packetReplyTimeout = SmackConfiguration.getDefaultPacketReplyTimeout();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SmackDebugger allows to log and debug XML traffic.
|
* The SmackDebugger allows to log and debug XML traffic.
|
||||||
*/
|
*/
|
||||||
|
@ -563,6 +569,24 @@ public abstract class Connection {
|
||||||
return connectionListeners;
|
return connectionListeners;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new packet collector collecting packets that are replies to <code>packet</code>.
|
||||||
|
* Does also send <code>packet</code>. Note that the packet filter is at the moment created as
|
||||||
|
* ID filter of <code>packet</code>'s ID. This may change in the future to also check the
|
||||||
|
* correct "from JID" value.
|
||||||
|
*
|
||||||
|
* @param packet the packet to filter responses from
|
||||||
|
* @return a new packet collector.
|
||||||
|
*/
|
||||||
|
public PacketCollector createPacketCollectorAndSend(Packet packet) {
|
||||||
|
PacketFilter packetFilter = new PacketIDFilter(packet.getPacketID());
|
||||||
|
// Create the packet collector before sending the packet
|
||||||
|
PacketCollector packetCollector = createPacketCollector(packetFilter);
|
||||||
|
// Now we can send the packet as the collector has been created
|
||||||
|
sendPacket(packet);
|
||||||
|
return packetCollector;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new packet collector for this connection. A packet filter determines
|
* Creates a new packet collector for this connection. A packet filter determines
|
||||||
* which packets will be accumulated by the collector. A PacketCollector is
|
* which packets will be accumulated by the collector. A PacketCollector is
|
||||||
|
@ -848,6 +872,10 @@ public abstract class Connection {
|
||||||
rosterVersioningSupported = true;
|
rosterVersioningSupported = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getPacketReplyTimeout() {
|
||||||
|
return packetReplyTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapper class to associate a packet filter with a listener.
|
* A wrapper class to associate a packet filter with a listener.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -17,9 +17,9 @@
|
||||||
|
|
||||||
package org.jivesoftware.smack;
|
package org.jivesoftware.smack;
|
||||||
|
|
||||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
|
||||||
import org.jivesoftware.smack.packet.Authentication;
|
import org.jivesoftware.smack.packet.Authentication;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
|
|
||||||
import javax.security.auth.callback.CallbackHandler;
|
import javax.security.auth.callback.CallbackHandler;
|
||||||
import javax.security.auth.callback.PasswordCallback;
|
import javax.security.auth.callback.PasswordCallback;
|
||||||
|
@ -60,22 +60,9 @@ class NonSASLAuthentication implements UserAuthentication {
|
||||||
discoveryAuth.setType(IQ.Type.GET);
|
discoveryAuth.setType(IQ.Type.GET);
|
||||||
discoveryAuth.setUsername(username);
|
discoveryAuth.setUsername(username);
|
||||||
|
|
||||||
PacketCollector collector =
|
|
||||||
connection.createPacketCollector(new PacketIDFilter(discoveryAuth.getPacketID()));
|
|
||||||
// Send the packet
|
|
||||||
connection.sendPacket(discoveryAuth);
|
|
||||||
// Wait up to a certain number of seconds for a response from the server.
|
|
||||||
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from the server.");
|
|
||||||
}
|
|
||||||
// If the server replied with an error, throw an exception.
|
|
||||||
else if (response.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
// Otherwise, no error so continue processing.
|
// Otherwise, no error so continue processing.
|
||||||
Authentication authTypes = (Authentication) response;
|
Authentication authTypes = (Authentication) connection.createPacketCollectorAndSend(
|
||||||
collector.cancel();
|
discoveryAuth).nextResultOrThrow();
|
||||||
|
|
||||||
// Now, create the authentication packet we'll send to the server.
|
// Now, create the authentication packet we'll send to the server.
|
||||||
Authentication auth = new Authentication();
|
Authentication auth = new Authentication();
|
||||||
|
@ -94,19 +81,7 @@ class NonSASLAuthentication implements UserAuthentication {
|
||||||
|
|
||||||
auth.setResource(resource);
|
auth.setResource(resource);
|
||||||
|
|
||||||
collector = connection.createPacketCollector(new PacketIDFilter(auth.getPacketID()));
|
Packet response = connection.createPacketCollectorAndSend(auth).nextResultOrThrow();
|
||||||
// Send the packet.
|
|
||||||
connection.sendPacket(auth);
|
|
||||||
// Wait up to a certain number of seconds for a response from the server.
|
|
||||||
response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("Authentication failed.");
|
|
||||||
}
|
|
||||||
else if (response.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
// We're done with the collector, so explicitly cancel it.
|
|
||||||
collector.cancel();
|
|
||||||
|
|
||||||
return response.getTo();
|
return response.getTo();
|
||||||
}
|
}
|
||||||
|
@ -115,20 +90,7 @@ class NonSASLAuthentication implements UserAuthentication {
|
||||||
// Create the authentication packet we'll send to the server.
|
// Create the authentication packet we'll send to the server.
|
||||||
Authentication auth = new Authentication();
|
Authentication auth = new Authentication();
|
||||||
|
|
||||||
PacketCollector collector =
|
Packet response = connection.createPacketCollectorAndSend(auth).nextResultOrThrow();
|
||||||
connection.createPacketCollector(new PacketIDFilter(auth.getPacketID()));
|
|
||||||
// Send the packet.
|
|
||||||
connection.sendPacket(auth);
|
|
||||||
// Wait up to a certain number of seconds for a response from the server.
|
|
||||||
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("Anonymous login failed.");
|
|
||||||
}
|
|
||||||
else if (response.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
// We're done with the collector, so explicitly cancel it.
|
|
||||||
collector.cancel();
|
|
||||||
|
|
||||||
if (response.getTo() != null) {
|
if (response.getTo() != null) {
|
||||||
return response.getTo();
|
return response.getTo();
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jivesoftware.smack.filter.PacketFilter;
|
import org.jivesoftware.smack.filter.PacketFilter;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
|
import org.jivesoftware.smack.packet.XMPPError;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a mechanism to collect packets into a result queue that pass a
|
* Provides a mechanism to collect packets into a result queue that pass a
|
||||||
|
@ -105,12 +106,12 @@ public class PacketCollector {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the next available packet. The method call will block (not return)
|
* Returns the next available packet. The method call will block (not return) until a packet is
|
||||||
* until a packet is available.
|
* available.
|
||||||
*
|
*
|
||||||
* @return the next available packet.
|
* @return the next available packet.
|
||||||
*/
|
*/
|
||||||
public Packet nextResult() {
|
public Packet nextResultBlockForever() {
|
||||||
try {
|
try {
|
||||||
return resultQueue.take();
|
return resultQueue.take();
|
||||||
}
|
}
|
||||||
|
@ -119,12 +120,21 @@ public class PacketCollector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the next available packet. The method call will block until the connection's default
|
||||||
|
* timeout has elapsed.
|
||||||
|
*
|
||||||
|
* @return the next availabe packet.
|
||||||
|
*/
|
||||||
|
public Packet nextResult() {
|
||||||
|
return nextResult(connection.getPacketReplyTimeout());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the next available packet. The method call will block (not return)
|
* Returns the next available packet. The method call will block (not return)
|
||||||
* until a packet is available or the <tt>timeout</tt> has elapased. If the
|
* until a packet is available or the <tt>timeout</tt> has elapsed. If the
|
||||||
* timeout elapses without a result, <tt>null</tt> will be returned.
|
* timeout elapses without a result, <tt>null</tt> will be returned.
|
||||||
*
|
*
|
||||||
* @param timeout the amount of time to wait for the next packet (in milleseconds).
|
|
||||||
* @return the next available packet.
|
* @return the next available packet.
|
||||||
*/
|
*/
|
||||||
public Packet nextResult(long timeout) {
|
public Packet nextResult(long timeout) {
|
||||||
|
@ -136,6 +146,41 @@ public class PacketCollector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the next available packet. The method call will block until a packet is available or
|
||||||
|
* the connections reply timeout has elapsed. If the timeout elapses without a result,
|
||||||
|
* <tt>null</tt> will be returned. This method does also cancel the PacketCollector.
|
||||||
|
*
|
||||||
|
* @return the next available packet.
|
||||||
|
* @throws XMPPException
|
||||||
|
*/
|
||||||
|
public Packet nextResultOrThrow() throws XMPPException {
|
||||||
|
return nextResultOrThrow(connection.getPacketReplyTimeout());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the next available packet. The method call will block until a packet is available or
|
||||||
|
* the <tt>timeout</tt> has elapsed. This method does also cancel the PacketCollector.
|
||||||
|
*
|
||||||
|
* @param timeout the amount of time to wait for the next packet (in milleseconds).
|
||||||
|
* @return the next available packet.
|
||||||
|
* @throws XMPPException in case of no response or error response
|
||||||
|
*/
|
||||||
|
public Packet nextResultOrThrow(long timeout) throws XMPPException {
|
||||||
|
Packet result = nextResult(timeout);
|
||||||
|
cancel();
|
||||||
|
if (result == null) {
|
||||||
|
throw new XMPPException(SmackError.NO_RESPONSE_FROM_SERVER);
|
||||||
|
}
|
||||||
|
|
||||||
|
XMPPError xmppError = result.getError();
|
||||||
|
if (xmppError != null) {
|
||||||
|
throw new XMPPException(xmppError);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes a packet to see if it meets the criteria for this packet collector.
|
* Processes a packet to see if it meets the criteria for this packet collector.
|
||||||
* If so, the packet is added to the result queue.
|
* If so, the packet is added to the result queue.
|
||||||
|
|
|
@ -108,7 +108,7 @@ class PacketReader {
|
||||||
// (although this is a rare thing). Therefore, we continue waiting
|
// (although this is a rare thing). Therefore, we continue waiting
|
||||||
// until either a connectionID has been set (and hence a notify was
|
// until either a connectionID has been set (and hence a notify was
|
||||||
// made) or the total wait time has elapsed.
|
// made) or the total wait time has elapsed.
|
||||||
int waitTime = SmackConfiguration.getPacketReplyTimeout();
|
int waitTime = SmackConfiguration.getDefaultPacketReplyTimeout();
|
||||||
wait(3 * waitTime);
|
wait(3 * waitTime);
|
||||||
}
|
}
|
||||||
catch (InterruptedException ie) {
|
catch (InterruptedException ie) {
|
||||||
|
|
|
@ -277,19 +277,7 @@ public class Roster {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rosterPacket.addRosterItem(item);
|
rosterPacket.addRosterItem(item);
|
||||||
// Wait up to a certain number of seconds for a reply from the server.
|
connection.createPacketCollectorAndSend(rosterPacket).nextResultOrThrow();
|
||||||
PacketCollector collector = connection.createPacketCollector(
|
|
||||||
new PacketIDFilter(rosterPacket.getPacketID()));
|
|
||||||
connection.sendPacket(rosterPacket);
|
|
||||||
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from the server.");
|
|
||||||
}
|
|
||||||
// If the server replied with an error, throw an exception.
|
|
||||||
else if (response.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a presence subscription packet and send.
|
// Create a presence subscription packet and send.
|
||||||
Presence presencePacket = new Presence(Presence.Type.subscribe);
|
Presence presencePacket = new Presence(Presence.Type.subscribe);
|
||||||
|
@ -326,18 +314,7 @@ public class Roster {
|
||||||
// Set the item type as REMOVE so that the server will delete the entry
|
// Set the item type as REMOVE so that the server will delete the entry
|
||||||
item.setItemType(RosterPacket.ItemType.remove);
|
item.setItemType(RosterPacket.ItemType.remove);
|
||||||
packet.addRosterItem(item);
|
packet.addRosterItem(item);
|
||||||
PacketCollector collector = connection.createPacketCollector(
|
connection.createPacketCollectorAndSend(packet).nextResultOrThrow();
|
||||||
new PacketIDFilter(packet.getPacketID()));
|
|
||||||
connection.sendPacket(packet);
|
|
||||||
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from the server.");
|
|
||||||
}
|
|
||||||
// If the server replied with an error, throw an exception.
|
|
||||||
else if (response.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -178,15 +178,7 @@ public class RosterGroup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (collector != null) {
|
if (collector != null) {
|
||||||
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
collector.nextResultOrThrow();
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from the server.");
|
|
||||||
}
|
|
||||||
// If the server replied with an error, throw an exception.
|
|
||||||
else if (response.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,15 +212,7 @@ public class RosterGroup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (collector != null) {
|
if (collector != null) {
|
||||||
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
collector.nextResultOrThrow();
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from the server.");
|
|
||||||
}
|
|
||||||
// If the server replied with an error, throw an exception.
|
|
||||||
else if (response.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,7 @@
|
||||||
|
|
||||||
package org.jivesoftware.smack;
|
package org.jivesoftware.smack;
|
||||||
|
|
||||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
|
||||||
import org.jivesoftware.smack.packet.Bind;
|
import org.jivesoftware.smack.packet.Bind;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smack.packet.Session;
|
import org.jivesoftware.smack.packet.Session;
|
||||||
import org.jivesoftware.smack.sasl.*;
|
import org.jivesoftware.smack.sasl.*;
|
||||||
|
@ -443,37 +441,12 @@ public class SASLAuthentication implements UserAuthentication {
|
||||||
Bind bindResource = new Bind();
|
Bind bindResource = new Bind();
|
||||||
bindResource.setResource(resource);
|
bindResource.setResource(resource);
|
||||||
|
|
||||||
PacketCollector collector = connection
|
Bind response = (Bind) connection.createPacketCollectorAndSend(bindResource).nextResultOrThrow();
|
||||||
.createPacketCollector(new PacketIDFilter(bindResource.getPacketID()));
|
|
||||||
// Send the packet
|
|
||||||
connection.sendPacket(bindResource);
|
|
||||||
// Wait up to a certain number of seconds for a response from the server.
|
|
||||||
Bind response = (Bind) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from the server.");
|
|
||||||
}
|
|
||||||
// If the server replied with an error, throw an exception.
|
|
||||||
else if (response.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
String userJID = response.getJid();
|
String userJID = response.getJid();
|
||||||
|
|
||||||
if (sessionSupported) {
|
if (sessionSupported) {
|
||||||
Session session = new Session();
|
Session session = new Session();
|
||||||
collector = connection.createPacketCollector(new PacketIDFilter(session.getPacketID()));
|
connection.createPacketCollectorAndSend(session).nextResultOrThrow();
|
||||||
// Send the packet
|
|
||||||
connection.sendPacket(session);
|
|
||||||
// Wait up to a certain number of seconds for a response from the server.
|
|
||||||
IQ ack = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
collector.cancel();
|
|
||||||
if (ack == null) {
|
|
||||||
throw new XMPPException("No response from the server.");
|
|
||||||
}
|
|
||||||
// If the server replied with an error, throw an exception.
|
|
||||||
else if (ack.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(ack.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return userJID;
|
return userJID;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ public final class SmackConfiguration {
|
||||||
|
|
||||||
private static InputStream configFileStream;
|
private static InputStream configFileStream;
|
||||||
|
|
||||||
private static int packetReplyTimeout = 5000;
|
private static int defaultPacketReplyTimeout = 5000;
|
||||||
private static List<String> defaultMechs = new ArrayList<String>();
|
private static List<String> defaultMechs = new ArrayList<String>();
|
||||||
|
|
||||||
private static boolean localSocks5ProxyEnabled = true;
|
private static boolean localSocks5ProxyEnabled = true;
|
||||||
|
@ -150,14 +150,14 @@ public final class SmackConfiguration {
|
||||||
*
|
*
|
||||||
* @return the milliseconds to wait for a response from the server
|
* @return the milliseconds to wait for a response from the server
|
||||||
*/
|
*/
|
||||||
public static int getPacketReplyTimeout() {
|
public static int getDefaultPacketReplyTimeout() {
|
||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
// The timeout value must be greater than 0 otherwise we will answer the default value
|
// The timeout value must be greater than 0 otherwise we will answer the default value
|
||||||
if (packetReplyTimeout <= 0) {
|
if (defaultPacketReplyTimeout <= 0) {
|
||||||
packetReplyTimeout = 5000;
|
defaultPacketReplyTimeout = 5000;
|
||||||
}
|
}
|
||||||
return packetReplyTimeout;
|
return defaultPacketReplyTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -166,13 +166,13 @@ public final class SmackConfiguration {
|
||||||
*
|
*
|
||||||
* @param timeout the milliseconds to wait for a response from the server
|
* @param timeout the milliseconds to wait for a response from the server
|
||||||
*/
|
*/
|
||||||
public static void setPacketReplyTimeout(int timeout) {
|
public static void setDefaultPacketReplyTimeout(int timeout) {
|
||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
if (timeout <= 0) {
|
if (timeout <= 0) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
packetReplyTimeout = timeout;
|
defaultPacketReplyTimeout = timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -442,8 +442,8 @@ public final class SmackConfiguration {
|
||||||
else if (parser.getName().equals("optionalStartupClasses")) {
|
else if (parser.getName().equals("optionalStartupClasses")) {
|
||||||
parseClassesToLoad(parser, true);
|
parseClassesToLoad(parser, true);
|
||||||
}
|
}
|
||||||
else if (parser.getName().equals("packetReplyTimeout")) {
|
else if (parser.getName().equals("defaultPacketReplyTimeout")) {
|
||||||
packetReplyTimeout = parseIntProperty(parser, packetReplyTimeout);
|
defaultPacketReplyTimeout = parseIntProperty(parser, defaultPacketReplyTimeout);
|
||||||
}
|
}
|
||||||
else if (parser.getName().equals("mechName")) {
|
else if (parser.getName().equals("mechName")) {
|
||||||
defaultMechs.add(parser.nextText());
|
defaultMechs.add(parser.nextText());
|
||||||
|
|
|
@ -367,7 +367,7 @@ public class XMPPConnection extends Connection {
|
||||||
if (!roster.rosterInitialized) {
|
if (!roster.rosterInitialized) {
|
||||||
try {
|
try {
|
||||||
synchronized (roster) {
|
synchronized (roster) {
|
||||||
long waitTime = SmackConfiguration.getPacketReplyTimeout();
|
long waitTime = SmackConfiguration.getDefaultPacketReplyTimeout();
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
while (!roster.rosterInitialized) {
|
while (!roster.rosterInitialized) {
|
||||||
if (waitTime <= 0) {
|
if (waitTime <= 0) {
|
||||||
|
@ -930,7 +930,7 @@ public class XMPPConnection extends Connection {
|
||||||
// Wait until compression is being used or a timeout happened
|
// Wait until compression is being used or a timeout happened
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
try {
|
try {
|
||||||
this.wait(SmackConfiguration.getPacketReplyTimeout() * 5);
|
this.wait(SmackConfiguration.getDefaultPacketReplyTimeout() * 5);
|
||||||
}
|
}
|
||||||
catch (InterruptedException e) {
|
catch (InterruptedException e) {
|
||||||
// Ignore.
|
// Ignore.
|
||||||
|
|
|
@ -1,67 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright the original author or authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.jivesoftware.smack.util;
|
|
||||||
|
|
||||||
import org.jivesoftware.smack.PacketCollector;
|
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
|
||||||
import org.jivesoftware.smack.Connection;
|
|
||||||
import org.jivesoftware.smack.SmackError;
|
|
||||||
import org.jivesoftware.smack.XMPPException;
|
|
||||||
import org.jivesoftware.smack.filter.PacketFilter;
|
|
||||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility class for doing synchronous calls to the server. Provides several
|
|
||||||
* methods for sending a packet to the server and waiting for the reply.
|
|
||||||
*
|
|
||||||
* @author Robin Collier
|
|
||||||
*/
|
|
||||||
final public class SyncPacketSend
|
|
||||||
{
|
|
||||||
private SyncPacketSend()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
static public Packet getReply(Connection connection, Packet packet, long timeout)
|
|
||||||
throws XMPPException
|
|
||||||
{
|
|
||||||
PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID());
|
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
||||||
|
|
||||||
connection.sendPacket(packet);
|
|
||||||
|
|
||||||
// Wait up to a certain number of seconds for a reply.
|
|
||||||
Packet result = response.nextResult(timeout);
|
|
||||||
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (result == null) {
|
|
||||||
throw new XMPPException(SmackError.NO_RESPONSE_FROM_SERVER);
|
|
||||||
}
|
|
||||||
else if (result.getError() != null) {
|
|
||||||
throw new XMPPException(result.getError());
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static public Packet getReply(Connection connection, Packet packet)
|
|
||||||
throws XMPPException
|
|
||||||
{
|
|
||||||
return getReply(connection, packet, SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,8 +2,8 @@
|
||||||
<!-- Smack configuration file. -->
|
<!-- Smack configuration file. -->
|
||||||
<smack>
|
<smack>
|
||||||
|
|
||||||
<!-- Packet reply timeout in milliseconds -->
|
<!-- Default Packet reply timeout in milliseconds -->
|
||||||
<packetReplyTimeout>5000</packetReplyTimeout>
|
<defaultPacketReplyTimeout>5000</defaultPacketReplyTimeout>
|
||||||
|
|
||||||
<!-- Enable/Disable local Socks5 proxy -->
|
<!-- Enable/Disable local Socks5 proxy -->
|
||||||
<localSocks5ProxyEnabled>true</localSocks5ProxyEnabled>
|
<localSocks5ProxyEnabled>true</localSocks5ProxyEnabled>
|
||||||
|
|
|
@ -38,10 +38,10 @@ public class PacketCollectorTest
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert that '0' has rolled off
|
// Assert that '0' has rolled off
|
||||||
assertEquals("1", collector.nextResult().getPacketID());
|
assertEquals("1", collector.nextResultBlockForever().getPacketID());
|
||||||
assertEquals("2", collector.nextResult().getPacketID());
|
assertEquals("2", collector.nextResultBlockForever().getPacketID());
|
||||||
assertEquals("3", collector.nextResult().getPacketID());
|
assertEquals("3", collector.nextResultBlockForever().getPacketID());
|
||||||
assertEquals("4", collector.nextResult().getPacketID());
|
assertEquals("4", collector.nextResultBlockForever().getPacketID());
|
||||||
assertEquals("5", collector.pollResult().getPacketID());
|
assertEquals("5", collector.pollResult().getPacketID());
|
||||||
assertNull(collector.pollResult());
|
assertNull(collector.pollResult());
|
||||||
|
|
||||||
|
@ -51,10 +51,10 @@ public class PacketCollectorTest
|
||||||
collector.processPacket(testPacket);
|
collector.processPacket(testPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals("10", collector.nextResult().getPacketID());
|
assertEquals("10", collector.nextResultBlockForever().getPacketID());
|
||||||
assertEquals("11", collector.nextResult().getPacketID());
|
assertEquals("11", collector.nextResultBlockForever().getPacketID());
|
||||||
assertEquals("12", collector.nextResult().getPacketID());
|
assertEquals("12", collector.nextResultBlockForever().getPacketID());
|
||||||
assertEquals("13", collector.nextResult().getPacketID());
|
assertEquals("13", collector.nextResultBlockForever().getPacketID());
|
||||||
assertEquals("14", collector.pollResult().getPacketID());
|
assertEquals("14", collector.pollResult().getPacketID());
|
||||||
assertNull(collector.pollResult());
|
assertNull(collector.pollResult());
|
||||||
|
|
||||||
|
@ -87,7 +87,8 @@ public class PacketCollectorTest
|
||||||
catch (InterruptedException e)
|
catch (InterruptedException e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
Packet packet = collector.nextResult();
|
@SuppressWarnings("unused")
|
||||||
|
Packet packet = collector.nextResultBlockForever();
|
||||||
// System.out.println(Thread.currentThread().getName() + " packet: " + packet);
|
// System.out.println(Thread.currentThread().getName() + " packet: " + packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class SmackConfigurationTest {
|
||||||
@Test
|
@Test
|
||||||
public void testSmackConfiguration() {
|
public void testSmackConfiguration() {
|
||||||
try {
|
try {
|
||||||
SmackConfiguration.getPacketReplyTimeout();
|
SmackConfiguration.getDefaultPacketReplyTimeout();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
fail("SmackConfiguration threw Throwable");
|
fail("SmackConfiguration threw Throwable");
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,7 @@ import java.util.WeakHashMap;
|
||||||
|
|
||||||
import org.jivesoftware.smack.Connection;
|
import org.jivesoftware.smack.Connection;
|
||||||
import org.jivesoftware.smack.ConnectionCreationListener;
|
import org.jivesoftware.smack.ConnectionCreationListener;
|
||||||
import org.jivesoftware.smack.PacketCollector;
|
|
||||||
import org.jivesoftware.smack.PacketListener;
|
import org.jivesoftware.smack.PacketListener;
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
import org.jivesoftware.smack.filter.PacketIDFilter;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
|
@ -147,43 +145,36 @@ public class CarbonManager {
|
||||||
* @param new_state whether carbons should be enabled or disabled
|
* @param new_state whether carbons should be enabled or disabled
|
||||||
*
|
*
|
||||||
* @return true if the operation was successful
|
* @return true if the operation was successful
|
||||||
|
* @throws XMPPException
|
||||||
*/
|
*/
|
||||||
public boolean setCarbonsEnabled(final boolean new_state) {
|
public void setCarbonsEnabled(final boolean new_state) throws XMPPException {
|
||||||
if (enabled_state == new_state)
|
if (enabled_state == new_state) return;
|
||||||
return true;
|
|
||||||
|
|
||||||
Connection connection = weakRefConnection.get();
|
Connection connection = weakRefConnection.get();
|
||||||
IQ setIQ = carbonsEnabledIQ(new_state);
|
IQ setIQ = carbonsEnabledIQ(new_state);
|
||||||
|
|
||||||
PacketCollector collector =
|
connection.createPacketCollectorAndSend(setIQ).nextResultOrThrow();
|
||||||
connection.createPacketCollector(new PacketIDFilter(setIQ.getPacketID()));
|
|
||||||
connection.sendPacket(setIQ);
|
|
||||||
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
collector.cancel();
|
|
||||||
|
|
||||||
if (result != null && result.getType() == IQ.Type.RESULT) {
|
|
||||||
enabled_state = new_state;
|
enabled_state = new_state;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to enable carbons.
|
* Helper method to enable carbons.
|
||||||
*
|
*
|
||||||
* @return true if the operation was successful
|
* @return true if the operation was successful
|
||||||
|
* @throws XMPPException
|
||||||
*/
|
*/
|
||||||
public boolean enableCarbons() {
|
public void enableCarbons() throws XMPPException {
|
||||||
return setCarbonsEnabled(true);
|
setCarbonsEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to disable carbons.
|
* Helper method to disable carbons.
|
||||||
*
|
*
|
||||||
* @return true if the operation was successful
|
* @return true if the operation was successful
|
||||||
|
* @throws XMPPException
|
||||||
*/
|
*/
|
||||||
public boolean disableCarbons() {
|
public void disableCarbons() throws XMPPException {
|
||||||
return setCarbonsEnabled(false);
|
setCarbonsEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -30,7 +30,6 @@ import org.jivesoftware.smack.ConnectionCreationListener;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.XMPPError;
|
import org.jivesoftware.smack.packet.XMPPError;
|
||||||
import org.jivesoftware.smack.util.SyncPacketSend;
|
|
||||||
import org.jivesoftware.smackx.bytestreams.BytestreamListener;
|
import org.jivesoftware.smackx.bytestreams.BytestreamListener;
|
||||||
import org.jivesoftware.smackx.bytestreams.BytestreamManager;
|
import org.jivesoftware.smackx.bytestreams.BytestreamManager;
|
||||||
import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
|
import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
|
||||||
|
@ -428,7 +427,7 @@ public class InBandBytestreamManager implements BytestreamManager {
|
||||||
byteStreamRequest.setTo(targetJID);
|
byteStreamRequest.setTo(targetJID);
|
||||||
|
|
||||||
// sending packet will throw exception on timeout or error reply
|
// sending packet will throw exception on timeout or error reply
|
||||||
SyncPacketSend.getReply(this.connection, byteStreamRequest);
|
connection.createPacketCollectorAndSend(byteStreamRequest).nextResultOrThrow();
|
||||||
|
|
||||||
InBandBytestreamSession inBandBytestreamSession = new InBandBytestreamSession(
|
InBandBytestreamSession inBandBytestreamSession = new InBandBytestreamSession(
|
||||||
this.connection, byteStreamRequest, targetJID);
|
this.connection, byteStreamRequest, targetJID);
|
||||||
|
|
|
@ -36,7 +36,6 @@ import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smack.packet.PacketExtension;
|
import org.jivesoftware.smack.packet.PacketExtension;
|
||||||
import org.jivesoftware.smack.packet.XMPPError;
|
import org.jivesoftware.smack.packet.XMPPError;
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
import org.jivesoftware.smack.util.SyncPacketSend;
|
|
||||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||||
import org.jivesoftware.smackx.bytestreams.ibb.packet.Close;
|
import org.jivesoftware.smackx.bytestreams.ibb.packet.Close;
|
||||||
import org.jivesoftware.smackx.bytestreams.ibb.packet.Data;
|
import org.jivesoftware.smackx.bytestreams.ibb.packet.Data;
|
||||||
|
@ -210,7 +209,7 @@ public class InBandBytestreamSession implements BytestreamSession {
|
||||||
Close close = new Close(this.byteStreamRequest.getSessionID());
|
Close close = new Close(this.byteStreamRequest.getSessionID());
|
||||||
close.setTo(this.remoteJID);
|
close.setTo(this.remoteJID);
|
||||||
try {
|
try {
|
||||||
SyncPacketSend.getReply(this.connection, close);
|
connection.createPacketCollectorAndSend(close).nextResultOrThrow();
|
||||||
}
|
}
|
||||||
catch (XMPPException e) {
|
catch (XMPPException e) {
|
||||||
throw new IOException("Error while closing stream: " + e.getMessage());
|
throw new IOException("Error while closing stream: " + e.getMessage());
|
||||||
|
@ -763,7 +762,7 @@ public class InBandBytestreamSession implements BytestreamSession {
|
||||||
iq.setTo(remoteJID);
|
iq.setTo(remoteJID);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SyncPacketSend.getReply(connection, iq);
|
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||||
}
|
}
|
||||||
catch (XMPPException e) {
|
catch (XMPPException e) {
|
||||||
// close session unless it is already closed
|
// close session unless it is already closed
|
||||||
|
|
|
@ -36,7 +36,6 @@ import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smack.packet.XMPPError;
|
import org.jivesoftware.smack.packet.XMPPError;
|
||||||
import org.jivesoftware.smack.util.SyncPacketSend;
|
|
||||||
import org.jivesoftware.smackx.bytestreams.BytestreamListener;
|
import org.jivesoftware.smackx.bytestreams.BytestreamListener;
|
||||||
import org.jivesoftware.smackx.bytestreams.BytestreamManager;
|
import org.jivesoftware.smackx.bytestreams.BytestreamManager;
|
||||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||||
|
@ -481,7 +480,7 @@ public final class Socks5BytestreamManager implements BytestreamManager {
|
||||||
Bytestream initiation = createBytestreamInitiation(sessionID, targetJID, streamHosts);
|
Bytestream initiation = createBytestreamInitiation(sessionID, targetJID, streamHosts);
|
||||||
|
|
||||||
// send initiation packet
|
// send initiation packet
|
||||||
Packet response = SyncPacketSend.getReply(this.connection, initiation,
|
Packet response = connection.createPacketCollectorAndSend(initiation).nextResultOrThrow(
|
||||||
getTargetResponseTimeout());
|
getTargetResponseTimeout());
|
||||||
|
|
||||||
// extract used stream host from response
|
// extract used stream host from response
|
||||||
|
@ -612,8 +611,8 @@ public final class Socks5BytestreamManager implements BytestreamManager {
|
||||||
for (String proxy : proxies) {
|
for (String proxy : proxies) {
|
||||||
Bytestream streamHostRequest = createStreamHostRequest(proxy);
|
Bytestream streamHostRequest = createStreamHostRequest(proxy);
|
||||||
try {
|
try {
|
||||||
Bytestream response = (Bytestream) SyncPacketSend.getReply(this.connection,
|
Bytestream response = (Bytestream) connection.createPacketCollectorAndSend(
|
||||||
streamHostRequest);
|
streamHostRequest).nextResultOrThrow();
|
||||||
streamHosts.addAll(response.getStreamHosts());
|
streamHosts.addAll(response.getStreamHosts());
|
||||||
}
|
}
|
||||||
catch (XMPPException e) {
|
catch (XMPPException e) {
|
||||||
|
|
|
@ -23,7 +23,6 @@ import java.util.concurrent.TimeoutException;
|
||||||
import org.jivesoftware.smack.Connection;
|
import org.jivesoftware.smack.Connection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.util.SyncPacketSend;
|
|
||||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost;
|
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost;
|
||||||
|
|
||||||
|
@ -97,8 +96,8 @@ class Socks5ClientForInitiator extends Socks5Client {
|
||||||
*/
|
*/
|
||||||
private void activate() throws XMPPException {
|
private void activate() throws XMPPException {
|
||||||
Bytestream activate = createStreamHostActivation();
|
Bytestream activate = createStreamHostActivation();
|
||||||
// if activation fails #getReply throws an exception
|
// if activation fails #nextResultOrThrow() throws an exception
|
||||||
SyncPacketSend.getReply(this.connection, activate);
|
connection.createPacketCollectorAndSend(activate).nextResultOrThrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -17,13 +17,10 @@
|
||||||
|
|
||||||
package org.jivesoftware.smackx.commands;
|
package org.jivesoftware.smackx.commands;
|
||||||
|
|
||||||
import org.jivesoftware.smack.PacketCollector;
|
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
import org.jivesoftware.smack.SmackConfiguration;
|
||||||
import org.jivesoftware.smack.Connection;
|
import org.jivesoftware.smack.Connection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
|
||||||
import org.jivesoftware.smackx.commands.packet.AdHocCommandData;
|
import org.jivesoftware.smackx.commands.packet.AdHocCommandData;
|
||||||
import org.jivesoftware.smackx.xdata.Form;
|
import org.jivesoftware.smackx.xdata.Form;
|
||||||
|
|
||||||
|
@ -79,7 +76,7 @@ public class RemoteCommand extends AdHocCommand {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
this.jid = jid;
|
this.jid = jid;
|
||||||
this.setNode(node);
|
this.setNode(node);
|
||||||
this.packetReplyTimeout = SmackConfiguration.getPacketReplyTimeout();
|
this.packetReplyTimeout = SmackConfiguration.getDefaultPacketReplyTimeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -148,23 +145,9 @@ public class RemoteCommand extends AdHocCommand {
|
||||||
data.setForm(form.getDataFormToSend());
|
data.setForm(form.getDataFormToSend());
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollector(
|
AdHocCommandData responseData = (AdHocCommandData) connection.createPacketCollectorAndSend(
|
||||||
new PacketIDFilter(data.getPacketID()));
|
data).nextResultOrThrow();
|
||||||
|
|
||||||
connection.sendPacket(data);
|
|
||||||
|
|
||||||
Packet response = collector.nextResult(timeout);
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
|
|
||||||
AdHocCommandData responseData = (AdHocCommandData) response;
|
|
||||||
this.sessionID = responseData.getSessionID();
|
this.sessionID = responseData.getSessionID();
|
||||||
super.setData(responseData);
|
super.setData(responseData);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ package org.jivesoftware.smackx.disco;
|
||||||
|
|
||||||
import org.jivesoftware.smack.*;
|
import org.jivesoftware.smack.*;
|
||||||
import org.jivesoftware.smack.filter.PacketFilter;
|
import org.jivesoftware.smack.filter.PacketFilter;
|
||||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
|
||||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
|
@ -232,6 +231,7 @@ public class ServiceDiscoveryManager {
|
||||||
* @param type the type of client that will be returned when asked for the client identity in a
|
* @param type the type of client that will be returned when asked for the client identity in a
|
||||||
* disco request.
|
* disco request.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void setIdentityType(String type) {
|
public void setIdentityType(String type) {
|
||||||
identity.setType(type);
|
identity.setType(type);
|
||||||
renewEntityCapsVersion();
|
renewEntityCapsVersion();
|
||||||
|
@ -541,22 +541,8 @@ public class ServiceDiscoveryManager {
|
||||||
disco.setTo(entityID);
|
disco.setTo(entityID);
|
||||||
disco.setNode(node);
|
disco.setNode(node);
|
||||||
|
|
||||||
// Create a packet collector to listen for a response.
|
Packet result = connection.createPacketCollectorAndSend(disco).nextResultOrThrow();
|
||||||
PacketCollector collector =
|
|
||||||
connection.createPacketCollector(new PacketIDFilter(disco.getPacketID()));
|
|
||||||
|
|
||||||
connection.sendPacket(disco);
|
|
||||||
|
|
||||||
// Wait up to 5 seconds for a result.
|
|
||||||
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
collector.cancel();
|
|
||||||
if (result == null) {
|
|
||||||
throw new XMPPException("No response from the server.");
|
|
||||||
}
|
|
||||||
if (result.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(result.getError());
|
|
||||||
}
|
|
||||||
return (DiscoverInfo) result;
|
return (DiscoverInfo) result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -591,22 +577,7 @@ public class ServiceDiscoveryManager {
|
||||||
disco.setTo(entityID);
|
disco.setTo(entityID);
|
||||||
disco.setNode(node);
|
disco.setNode(node);
|
||||||
|
|
||||||
// Create a packet collector to listen for a response.
|
Packet result = connection.createPacketCollectorAndSend(disco).nextResultOrThrow();
|
||||||
PacketCollector collector =
|
|
||||||
connection.createPacketCollector(new PacketIDFilter(disco.getPacketID()));
|
|
||||||
|
|
||||||
connection.sendPacket(disco);
|
|
||||||
|
|
||||||
// Wait up to 5 seconds for a result.
|
|
||||||
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
collector.cancel();
|
|
||||||
if (result == null) {
|
|
||||||
throw new XMPPException("No response from the server.");
|
|
||||||
}
|
|
||||||
if (result.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(result.getError());
|
|
||||||
}
|
|
||||||
return (DiscoverItems) result;
|
return (DiscoverItems) result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -673,22 +644,7 @@ public class ServiceDiscoveryManager {
|
||||||
discoverItems.setTo(entityID);
|
discoverItems.setTo(entityID);
|
||||||
discoverItems.setNode(node);
|
discoverItems.setNode(node);
|
||||||
|
|
||||||
// Create a packet collector to listen for a response.
|
connection.createPacketCollectorAndSend(discoverItems).nextResultOrThrow();
|
||||||
PacketCollector collector =
|
|
||||||
connection.createPacketCollector(new PacketIDFilter(discoverItems.getPacketID()));
|
|
||||||
|
|
||||||
connection.sendPacket(discoverItems);
|
|
||||||
|
|
||||||
// Wait up to 5 seconds for a result.
|
|
||||||
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
collector.cancel();
|
|
||||||
if (result == null) {
|
|
||||||
throw new XMPPException("No response from the server.");
|
|
||||||
}
|
|
||||||
if (result.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(result.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
package org.jivesoftware.smackx.filetransfer;
|
package org.jivesoftware.smackx.filetransfer;
|
||||||
|
|
||||||
import org.jivesoftware.smack.PacketCollector;
|
import org.jivesoftware.smack.PacketCollector;
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
|
||||||
import org.jivesoftware.smack.Connection;
|
import org.jivesoftware.smack.Connection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.filter.OrFilter;
|
import org.jivesoftware.smack.filter.OrFilter;
|
||||||
|
@ -171,8 +170,7 @@ public class FaultTolerantNegotiator extends StreamNegotiator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream call() throws Exception {
|
public InputStream call() throws Exception {
|
||||||
Packet streamInitiation = collector.nextResult(
|
Packet streamInitiation = collector.nextResult();
|
||||||
SmackConfiguration.getPacketReplyTimeout() * 2);
|
|
||||||
if (streamInitiation == null) {
|
if (streamInitiation == null) {
|
||||||
throw new XMPPException("No response from remote client");
|
throw new XMPPException("No response from remote client");
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
package org.jivesoftware.smackx.filetransfer;
|
package org.jivesoftware.smackx.filetransfer;
|
||||||
|
|
||||||
import org.jivesoftware.smack.PacketCollector;
|
import org.jivesoftware.smack.PacketCollector;
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
|
||||||
import org.jivesoftware.smack.Connection;
|
import org.jivesoftware.smack.Connection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.filter.PacketFilter;
|
import org.jivesoftware.smack.filter.PacketFilter;
|
||||||
|
@ -87,8 +86,7 @@ public abstract class StreamNegotiator {
|
||||||
.createPacketCollector(getInitiationPacketFilter(initiation.getFrom(), initiation.getSessionID()));
|
.createPacketCollector(getInitiationPacketFilter(initiation.getFrom(), initiation.getSessionID()));
|
||||||
connection.sendPacket(response);
|
connection.sendPacket(response);
|
||||||
|
|
||||||
Packet streamMethodInitiation = collector
|
Packet streamMethodInitiation = collector.nextResult();
|
||||||
.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
collector.cancel();
|
collector.cancel();
|
||||||
if (streamMethodInitiation == null) {
|
if (streamMethodInitiation == null) {
|
||||||
throw new XMPPException("No response from file transfer initiator");
|
throw new XMPPException("No response from file transfer initiator");
|
||||||
|
|
|
@ -19,13 +19,10 @@ package org.jivesoftware.smackx.iqlast;
|
||||||
|
|
||||||
import org.jivesoftware.smack.Connection;
|
import org.jivesoftware.smack.Connection;
|
||||||
import org.jivesoftware.smack.ConnectionCreationListener;
|
import org.jivesoftware.smack.ConnectionCreationListener;
|
||||||
import org.jivesoftware.smack.PacketCollector;
|
|
||||||
import org.jivesoftware.smack.PacketListener;
|
import org.jivesoftware.smack.PacketListener;
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.filter.AndFilter;
|
import org.jivesoftware.smack.filter.AndFilter;
|
||||||
import org.jivesoftware.smack.filter.IQTypeFilter;
|
import org.jivesoftware.smack.filter.IQTypeFilter;
|
||||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
|
||||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.Message;
|
||||||
|
@ -199,19 +196,7 @@ public class LastActivityManager {
|
||||||
LastActivity activity = new LastActivity();
|
LastActivity activity = new LastActivity();
|
||||||
activity.setTo(jid);
|
activity.setTo(jid);
|
||||||
|
|
||||||
PacketCollector collector = con.createPacketCollector(new PacketIDFilter(activity.getPacketID()));
|
LastActivity response = (LastActivity) con.createPacketCollectorAndSend(activity).nextResultOrThrow();
|
||||||
con.sendPacket(activity);
|
|
||||||
|
|
||||||
LastActivity response = (LastActivity) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,8 @@ package org.jivesoftware.smackx.iqlast.packet;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.jivesoftware.smack.PacketCollector;
|
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
|
||||||
import org.jivesoftware.smack.Connection;
|
import org.jivesoftware.smack.Connection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.provider.IQProvider;
|
import org.jivesoftware.smack.provider.IQProvider;
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
|
@ -143,19 +140,7 @@ public class LastActivity extends IQ {
|
||||||
jid = StringUtils.parseBareAddress(jid);
|
jid = StringUtils.parseBareAddress(jid);
|
||||||
activity.setTo(jid);
|
activity.setTo(jid);
|
||||||
|
|
||||||
PacketCollector collector = con.createPacketCollector(new PacketIDFilter(activity.getPacketID()));
|
LastActivity response = (LastActivity) con.createPacketCollectorAndSend(activity).nextResultOrThrow();
|
||||||
con.sendPacket(activity);
|
|
||||||
|
|
||||||
LastActivity response = (LastActivity) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,11 +17,8 @@
|
||||||
|
|
||||||
package org.jivesoftware.smackx.iqprivate;
|
package org.jivesoftware.smackx.iqprivate;
|
||||||
|
|
||||||
import org.jivesoftware.smack.PacketCollector;
|
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
|
||||||
import org.jivesoftware.smack.Connection;
|
import org.jivesoftware.smack.Connection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.provider.IQProvider;
|
import org.jivesoftware.smack.provider.IQProvider;
|
||||||
import org.jivesoftware.smackx.iqprivate.packet.DefaultPrivateData;
|
import org.jivesoftware.smackx.iqprivate.packet.DefaultPrivateData;
|
||||||
|
@ -191,25 +188,9 @@ public class PrivateDataManager {
|
||||||
privateDataGet.setTo(user);
|
privateDataGet.setTo(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup a listener for the reply to the set operation.
|
PrivateDataResult response = (PrivateDataResult) connection.createPacketCollectorAndSend(
|
||||||
String packetID = privateDataGet.getPacketID();
|
privateDataGet).nextResultOrThrow();
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(packetID));
|
return response.getPrivateData();
|
||||||
|
|
||||||
// Send the private data.
|
|
||||||
connection.sendPacket(privateDataGet);
|
|
||||||
|
|
||||||
// Wait up to five seconds for a response from the server.
|
|
||||||
IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from the server.");
|
|
||||||
}
|
|
||||||
// If the server replied with an error, throw an exception.
|
|
||||||
else if (response.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return ((PrivateDataResult)response).getPrivateData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -237,24 +218,7 @@ public class PrivateDataManager {
|
||||||
privateDataSet.setTo(user);
|
privateDataSet.setTo(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup a listener for the reply to the set operation.
|
connection.createPacketCollectorAndSend(privateDataSet).nextResultOrThrow();
|
||||||
String packetID = privateDataSet.getPacketID();
|
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(packetID));
|
|
||||||
|
|
||||||
// Send the private data.
|
|
||||||
connection.sendPacket(privateDataSet);
|
|
||||||
|
|
||||||
// Wait up to five seconds for a response from the server.
|
|
||||||
IQ response = (IQ)collector.nextResult(5000);
|
|
||||||
// Stop queuing results
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from the server.");
|
|
||||||
}
|
|
||||||
// If the server replied with an error, throw an exception.
|
|
||||||
else if (response.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -47,7 +47,6 @@ import org.jivesoftware.smack.filter.FromMatchesFilter;
|
||||||
import org.jivesoftware.smack.filter.MessageTypeFilter;
|
import org.jivesoftware.smack.filter.MessageTypeFilter;
|
||||||
import org.jivesoftware.smack.filter.PacketExtensionFilter;
|
import org.jivesoftware.smack.filter.PacketExtensionFilter;
|
||||||
import org.jivesoftware.smack.filter.PacketFilter;
|
import org.jivesoftware.smack.filter.PacketFilter;
|
||||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
|
||||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.Message;
|
||||||
|
@ -355,17 +354,8 @@ public class MultiUserChat {
|
||||||
// Send create & join packet.
|
// Send create & join packet.
|
||||||
connection.sendPacket(joinPresence);
|
connection.sendPacket(joinPresence);
|
||||||
// Wait up to a certain number of seconds for a reply.
|
// Wait up to a certain number of seconds for a reply.
|
||||||
Presence presence =
|
Presence presence = (Presence) response.nextResultOrThrow();
|
||||||
(Presence) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (presence == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (presence.getError() != null) {
|
|
||||||
throw new XMPPException(presence.getError());
|
|
||||||
}
|
|
||||||
// Whether the room existed before or was created, the user has joined the room
|
// Whether the room existed before or was created, the user has joined the room
|
||||||
this.nickname = nickname;
|
this.nickname = nickname;
|
||||||
joined = true;
|
joined = true;
|
||||||
|
@ -400,7 +390,7 @@ public class MultiUserChat {
|
||||||
* 409 error can occur if someone is already in the group chat with the same nickname.
|
* 409 error can occur if someone is already in the group chat with the same nickname.
|
||||||
*/
|
*/
|
||||||
public void join(String nickname) throws XMPPException {
|
public void join(String nickname) throws XMPPException {
|
||||||
join(nickname, null, null, SmackConfiguration.getPacketReplyTimeout());
|
join(nickname, null, null, SmackConfiguration.getDefaultPacketReplyTimeout());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -423,7 +413,7 @@ public class MultiUserChat {
|
||||||
* 409 error can occur if someone is already in the group chat with the same nickname.
|
* 409 error can occur if someone is already in the group chat with the same nickname.
|
||||||
*/
|
*/
|
||||||
public void join(String nickname, String password) throws XMPPException {
|
public void join(String nickname, String password) throws XMPPException {
|
||||||
join(nickname, password, null, SmackConfiguration.getPacketReplyTimeout());
|
join(nickname, password, null, SmackConfiguration.getDefaultPacketReplyTimeout());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -490,27 +480,13 @@ public class MultiUserChat {
|
||||||
new FromMatchesFilter(room + "/" + nickname),
|
new FromMatchesFilter(room + "/" + nickname),
|
||||||
new PacketTypeFilter(Presence.class));
|
new PacketTypeFilter(Presence.class));
|
||||||
PacketCollector response = null;
|
PacketCollector response = null;
|
||||||
Presence presence;
|
|
||||||
try {
|
|
||||||
response = connection.createPacketCollector(responseFilter);
|
response = connection.createPacketCollector(responseFilter);
|
||||||
// Send join packet.
|
// Send join packet.
|
||||||
connection.sendPacket(joinPresence);
|
connection.sendPacket(joinPresence);
|
||||||
// Wait up to a certain number of seconds for a reply.
|
// Wait up to a certain number of seconds for a reply.
|
||||||
presence = (Presence) response.nextResult(timeout);
|
response.nextResultOrThrow(timeout);
|
||||||
}
|
|
||||||
finally {
|
|
||||||
// Stop queuing results
|
|
||||||
if (response != null) {
|
|
||||||
response.cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (presence == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (presence.getError() != null) {
|
|
||||||
throw new XMPPException(presence.getError());
|
|
||||||
}
|
|
||||||
this.nickname = nickname;
|
this.nickname = nickname;
|
||||||
joined = true;
|
joined = true;
|
||||||
userHasJoined();
|
userHasJoined();
|
||||||
|
@ -564,22 +540,7 @@ public class MultiUserChat {
|
||||||
iq.setTo(room);
|
iq.setTo(room);
|
||||||
iq.setType(IQ.Type.GET);
|
iq.setType(IQ.Type.GET);
|
||||||
|
|
||||||
// Filter packets looking for an answer from the server.
|
IQ answer = (IQ) connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||||
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
||||||
// Request the configuration form to the server.
|
|
||||||
connection.sendPacket(iq);
|
|
||||||
// Wait up to a certain number of seconds for a reply.
|
|
||||||
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (answer == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (answer.getError() != null) {
|
|
||||||
throw new XMPPException(answer.getError());
|
|
||||||
}
|
|
||||||
return Form.getFormFrom(answer);
|
return Form.getFormFrom(answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,22 +558,7 @@ public class MultiUserChat {
|
||||||
iq.setType(IQ.Type.SET);
|
iq.setType(IQ.Type.SET);
|
||||||
iq.addExtension(form.getDataFormToSend());
|
iq.addExtension(form.getDataFormToSend());
|
||||||
|
|
||||||
// Filter packets looking for an answer from the server.
|
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||||
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
||||||
// Send the completed configuration form to the server.
|
|
||||||
connection.sendPacket(iq);
|
|
||||||
// Wait up to a certain number of seconds for a reply.
|
|
||||||
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (answer == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (answer.getError() != null) {
|
|
||||||
throw new XMPPException(answer.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -634,18 +580,7 @@ public class MultiUserChat {
|
||||||
reg.setType(IQ.Type.GET);
|
reg.setType(IQ.Type.GET);
|
||||||
reg.setTo(room);
|
reg.setTo(room);
|
||||||
|
|
||||||
PacketFilter filter =
|
IQ result = (IQ) connection.createPacketCollectorAndSend(reg).nextResultOrThrow();
|
||||||
new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
|
|
||||||
PacketCollector collector = connection.createPacketCollector(filter);
|
|
||||||
connection.sendPacket(reg);
|
|
||||||
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
collector.cancel();
|
|
||||||
if (result == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (result.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(result.getError());
|
|
||||||
}
|
|
||||||
return Form.getFormFrom(result);
|
return Form.getFormFrom(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -669,18 +604,7 @@ public class MultiUserChat {
|
||||||
reg.setTo(room);
|
reg.setTo(room);
|
||||||
reg.addExtension(form.getDataFormToSend());
|
reg.addExtension(form.getDataFormToSend());
|
||||||
|
|
||||||
PacketFilter filter =
|
connection.createPacketCollectorAndSend(reg).nextResultOrThrow();
|
||||||
new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
|
|
||||||
PacketCollector collector = connection.createPacketCollector(filter);
|
|
||||||
connection.sendPacket(reg);
|
|
||||||
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
collector.cancel();
|
|
||||||
if (result == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (result.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(result.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -706,22 +630,8 @@ public class MultiUserChat {
|
||||||
destroy.setJid(alternateJID);
|
destroy.setJid(alternateJID);
|
||||||
iq.setDestroy(destroy);
|
iq.setDestroy(destroy);
|
||||||
|
|
||||||
// Wait for a presence packet back from the server.
|
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||||
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
||||||
// Send the room destruction request.
|
|
||||||
connection.sendPacket(iq);
|
|
||||||
// Wait up to a certain number of seconds for a reply.
|
|
||||||
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (answer == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (answer.getError() != null) {
|
|
||||||
throw new XMPPException(answer.getError());
|
|
||||||
}
|
|
||||||
// Reset occupant information.
|
// Reset occupant information.
|
||||||
occupantsMap.clear();
|
occupantsMap.clear();
|
||||||
nickname = null;
|
nickname = null;
|
||||||
|
@ -1013,18 +923,10 @@ public class MultiUserChat {
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
PacketCollector response = connection.createPacketCollector(responseFilter);
|
||||||
// Send join packet.
|
// Send join packet.
|
||||||
connection.sendPacket(joinPresence);
|
connection.sendPacket(joinPresence);
|
||||||
// Wait up to a certain number of seconds for a reply.
|
// Wait up to a certain number of seconds for a reply. If there is a negative reply, an
|
||||||
Presence presence =
|
// exception will be thrown
|
||||||
(Presence) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
response.nextResultOrThrow();
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (presence == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (presence.getError() != null) {
|
|
||||||
throw new XMPPException(presence.getError());
|
|
||||||
}
|
|
||||||
this.nickname = nickname;
|
this.nickname = nickname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1385,22 +1287,7 @@ public class MultiUserChat {
|
||||||
item.setJid(jid);
|
item.setJid(jid);
|
||||||
iq.addItem(item);
|
iq.addItem(item);
|
||||||
|
|
||||||
// Wait for a response packet back from the server.
|
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||||
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
||||||
// Send the change request to the server.
|
|
||||||
connection.sendPacket(iq);
|
|
||||||
// Wait up to a certain number of seconds for a reply.
|
|
||||||
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (answer == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (answer.getError() != null) {
|
|
||||||
throw new XMPPException(answer.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeAffiliationByOwner(Collection<String> jids, String affiliation)
|
private void changeAffiliationByOwner(Collection<String> jids, String affiliation)
|
||||||
|
@ -1415,22 +1302,7 @@ public class MultiUserChat {
|
||||||
iq.addItem(item);
|
iq.addItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for a response packet back from the server.
|
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||||
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
||||||
// Send the change request to the server.
|
|
||||||
connection.sendPacket(iq);
|
|
||||||
// Wait up to a certain number of seconds for a reply.
|
|
||||||
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (answer == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (answer.getError() != null) {
|
|
||||||
throw new XMPPException(answer.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1452,22 +1324,7 @@ public class MultiUserChat {
|
||||||
item.setReason(reason);
|
item.setReason(reason);
|
||||||
iq.addItem(item);
|
iq.addItem(item);
|
||||||
|
|
||||||
// Wait for a response packet back from the server.
|
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||||
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
||||||
// Send the change request to the server.
|
|
||||||
connection.sendPacket(iq);
|
|
||||||
// Wait up to a certain number of seconds for a reply.
|
|
||||||
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (answer == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (answer.getError() != null) {
|
|
||||||
throw new XMPPException(answer.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeAffiliationByAdmin(Collection<String> jids, String affiliation)
|
private void changeAffiliationByAdmin(Collection<String> jids, String affiliation)
|
||||||
|
@ -1482,22 +1339,7 @@ public class MultiUserChat {
|
||||||
iq.addItem(item);
|
iq.addItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for a response packet back from the server.
|
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||||
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
||||||
// Send the change request to the server.
|
|
||||||
connection.sendPacket(iq);
|
|
||||||
// Wait up to a certain number of seconds for a reply.
|
|
||||||
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (answer == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (answer.getError() != null) {
|
|
||||||
throw new XMPPException(answer.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeRole(String nickname, String role, String reason) throws XMPPException {
|
private void changeRole(String nickname, String role, String reason) throws XMPPException {
|
||||||
|
@ -1510,22 +1352,7 @@ public class MultiUserChat {
|
||||||
item.setReason(reason);
|
item.setReason(reason);
|
||||||
iq.addItem(item);
|
iq.addItem(item);
|
||||||
|
|
||||||
// Wait for a response packet back from the server.
|
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||||
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
||||||
// Send the change request to the server.
|
|
||||||
connection.sendPacket(iq);
|
|
||||||
// Wait up to a certain number of seconds for a reply.
|
|
||||||
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (answer == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (answer.getError() != null) {
|
|
||||||
throw new XMPPException(answer.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeRole(Collection<String> nicknames, String role) throws XMPPException {
|
private void changeRole(Collection<String> nicknames, String role) throws XMPPException {
|
||||||
|
@ -1539,22 +1366,7 @@ public class MultiUserChat {
|
||||||
iq.addItem(item);
|
iq.addItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for a response packet back from the server.
|
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||||
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
||||||
// Send the change request to the server.
|
|
||||||
connection.sendPacket(iq);
|
|
||||||
// Wait up to a certain number of seconds for a reply.
|
|
||||||
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (answer == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (answer.getError() != null) {
|
|
||||||
throw new XMPPException(answer.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1703,22 +1515,8 @@ public class MultiUserChat {
|
||||||
MUCOwner.Item item = new MUCOwner.Item(affiliation);
|
MUCOwner.Item item = new MUCOwner.Item(affiliation);
|
||||||
iq.addItem(item);
|
iq.addItem(item);
|
||||||
|
|
||||||
// Wait for a response packet back from the server.
|
MUCOwner answer = (MUCOwner) connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||||
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
||||||
// Send the request to the server.
|
|
||||||
connection.sendPacket(iq);
|
|
||||||
// Wait up to a certain number of seconds for a reply.
|
|
||||||
MUCOwner answer = (MUCOwner) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (answer == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (answer.getError() != null) {
|
|
||||||
throw new XMPPException(answer.getError());
|
|
||||||
}
|
|
||||||
// Get the list of affiliates from the server's answer
|
// Get the list of affiliates from the server's answer
|
||||||
List<Affiliate> affiliates = new ArrayList<Affiliate>();
|
List<Affiliate> affiliates = new ArrayList<Affiliate>();
|
||||||
for (Iterator<MUCOwner.Item> it = answer.getItems(); it.hasNext();) {
|
for (Iterator<MUCOwner.Item> it = answer.getItems(); it.hasNext();) {
|
||||||
|
@ -1744,22 +1542,8 @@ public class MultiUserChat {
|
||||||
MUCAdmin.Item item = new MUCAdmin.Item(affiliation, null);
|
MUCAdmin.Item item = new MUCAdmin.Item(affiliation, null);
|
||||||
iq.addItem(item);
|
iq.addItem(item);
|
||||||
|
|
||||||
// Wait for a response packet back from the server.
|
MUCAdmin answer = (MUCAdmin) connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||||
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
||||||
// Send the request to the server.
|
|
||||||
connection.sendPacket(iq);
|
|
||||||
// Wait up to a certain number of seconds for a reply.
|
|
||||||
MUCAdmin answer = (MUCAdmin) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (answer == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (answer.getError() != null) {
|
|
||||||
throw new XMPPException(answer.getError());
|
|
||||||
}
|
|
||||||
// Get the list of affiliates from the server's answer
|
// Get the list of affiliates from the server's answer
|
||||||
List<Affiliate> affiliates = new ArrayList<Affiliate>();
|
List<Affiliate> affiliates = new ArrayList<Affiliate>();
|
||||||
for (Iterator<MUCAdmin.Item> it = answer.getItems(); it.hasNext();) {
|
for (Iterator<MUCAdmin.Item> it = answer.getItems(); it.hasNext();) {
|
||||||
|
@ -1806,22 +1590,7 @@ public class MultiUserChat {
|
||||||
MUCAdmin.Item item = new MUCAdmin.Item(null, role);
|
MUCAdmin.Item item = new MUCAdmin.Item(null, role);
|
||||||
iq.addItem(item);
|
iq.addItem(item);
|
||||||
|
|
||||||
// Wait for a response packet back from the server.
|
MUCAdmin answer = (MUCAdmin) connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||||
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
|
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
||||||
// Send the request to the server.
|
|
||||||
connection.sendPacket(iq);
|
|
||||||
// Wait up to a certain number of seconds for a reply.
|
|
||||||
MUCAdmin answer = (MUCAdmin) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (answer == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (answer.getError() != null) {
|
|
||||||
throw new XMPPException(answer.getError());
|
|
||||||
}
|
|
||||||
// Get the list of participants from the server's answer
|
// Get the list of participants from the server's answer
|
||||||
List<Occupant> participants = new ArrayList<Occupant>();
|
List<Occupant> participants = new ArrayList<Occupant>();
|
||||||
for (Iterator<MUCAdmin.Item> it = answer.getItems(); it.hasNext();) {
|
for (Iterator<MUCAdmin.Item> it = answer.getItems(); it.hasNext();) {
|
||||||
|
@ -1968,17 +1737,7 @@ public class MultiUserChat {
|
||||||
// Send change subject packet.
|
// Send change subject packet.
|
||||||
connection.sendPacket(message);
|
connection.sendPacket(message);
|
||||||
// Wait up to a certain number of seconds for a reply.
|
// Wait up to a certain number of seconds for a reply.
|
||||||
Message answer =
|
response.nextResultOrThrow();
|
||||||
(Message) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (answer == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (answer.getError() != null) {
|
|
||||||
throw new XMPPException(answer.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,8 +21,10 @@ import org.jivesoftware.smack.PacketCollector;
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
import org.jivesoftware.smack.SmackConfiguration;
|
||||||
import org.jivesoftware.smack.Connection;
|
import org.jivesoftware.smack.Connection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.filter.*;
|
import org.jivesoftware.smack.filter.AndFilter;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.filter.PacketExtensionFilter;
|
||||||
|
import org.jivesoftware.smack.filter.PacketFilter;
|
||||||
|
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.Message;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
|
@ -139,9 +141,8 @@ public class OfflineMessageManager {
|
||||||
item.setAction("view");
|
item.setAction("view");
|
||||||
request.addItem(item);
|
request.addItem(item);
|
||||||
}
|
}
|
||||||
// Filter packets looking for an answer from the server.
|
connection.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
PacketFilter responseFilter = new PacketIDFilter(request.getPacketID());
|
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
||||||
// Filter offline messages that were requested by this request
|
// Filter offline messages that were requested by this request
|
||||||
PacketFilter messageFilter = new AndFilter(packetFilter, new PacketFilter() {
|
PacketFilter messageFilter = new AndFilter(packetFilter, new PacketFilter() {
|
||||||
public boolean accept(Packet packet) {
|
public boolean accept(Packet packet) {
|
||||||
|
@ -151,27 +152,13 @@ public class OfflineMessageManager {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
PacketCollector messageCollector = connection.createPacketCollector(messageFilter);
|
PacketCollector messageCollector = connection.createPacketCollector(messageFilter);
|
||||||
// Send the retrieval request to the server.
|
|
||||||
connection.sendPacket(request);
|
|
||||||
// Wait up to a certain number of seconds for a reply.
|
|
||||||
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (answer == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
} else if (answer.getError() != null) {
|
|
||||||
throw new XMPPException(answer.getError());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect the received offline messages
|
// Collect the received offline messages
|
||||||
Message message = (Message) messageCollector.nextResult(
|
Message message = (Message) messageCollector.nextResult();
|
||||||
SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
while (message != null) {
|
while (message != null) {
|
||||||
messages.add(message);
|
messages.add(message);
|
||||||
message =
|
message =
|
||||||
(Message) messageCollector.nextResult(
|
(Message) messageCollector.nextResult(
|
||||||
SmackConfiguration.getPacketReplyTimeout());
|
SmackConfiguration.getDefaultPacketReplyTimeout());
|
||||||
}
|
}
|
||||||
// Stop queuing offline messages
|
// Stop queuing offline messages
|
||||||
messageCollector.cancel();
|
messageCollector.cancel();
|
||||||
|
@ -191,32 +178,16 @@ public class OfflineMessageManager {
|
||||||
List<Message> messages = new ArrayList<Message>();
|
List<Message> messages = new ArrayList<Message>();
|
||||||
OfflineMessageRequest request = new OfflineMessageRequest();
|
OfflineMessageRequest request = new OfflineMessageRequest();
|
||||||
request.setFetch(true);
|
request.setFetch(true);
|
||||||
// Filter packets looking for an answer from the server.
|
connection.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
PacketFilter responseFilter = new PacketIDFilter(request.getPacketID());
|
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
||||||
// Filter offline messages that were requested by this request
|
|
||||||
PacketCollector messageCollector = connection.createPacketCollector(packetFilter);
|
PacketCollector messageCollector = connection.createPacketCollector(packetFilter);
|
||||||
// Send the retrieval request to the server.
|
|
||||||
connection.sendPacket(request);
|
|
||||||
// Wait up to a certain number of seconds for a reply.
|
|
||||||
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (answer == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
} else if (answer.getError() != null) {
|
|
||||||
throw new XMPPException(answer.getError());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect the received offline messages
|
// Collect the received offline messages
|
||||||
Message message = (Message) messageCollector.nextResult(
|
Message message = (Message) messageCollector.nextResult();
|
||||||
SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
while (message != null) {
|
while (message != null) {
|
||||||
messages.add(message);
|
messages.add(message);
|
||||||
message =
|
message =
|
||||||
(Message) messageCollector.nextResult(
|
(Message) messageCollector.nextResult(
|
||||||
SmackConfiguration.getPacketReplyTimeout());
|
SmackConfiguration.getDefaultPacketReplyTimeout());
|
||||||
}
|
}
|
||||||
// Stop queuing offline messages
|
// Stop queuing offline messages
|
||||||
messageCollector.cancel();
|
messageCollector.cancel();
|
||||||
|
@ -238,21 +209,7 @@ public class OfflineMessageManager {
|
||||||
item.setAction("remove");
|
item.setAction("remove");
|
||||||
request.addItem(item);
|
request.addItem(item);
|
||||||
}
|
}
|
||||||
// Filter packets looking for an answer from the server.
|
connection.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
PacketFilter responseFilter = new PacketIDFilter(request.getPacketID());
|
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
||||||
// Send the deletion request to the server.
|
|
||||||
connection.sendPacket(request);
|
|
||||||
// Wait up to a certain number of seconds for a reply.
|
|
||||||
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (answer == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
} else if (answer.getError() != null) {
|
|
||||||
throw new XMPPException(answer.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -264,20 +221,6 @@ public class OfflineMessageManager {
|
||||||
public void deleteMessages() throws XMPPException {
|
public void deleteMessages() throws XMPPException {
|
||||||
OfflineMessageRequest request = new OfflineMessageRequest();
|
OfflineMessageRequest request = new OfflineMessageRequest();
|
||||||
request.setPurge(true);
|
request.setPurge(true);
|
||||||
// Filter packets looking for an answer from the server.
|
connection.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
PacketFilter responseFilter = new PacketIDFilter(request.getPacketID());
|
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
||||||
// Send the deletion request to the server.
|
|
||||||
connection.sendPacket(request);
|
|
||||||
// Wait up to a certain number of seconds for a reply.
|
|
||||||
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (answer == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
} else if (answer.getError() != null) {
|
|
||||||
throw new XMPPException(answer.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,6 @@ import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smack.packet.IQ.Type;
|
import org.jivesoftware.smack.packet.IQ.Type;
|
||||||
import org.jivesoftware.smack.util.SyncPacketSend;
|
|
||||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
||||||
import org.jivesoftware.smackx.ping.packet.Ping;
|
import org.jivesoftware.smackx.ping.packet.Ping;
|
||||||
|
@ -120,7 +119,7 @@ public class PingManager {
|
||||||
Ping ping = new Ping(jid);
|
Ping ping = new Ping(jid);
|
||||||
Connection connection = weakRefConnection.get();
|
Connection connection = weakRefConnection.get();
|
||||||
try {
|
try {
|
||||||
SyncPacketSend.getReply(connection, ping);
|
connection.createPacketCollectorAndSend(ping).nextResultOrThrow();
|
||||||
}
|
}
|
||||||
catch (XMPPException exc) {
|
catch (XMPPException exc) {
|
||||||
|
|
||||||
|
@ -137,7 +136,7 @@ public class PingManager {
|
||||||
* @return true if a reply was received from the entity, false otherwise.
|
* @return true if a reply was received from the entity, false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean ping(String jid) {
|
public boolean ping(String jid) {
|
||||||
return ping(jid, SmackConfiguration.getPacketReplyTimeout());
|
return ping(jid, SmackConfiguration.getDefaultPacketReplyTimeout());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,9 +18,7 @@ package org.jivesoftware.smackx.privacy;
|
||||||
|
|
||||||
import org.jivesoftware.smack.Connection;
|
import org.jivesoftware.smack.Connection;
|
||||||
import org.jivesoftware.smack.ConnectionCreationListener;
|
import org.jivesoftware.smack.ConnectionCreationListener;
|
||||||
import org.jivesoftware.smack.PacketCollector;
|
|
||||||
import org.jivesoftware.smack.PacketListener;
|
import org.jivesoftware.smack.PacketListener;
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.filter.*;
|
import org.jivesoftware.smack.filter.*;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
|
@ -154,66 +152,28 @@ public class PrivacyListManager {
|
||||||
requestPrivacy.setType(Privacy.Type.GET);
|
requestPrivacy.setType(Privacy.Type.GET);
|
||||||
requestPrivacy.setFrom(this.getUser());
|
requestPrivacy.setFrom(this.getUser());
|
||||||
|
|
||||||
// Filter packets looking for an answer from the server.
|
Privacy privacyAnswer = (Privacy) connection.createPacketCollectorAndSend(requestPrivacy).nextResultOrThrow();
|
||||||
PacketFilter responseFilter = new PacketIDFilter(requestPrivacy.getPacketID());
|
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
||||||
|
|
||||||
// Send create & join packet.
|
|
||||||
connection.sendPacket(requestPrivacy);
|
|
||||||
|
|
||||||
// Wait up to a certain number of seconds for a reply.
|
|
||||||
Privacy privacyAnswer =
|
|
||||||
(Privacy) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
// Interprete the result and answer the privacy only if it is valid
|
|
||||||
if (privacyAnswer == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (privacyAnswer.getError() != null) {
|
|
||||||
throw new XMPPException(privacyAnswer.getError());
|
|
||||||
}
|
|
||||||
return privacyAnswer;
|
return privacyAnswer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the {@link Privacy} packet to the server in order to modify the server privacy and
|
* Send the {@link Privacy} packet to the server in order to modify the server privacy and waits
|
||||||
* waits for the answer.
|
* for the answer.
|
||||||
*
|
*
|
||||||
* @param requestPrivacy is the {@link Privacy} packet configured properly whose xml will be sent
|
* @param requestPrivacy is the {@link Privacy} packet configured properly whose xml will be
|
||||||
* to the server.
|
* sent to the server.
|
||||||
* @return a new {@link Privacy} with the data received from the server.
|
* @return a new {@link Privacy} with the data received from the server.
|
||||||
* @exception XMPPException if the request or the answer failed, it raises an exception.
|
* @exception XMPPException if the request or the answer failed, it raises an exception.
|
||||||
*/
|
*/
|
||||||
private Packet setRequest(Privacy requestPrivacy) throws XMPPException {
|
private Packet setRequest(Privacy requestPrivacy) throws XMPPException {
|
||||||
Connection connection = PrivacyListManager.this.connection.get();
|
Connection connection = PrivacyListManager.this.connection.get();
|
||||||
if (connection == null) throw new XMPPException("Connection instance already gc'ed");
|
if (connection == null)
|
||||||
|
throw new XMPPException("Connection instance already gc'ed");
|
||||||
// The request is a get iq type
|
// The request is a get iq type
|
||||||
requestPrivacy.setType(Privacy.Type.SET);
|
requestPrivacy.setType(Privacy.Type.SET);
|
||||||
requestPrivacy.setFrom(this.getUser());
|
requestPrivacy.setFrom(this.getUser());
|
||||||
|
|
||||||
// Filter packets looking for an answer from the server.
|
return connection.createPacketCollectorAndSend(requestPrivacy).nextResultOrThrow();
|
||||||
PacketFilter responseFilter = new PacketIDFilter(requestPrivacy.getPacketID());
|
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
||||||
|
|
||||||
// Send create & join packet.
|
|
||||||
connection.sendPacket(requestPrivacy);
|
|
||||||
|
|
||||||
// Wait up to a certain number of seconds for a reply.
|
|
||||||
Packet privacyAnswer = response.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
// Interprete the result and answer the privacy only if it is valid
|
|
||||||
if (privacyAnswer == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
} else if (privacyAnswer.getError() != null) {
|
|
||||||
throw new XMPPException(privacyAnswer.getError());
|
|
||||||
}
|
|
||||||
return privacyAnswer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.packet.IQ.Type;
|
import org.jivesoftware.smack.packet.IQ.Type;
|
||||||
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
|
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
|
||||||
import org.jivesoftware.smackx.pubsub.packet.PubSub;
|
import org.jivesoftware.smackx.pubsub.packet.PubSub;
|
||||||
import org.jivesoftware.smackx.pubsub.packet.SyncPacketSend;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main class for the majority of pubsub functionality. In general
|
* The main class for the majority of pubsub functionality. In general
|
||||||
|
@ -56,7 +55,7 @@ public class LeafNode extends Node
|
||||||
DiscoverItems items = new DiscoverItems();
|
DiscoverItems items = new DiscoverItems();
|
||||||
items.setTo(to);
|
items.setTo(to);
|
||||||
items.setNode(getId());
|
items.setNode(getId());
|
||||||
return (DiscoverItems)SyncPacketSend.getReply(con, items);
|
return (DiscoverItems) con.createPacketCollectorAndSend(items).nextResultOrThrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,7 +71,7 @@ public class LeafNode extends Node
|
||||||
{
|
{
|
||||||
PubSub request = createPubsubPacket(Type.GET, new GetItemsRequest(getId()));
|
PubSub request = createPubsubPacket(Type.GET, new GetItemsRequest(getId()));
|
||||||
|
|
||||||
PubSub result = (PubSub)SyncPacketSend.getReply(con, request);
|
PubSub result = (PubSub) con.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS);
|
ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS);
|
||||||
return (List<T>)itemsElem.getItems();
|
return (List<T>)itemsElem.getItems();
|
||||||
}
|
}
|
||||||
|
@ -94,7 +93,7 @@ public class LeafNode extends Node
|
||||||
{
|
{
|
||||||
PubSub request = createPubsubPacket(Type.GET, new GetItemsRequest(getId(), subscriptionId));
|
PubSub request = createPubsubPacket(Type.GET, new GetItemsRequest(getId(), subscriptionId));
|
||||||
|
|
||||||
PubSub result = (PubSub)SyncPacketSend.getReply(con, request);
|
PubSub result = (PubSub) con.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS);
|
ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS);
|
||||||
return (List<T>)itemsElem.getItems();
|
return (List<T>)itemsElem.getItems();
|
||||||
}
|
}
|
||||||
|
@ -124,7 +123,7 @@ public class LeafNode extends Node
|
||||||
}
|
}
|
||||||
PubSub request = createPubsubPacket(Type.GET, new ItemsExtension(ItemsExtension.ItemsElementType.items, getId(), itemList));
|
PubSub request = createPubsubPacket(Type.GET, new ItemsExtension(ItemsExtension.ItemsElementType.items, getId(), itemList));
|
||||||
|
|
||||||
PubSub result = (PubSub)SyncPacketSend.getReply(con, request);
|
PubSub result = (PubSub) con.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS);
|
ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS);
|
||||||
return (List<T>)itemsElem.getItems();
|
return (List<T>)itemsElem.getItems();
|
||||||
}
|
}
|
||||||
|
@ -144,7 +143,7 @@ public class LeafNode extends Node
|
||||||
{
|
{
|
||||||
PubSub request = createPubsubPacket(Type.GET, new GetItemsRequest(getId(), maxItems));
|
PubSub request = createPubsubPacket(Type.GET, new GetItemsRequest(getId(), maxItems));
|
||||||
|
|
||||||
PubSub result = (PubSub)SyncPacketSend.getReply(con, request);
|
PubSub result = (PubSub) con.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS);
|
ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS);
|
||||||
return (List<T>)itemsElem.getItems();
|
return (List<T>)itemsElem.getItems();
|
||||||
}
|
}
|
||||||
|
@ -167,7 +166,7 @@ public class LeafNode extends Node
|
||||||
{
|
{
|
||||||
PubSub request = createPubsubPacket(Type.GET, new GetItemsRequest(getId(), subscriptionId, maxItems));
|
PubSub request = createPubsubPacket(Type.GET, new GetItemsRequest(getId(), subscriptionId, maxItems));
|
||||||
|
|
||||||
PubSub result = (PubSub)SyncPacketSend.getReply(con, request);
|
PubSub result = (PubSub) con.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS);
|
ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS);
|
||||||
return (List<T>)itemsElem.getItems();
|
return (List<T>)itemsElem.getItems();
|
||||||
}
|
}
|
||||||
|
@ -253,7 +252,7 @@ public class LeafNode extends Node
|
||||||
{
|
{
|
||||||
PubSub packet = createPubsubPacket(Type.SET, new NodeExtension(PubSubElementType.PUBLISH, getId()));
|
PubSub packet = createPubsubPacket(Type.SET, new NodeExtension(PubSubElementType.PUBLISH, getId()));
|
||||||
|
|
||||||
SyncPacketSend.getReply(con, packet);
|
con.createPacketCollectorAndSend(packet).nextResultOrThrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -306,7 +305,7 @@ public class LeafNode extends Node
|
||||||
{
|
{
|
||||||
PubSub packet = createPubsubPacket(Type.SET, new PublishItem<T>(getId(), items));
|
PubSub packet = createPubsubPacket(Type.SET, new PublishItem<T>(getId(), items));
|
||||||
|
|
||||||
SyncPacketSend.getReply(con, packet);
|
con.createPacketCollectorAndSend(packet).nextResultOrThrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -322,7 +321,7 @@ public class LeafNode extends Node
|
||||||
{
|
{
|
||||||
PubSub request = createPubsubPacket(Type.SET, new NodeExtension(PubSubElementType.PURGE_OWNER, getId()), PubSubElementType.PURGE_OWNER.getNamespace());
|
PubSub request = createPubsubPacket(Type.SET, new NodeExtension(PubSubElementType.PURGE_OWNER, getId()), PubSubElementType.PURGE_OWNER.getNamespace());
|
||||||
|
|
||||||
SyncPacketSend.getReply(con, request);
|
con.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -357,6 +356,6 @@ public class LeafNode extends Node
|
||||||
items.add(new Item(id));
|
items.add(new Item(id));
|
||||||
}
|
}
|
||||||
PubSub request = createPubsubPacket(Type.SET, new ItemsExtension(ItemsExtension.ItemsElementType.retract, getId(), items));
|
PubSub request = createPubsubPacket(Type.SET, new ItemsExtension(ItemsExtension.ItemsElementType.retract, getId(), items));
|
||||||
SyncPacketSend.getReply(con, request);
|
con.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,6 @@ import org.jivesoftware.smackx.pubsub.listener.ItemEventListener;
|
||||||
import org.jivesoftware.smackx.pubsub.listener.NodeConfigListener;
|
import org.jivesoftware.smackx.pubsub.listener.NodeConfigListener;
|
||||||
import org.jivesoftware.smackx.pubsub.packet.PubSub;
|
import org.jivesoftware.smackx.pubsub.packet.PubSub;
|
||||||
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
|
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
|
||||||
import org.jivesoftware.smackx.pubsub.packet.SyncPacketSend;
|
|
||||||
import org.jivesoftware.smackx.pubsub.util.NodeUtils;
|
import org.jivesoftware.smackx.pubsub.util.NodeUtils;
|
||||||
import org.jivesoftware.smackx.shim.packet.Header;
|
import org.jivesoftware.smackx.shim.packet.Header;
|
||||||
import org.jivesoftware.smackx.shim.packet.HeadersExtension;
|
import org.jivesoftware.smackx.shim.packet.HeadersExtension;
|
||||||
|
@ -109,7 +108,7 @@ abstract public class Node
|
||||||
throws XMPPException
|
throws XMPPException
|
||||||
{
|
{
|
||||||
PubSub packet = createPubsubPacket(Type.SET, new FormNode(FormNodeType.CONFIGURE_OWNER, getId(), submitForm), PubSubNamespace.OWNER);
|
PubSub packet = createPubsubPacket(Type.SET, new FormNode(FormNodeType.CONFIGURE_OWNER, getId(), submitForm), PubSubNamespace.OWNER);
|
||||||
SyncPacketSend.getReply(con, packet);
|
con.createPacketCollectorAndSend(packet).nextResultOrThrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,7 +124,7 @@ abstract public class Node
|
||||||
DiscoverInfo info = new DiscoverInfo();
|
DiscoverInfo info = new DiscoverInfo();
|
||||||
info.setTo(to);
|
info.setTo(to);
|
||||||
info.setNode(getId());
|
info.setNode(getId());
|
||||||
return (DiscoverInfo)SyncPacketSend.getReply(con, info);
|
return (DiscoverInfo) con.createPacketCollectorAndSend(info).nextResultOrThrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -30,7 +30,6 @@ import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
||||||
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
|
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
|
||||||
import org.jivesoftware.smackx.pubsub.packet.PubSub;
|
import org.jivesoftware.smackx.pubsub.packet.PubSub;
|
||||||
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
|
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
|
||||||
import org.jivesoftware.smackx.pubsub.packet.SyncPacketSend;
|
|
||||||
import org.jivesoftware.smackx.pubsub.util.NodeUtils;
|
import org.jivesoftware.smackx.pubsub.util.NodeUtils;
|
||||||
import org.jivesoftware.smackx.xdata.Form;
|
import org.jivesoftware.smackx.xdata.Form;
|
||||||
import org.jivesoftware.smackx.xdata.FormField;
|
import org.jivesoftware.smackx.xdata.FormField;
|
||||||
|
@ -164,7 +163,7 @@ final public class PubSubManager
|
||||||
info.setTo(to);
|
info.setTo(to);
|
||||||
info.setNode(id);
|
info.setNode(id);
|
||||||
|
|
||||||
DiscoverInfo infoReply = (DiscoverInfo)SyncPacketSend.getReply(con, info);
|
DiscoverInfo infoReply = (DiscoverInfo) con.createPacketCollectorAndSend(info).nextResultOrThrow();
|
||||||
|
|
||||||
if (infoReply.getIdentities().next().getType().equals(NodeType.leaf.toString()))
|
if (infoReply.getIdentities().next().getType().equals(NodeType.leaf.toString()))
|
||||||
node = new LeafNode(con, id);
|
node = new LeafNode(con, id);
|
||||||
|
@ -198,7 +197,7 @@ final public class PubSubManager
|
||||||
if (nodeId != null)
|
if (nodeId != null)
|
||||||
items.setNode(nodeId);
|
items.setNode(nodeId);
|
||||||
items.setTo(to);
|
items.setTo(to);
|
||||||
DiscoverItems nodeItems = (DiscoverItems)SyncPacketSend.getReply(con, items);
|
DiscoverItems nodeItems = (DiscoverItems) con.createPacketCollectorAndSend(items).nextResultOrThrow();
|
||||||
return nodeItems;
|
return nodeItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,7 +314,7 @@ final public class PubSubManager
|
||||||
static Packet sendPubsubPacket(Connection con, String to, Type type, PacketExtension ext, PubSubNamespace ns)
|
static Packet sendPubsubPacket(Connection con, String to, Type type, PacketExtension ext, PubSubNamespace ns)
|
||||||
throws XMPPException
|
throws XMPPException
|
||||||
{
|
{
|
||||||
return SyncPacketSend.getReply(con, createPubsubPacket(to, type, ext, ns));
|
return con.createPacketCollectorAndSend(createPubsubPacket(to, type, ext, ns)).nextResultOrThrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Packet sendPubsubPacket(Connection con, String to, Type type, PubSub packet)
|
static Packet sendPubsubPacket(Connection con, String to, Type type, PubSub packet)
|
||||||
|
@ -327,7 +326,7 @@ final public class PubSubManager
|
||||||
static Packet sendPubsubPacket(Connection con, String to, Type type, PubSub packet, PubSubNamespace ns)
|
static Packet sendPubsubPacket(Connection con, String to, Type type, PubSub packet, PubSubNamespace ns)
|
||||||
throws XMPPException
|
throws XMPPException
|
||||||
{
|
{
|
||||||
return SyncPacketSend.getReply(con, packet);
|
return con.createPacketCollectorAndSend(packet).nextResultOrThrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright the original author or authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.jivesoftware.smackx.pubsub.packet;
|
|
||||||
|
|
||||||
import org.jivesoftware.smack.PacketCollector;
|
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
|
||||||
import org.jivesoftware.smack.Connection;
|
|
||||||
import org.jivesoftware.smack.XMPPException;
|
|
||||||
import org.jivesoftware.smack.filter.PacketFilter;
|
|
||||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility class for doing synchronous calls to the server. Provides several
|
|
||||||
* methods for sending a packet to the server and waiting for the reply.
|
|
||||||
*
|
|
||||||
* @author Robin Collier
|
|
||||||
*/
|
|
||||||
final public class SyncPacketSend
|
|
||||||
{
|
|
||||||
private SyncPacketSend()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
static public Packet getReply(Connection connection, Packet packet, long timeout)
|
|
||||||
throws XMPPException
|
|
||||||
{
|
|
||||||
PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID());
|
|
||||||
PacketCollector response = connection.createPacketCollector(responseFilter);
|
|
||||||
|
|
||||||
connection.sendPacket(packet);
|
|
||||||
|
|
||||||
// Wait up to a certain number of seconds for a reply.
|
|
||||||
Packet result = response.nextResult(timeout);
|
|
||||||
|
|
||||||
// Stop queuing results
|
|
||||||
response.cancel();
|
|
||||||
|
|
||||||
if (result == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
else if (result.getError() != null) {
|
|
||||||
throw new XMPPException(result.getError());
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static public Packet getReply(Connection connection, Packet packet)
|
|
||||||
throws XMPPException
|
|
||||||
{
|
|
||||||
return getReply(connection, packet, SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -16,11 +16,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.search;
|
package org.jivesoftware.smackx.search;
|
||||||
|
|
||||||
import org.jivesoftware.smack.PacketCollector;
|
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
|
||||||
import org.jivesoftware.smack.Connection;
|
import org.jivesoftware.smack.Connection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.provider.IQProvider;
|
import org.jivesoftware.smack.provider.IQProvider;
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
|
@ -69,19 +66,7 @@ public class UserSearch extends IQ {
|
||||||
search.setType(IQ.Type.GET);
|
search.setType(IQ.Type.GET);
|
||||||
search.setTo(searchService);
|
search.setTo(searchService);
|
||||||
|
|
||||||
PacketCollector collector = con.createPacketCollector(new PacketIDFilter(search.getPacketID()));
|
IQ response = (IQ) con.createPacketCollectorAndSend(search).nextResultOrThrow();
|
||||||
con.sendPacket(search);
|
|
||||||
|
|
||||||
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return Form.getFormFrom(response);
|
return Form.getFormFrom(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,22 +86,7 @@ public class UserSearch extends IQ {
|
||||||
search.setTo(searchService);
|
search.setTo(searchService);
|
||||||
search.addExtension(searchForm.getDataFormToSend());
|
search.addExtension(searchForm.getDataFormToSend());
|
||||||
|
|
||||||
PacketCollector collector = con.createPacketCollector(new PacketIDFilter(search.getPacketID()));
|
IQ response = (IQ) con.createPacketCollectorAndSend(search).nextResultOrThrow();
|
||||||
|
|
||||||
con.sendPacket(search);
|
|
||||||
|
|
||||||
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
return sendSimpleSearchForm(con, searchForm, searchService);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return ReportedData.getReportedDataFrom(response);
|
return ReportedData.getReportedDataFrom(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,25 +106,8 @@ public class UserSearch extends IQ {
|
||||||
search.setType(IQ.Type.SET);
|
search.setType(IQ.Type.SET);
|
||||||
search.setTo(searchService);
|
search.setTo(searchService);
|
||||||
|
|
||||||
PacketCollector collector = con.createPacketCollector(new PacketIDFilter(search.getPacketID()));
|
SimpleUserSearch response = (SimpleUserSearch) con.createPacketCollectorAndSend(search).nextResultOrThrow();
|
||||||
|
return response.getReportedData();
|
||||||
con.sendPacket(search);
|
|
||||||
|
|
||||||
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response instanceof SimpleUserSearch) {
|
|
||||||
return ((SimpleUserSearch) response).getReportedData();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -17,10 +17,7 @@
|
||||||
package org.jivesoftware.smackx.sharedgroups;
|
package org.jivesoftware.smackx.sharedgroups;
|
||||||
|
|
||||||
import org.jivesoftware.smack.Connection;
|
import org.jivesoftware.smack.Connection;
|
||||||
import org.jivesoftware.smack.PacketCollector;
|
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smackx.sharedgroups.packet.SharedGroupsInfo;
|
import org.jivesoftware.smackx.sharedgroups.packet.SharedGroupsInfo;
|
||||||
|
|
||||||
|
@ -48,22 +45,7 @@ public class SharedGroupManager {
|
||||||
SharedGroupsInfo info = new SharedGroupsInfo();
|
SharedGroupsInfo info = new SharedGroupsInfo();
|
||||||
info.setType(IQ.Type.GET);
|
info.setType(IQ.Type.GET);
|
||||||
|
|
||||||
// Create a packet collector to listen for a response.
|
SharedGroupsInfo result = (SharedGroupsInfo) connection.createPacketCollectorAndSend(info).nextResultOrThrow();
|
||||||
PacketCollector collector =
|
return result.getGroups();
|
||||||
connection.createPacketCollector(new PacketIDFilter(info.getPacketID()));
|
|
||||||
|
|
||||||
connection.sendPacket(info);
|
|
||||||
|
|
||||||
// Wait up to 5 seconds for a result.
|
|
||||||
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
// Stop queuing results
|
|
||||||
collector.cancel();
|
|
||||||
if (result == null) {
|
|
||||||
throw new XMPPException("No response from the server.");
|
|
||||||
}
|
|
||||||
if (result.getType() == IQ.Type.ERROR) {
|
|
||||||
throw new XMPPException(result.getError());
|
|
||||||
}
|
|
||||||
return ((SharedGroupsInfo) result).getGroups();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,13 +34,8 @@ import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.jivesoftware.smack.Connection;
|
import org.jivesoftware.smack.Connection;
|
||||||
import org.jivesoftware.smack.PacketCollector;
|
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
|
||||||
import org.jivesoftware.smack.packet.XMPPError;
|
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -526,19 +521,7 @@ public class VCard extends IQ {
|
||||||
|
|
||||||
setType(IQ.Type.SET);
|
setType(IQ.Type.SET);
|
||||||
setFrom(connection.getUser());
|
setFrom(connection.getUser());
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(getPacketID()));
|
connection.createPacketCollectorAndSend(this).nextResultOrThrow();
|
||||||
connection.sendPacket(this);
|
|
||||||
|
|
||||||
Packet response = collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -564,29 +547,7 @@ public class VCard extends IQ {
|
||||||
|
|
||||||
private void doLoad(Connection connection, String user) throws XMPPException {
|
private void doLoad(Connection connection, String user) throws XMPPException {
|
||||||
setType(Type.GET);
|
setType(Type.GET);
|
||||||
PacketCollector collector = connection.createPacketCollector(
|
VCard result = (VCard) connection.createPacketCollectorAndSend(this).nextResultOrThrow();
|
||||||
new PacketIDFilter(getPacketID()));
|
|
||||||
connection.sendPacket(this);
|
|
||||||
|
|
||||||
VCard result = null;
|
|
||||||
Packet packet = collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
if (packet == null) {
|
|
||||||
String errorMessage = "Timeout getting VCard information";
|
|
||||||
throw new XMPPException(errorMessage, new XMPPError(XMPPError.Condition.request_timeout, errorMessage));
|
|
||||||
}
|
|
||||||
if (packet.getError() != null) {
|
|
||||||
throw new XMPPException(packet.getError());
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
result = (VCard) packet;
|
|
||||||
}
|
|
||||||
catch (ClassCastException e) {
|
|
||||||
log.log(Level.SEVERE, "No VCard for " + user, e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
copyFieldsFrom(result);
|
copyFieldsFrom(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,9 +54,10 @@ public class InBandBytestreamManagerTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize fields used in the tests.
|
* Initialize fields used in the tests.
|
||||||
|
* @throws XMPPException
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() throws XMPPException {
|
||||||
|
|
||||||
// build protocol verifier
|
// build protocol verifier
|
||||||
protocol = new Protocol();
|
protocol = new Protocol();
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.util.Random;
|
||||||
|
|
||||||
import org.jivesoftware.smack.Connection;
|
import org.jivesoftware.smack.Connection;
|
||||||
import org.jivesoftware.smack.PacketListener;
|
import org.jivesoftware.smack.PacketListener;
|
||||||
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.Message;
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
|
@ -71,9 +72,10 @@ public class InBandBytestreamSessionMessageTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize fields used in the tests.
|
* Initialize fields used in the tests.
|
||||||
|
* @throws XMPPException
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() throws XMPPException {
|
||||||
|
|
||||||
// build protocol verifier
|
// build protocol verifier
|
||||||
protocol = new Protocol();
|
protocol = new Protocol();
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.util.Random;
|
||||||
|
|
||||||
import org.jivesoftware.smack.Connection;
|
import org.jivesoftware.smack.Connection;
|
||||||
import org.jivesoftware.smack.PacketListener;
|
import org.jivesoftware.smack.PacketListener;
|
||||||
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.XMPPError;
|
import org.jivesoftware.smack.packet.XMPPError;
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
|
@ -72,9 +73,10 @@ public class InBandBytestreamSessionTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize fields used in the tests.
|
* Initialize fields used in the tests.
|
||||||
|
* @throws XMPPException
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() throws XMPPException {
|
||||||
|
|
||||||
// build protocol verifier
|
// build protocol verifier
|
||||||
protocol = new Protocol();
|
protocol = new Protocol();
|
||||||
|
|
|
@ -71,9 +71,10 @@ public class Socks5ByteStreamManagerTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize fields used in the tests.
|
* Initialize fields used in the tests.
|
||||||
|
* @throws XMPPException
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() throws XMPPException {
|
||||||
|
|
||||||
// build protocol verifier
|
// build protocol verifier
|
||||||
protocol = new Protocol();
|
protocol = new Protocol();
|
||||||
|
|
|
@ -60,9 +60,10 @@ public class Socks5ByteStreamRequestTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize fields used in the tests.
|
* Initialize fields used in the tests.
|
||||||
|
* @throws XMPPException
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() throws XMPPException {
|
||||||
|
|
||||||
// build protocol verifier
|
// build protocol verifier
|
||||||
protocol = new Protocol();
|
protocol = new Protocol();
|
||||||
|
|
|
@ -65,9 +65,10 @@ public class Socks5ClientForInitiatorTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize fields used in the tests.
|
* Initialize fields used in the tests.
|
||||||
|
* @throws XMPPException
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() throws XMPPException {
|
||||||
|
|
||||||
// build protocol verifier
|
// build protocol verifier
|
||||||
protocol = new Protocol();
|
protocol = new Protocol();
|
||||||
|
|
|
@ -83,7 +83,7 @@ public class ConfigureFormTest
|
||||||
|
|
||||||
Node node = mgr.getNode("princely_musings");
|
Node node = mgr.getNode("princely_musings");
|
||||||
|
|
||||||
SmackConfiguration.setPacketReplyTimeout(100);
|
SmackConfiguration.setDefaultPacketReplyTimeout(100);
|
||||||
con.setTimeout();
|
con.setTimeout();
|
||||||
|
|
||||||
node.getNodeConfiguration();
|
node.getNodeConfiguration();
|
||||||
|
|
|
@ -21,8 +21,10 @@ import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import org.jivesoftware.smack.PacketCollector;
|
import org.jivesoftware.smack.PacketCollector;
|
||||||
import org.jivesoftware.smack.Connection;
|
import org.jivesoftware.smack.Connection;
|
||||||
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.filter.PacketFilter;
|
import org.jivesoftware.smack.filter.PacketFilter;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
|
import org.jivesoftware.smack.packet.XMPPError;
|
||||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
@ -54,9 +56,10 @@ public class ConnectionUtils {
|
||||||
* @param initiatorJID the user associated to the XMPP connection
|
* @param initiatorJID the user associated to the XMPP connection
|
||||||
* @param xmppServer the XMPP server associated to the XMPP connection
|
* @param xmppServer the XMPP server associated to the XMPP connection
|
||||||
* @return a mocked XMPP connection
|
* @return a mocked XMPP connection
|
||||||
|
* @throws XMPPException
|
||||||
*/
|
*/
|
||||||
public static Connection createMockedConnection(final Protocol protocol,
|
public static Connection createMockedConnection(final Protocol protocol,
|
||||||
String initiatorJID, String xmppServer) {
|
String initiatorJID, String xmppServer) throws XMPPException {
|
||||||
|
|
||||||
// mock XMPP connection
|
// mock XMPP connection
|
||||||
Connection connection = mock(Connection.class);
|
Connection connection = mock(Connection.class);
|
||||||
|
@ -64,29 +67,49 @@ public class ConnectionUtils {
|
||||||
when(connection.getServiceName()).thenReturn(xmppServer);
|
when(connection.getServiceName()).thenReturn(xmppServer);
|
||||||
|
|
||||||
// mock packet collector
|
// mock packet collector
|
||||||
PacketCollector collector = mock(PacketCollector.class);
|
final PacketCollector collector = mock(PacketCollector.class);
|
||||||
when(connection.createPacketCollector(isA(PacketFilter.class))).thenReturn(
|
when(connection.createPacketCollector(isA(PacketFilter.class))).thenReturn(
|
||||||
collector);
|
collector);
|
||||||
Answer<Object> addIncoming = new Answer<Object>() {
|
Answer<PacketCollector> collectorAndSend = new Answer<PacketCollector>() {
|
||||||
|
@Override
|
||||||
|
public PacketCollector answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
Packet packet = (Packet) invocation.getArguments()[0];
|
||||||
|
protocol.getRequests().add(packet);
|
||||||
|
return collector;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
when(connection.createPacketCollectorAndSend(isA(Packet.class))).thenAnswer(collectorAndSend);
|
||||||
|
|
||||||
|
// mock send method
|
||||||
|
Answer<Object> addIncoming = new Answer<Object>() {
|
||||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||||
protocol.getRequests().add((Packet) invocation.getArguments()[0]);
|
protocol.getRequests().add((Packet) invocation.getArguments()[0]);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// mock send method
|
|
||||||
doAnswer(addIncoming).when(connection).sendPacket(isA(Packet.class));
|
doAnswer(addIncoming).when(connection).sendPacket(isA(Packet.class));
|
||||||
Answer<Packet> answer = new Answer<Packet>() {
|
|
||||||
|
|
||||||
|
// mock receive methods
|
||||||
|
Answer<Packet> answer = new Answer<Packet>() {
|
||||||
public Packet answer(InvocationOnMock invocation) throws Throwable {
|
public Packet answer(InvocationOnMock invocation) throws Throwable {
|
||||||
return protocol.getResponses().poll();
|
return protocol.getResponses().poll();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// mock nextResult method
|
|
||||||
when(collector.nextResult(anyInt())).thenAnswer(answer);
|
when(collector.nextResult(anyInt())).thenAnswer(answer);
|
||||||
when(collector.nextResult()).thenAnswer(answer);
|
when(collector.nextResult()).thenAnswer(answer);
|
||||||
|
Answer<Packet> answerOrThrow = new Answer<Packet>() {
|
||||||
|
@Override
|
||||||
|
public Packet answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
Packet packet = protocol.getResponses().poll();
|
||||||
|
if (packet == null) return packet;
|
||||||
|
XMPPError xmppError = packet.getError();
|
||||||
|
if (xmppError != null) throw new XMPPException(xmppError);
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
when(collector.nextResultOrThrow()).thenAnswer(answerOrThrow);
|
||||||
|
when(collector.nextResultOrThrow(anyLong())).thenAnswer(answerOrThrow);
|
||||||
|
|
||||||
// initialize service discovery manager for this connection
|
// initialize service discovery manager for this connection
|
||||||
ServiceDiscoveryManager.getInstanceFor(connection);
|
ServiceDiscoveryManager.getInstanceFor(connection);
|
||||||
|
|
|
@ -19,11 +19,8 @@ package org.jivesoftware.smackx.workgroup.agent;
|
||||||
|
|
||||||
import org.jivesoftware.smackx.workgroup.packet.AgentInfo;
|
import org.jivesoftware.smackx.workgroup.packet.AgentInfo;
|
||||||
import org.jivesoftware.smackx.workgroup.packet.AgentWorkgroups;
|
import org.jivesoftware.smackx.workgroup.packet.AgentWorkgroups;
|
||||||
import org.jivesoftware.smack.PacketCollector;
|
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
|
||||||
import org.jivesoftware.smack.Connection;
|
import org.jivesoftware.smack.Connection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -40,20 +37,7 @@ public class Agent {
|
||||||
public static Collection<String> getWorkgroups(String serviceJID, String agentJID, Connection connection) throws XMPPException {
|
public static Collection<String> getWorkgroups(String serviceJID, String agentJID, Connection connection) throws XMPPException {
|
||||||
AgentWorkgroups request = new AgentWorkgroups(agentJID);
|
AgentWorkgroups request = new AgentWorkgroups(agentJID);
|
||||||
request.setTo(serviceJID);
|
request.setTo(serviceJID);
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
|
AgentWorkgroups response = (AgentWorkgroups) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
// Send the request
|
|
||||||
connection.sendPacket(request);
|
|
||||||
|
|
||||||
AgentWorkgroups response = (AgentWorkgroups)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return response.getWorkgroups();
|
return response.getWorkgroups();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,20 +68,7 @@ public class Agent {
|
||||||
agentInfo.setType(IQ.Type.GET);
|
agentInfo.setType(IQ.Type.GET);
|
||||||
agentInfo.setTo(workgroupJID);
|
agentInfo.setTo(workgroupJID);
|
||||||
agentInfo.setFrom(getUser());
|
agentInfo.setFrom(getUser());
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(agentInfo.getPacketID()));
|
AgentInfo response = (AgentInfo) connection.createPacketCollectorAndSend(agentInfo).nextResultOrThrow();
|
||||||
// Send the request
|
|
||||||
connection.sendPacket(agentInfo);
|
|
||||||
|
|
||||||
AgentInfo response = (AgentInfo)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return response.getName();
|
return response.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,20 +88,6 @@ public class Agent {
|
||||||
agentInfo.setTo(workgroupJID);
|
agentInfo.setTo(workgroupJID);
|
||||||
agentInfo.setFrom(getUser());
|
agentInfo.setFrom(getUser());
|
||||||
agentInfo.setName(newName);
|
agentInfo.setName(newName);
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(agentInfo.getPacketID()));
|
connection.createPacketCollectorAndSend(agentInfo).nextResultOrThrow();
|
||||||
// Send the request
|
|
||||||
connection.sendPacket(agentInfo);
|
|
||||||
|
|
||||||
IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -266,15 +266,7 @@ public class AgentSession {
|
||||||
|
|
||||||
connection.sendPacket(presence);
|
connection.sendPacket(presence);
|
||||||
|
|
||||||
presence = (Presence)collector.nextResult(5000);
|
presence = (Presence)collector.nextResultOrThrow();
|
||||||
collector.cancel();
|
|
||||||
if (!presence.isAvailable()) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (presence.getError() != null) {
|
|
||||||
throw new XMPPException(presence.getError());
|
|
||||||
}
|
|
||||||
|
|
||||||
// We can safely update this iv since we didn't get any error
|
// We can safely update this iv since we didn't get any error
|
||||||
this.online = online;
|
this.online = online;
|
||||||
|
@ -371,15 +363,7 @@ public class AgentSession {
|
||||||
|
|
||||||
this.connection.sendPacket(presence);
|
this.connection.sendPacket(presence);
|
||||||
|
|
||||||
presence = (Presence)collector.nextResult(5000);
|
collector.nextResultOrThrow();
|
||||||
collector.cancel();
|
|
||||||
if (!presence.isAvailable()) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (presence.getError() != null) {
|
|
||||||
throw new XMPPException(presence.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -422,15 +406,7 @@ public class AgentSession {
|
||||||
|
|
||||||
this.connection.sendPacket(presence);
|
this.connection.sendPacket(presence);
|
||||||
|
|
||||||
presence = (Presence)collector.nextResult(5000);
|
collector.nextResultOrThrow();
|
||||||
collector.cancel();
|
|
||||||
if (!presence.isAvailable()) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (presence.getError() != null) {
|
|
||||||
throw new XMPPException(presence.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -513,19 +489,7 @@ public class AgentSession {
|
||||||
request.setType(IQ.Type.GET);
|
request.setType(IQ.Type.GET);
|
||||||
request.setTo(workgroupJID);
|
request.setTo(workgroupJID);
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
|
OccupantsInfo response = (OccupantsInfo) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
connection.sendPacket(request);
|
|
||||||
|
|
||||||
OccupantsInfo response = (OccupantsInfo)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -809,16 +773,7 @@ public class AgentSession {
|
||||||
// Send the request
|
// Send the request
|
||||||
connection.sendPacket(notes);
|
connection.sendPacket(notes);
|
||||||
|
|
||||||
IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
collector.nextResultOrThrow();
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -834,21 +789,8 @@ public class AgentSession {
|
||||||
request.setTo(workgroupJID);
|
request.setTo(workgroupJID);
|
||||||
request.setSessionID(sessionID);
|
request.setSessionID(sessionID);
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
|
ChatNotes response = (ChatNotes) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
connection.sendPacket(request);
|
|
||||||
|
|
||||||
ChatNotes response = (ChatNotes)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return response;
|
return response;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -871,19 +813,9 @@ public class AgentSession {
|
||||||
request.setType(IQ.Type.GET);
|
request.setType(IQ.Type.GET);
|
||||||
request.setTo(workgroupJID);
|
request.setTo(workgroupJID);
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
|
AgentChatHistory response = (AgentChatHistory) connection.createPacketCollectorAndSend(
|
||||||
connection.sendPacket(request);
|
request).nextResult();
|
||||||
|
|
||||||
AgentChatHistory response = (AgentChatHistory)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -898,20 +830,7 @@ public class AgentSession {
|
||||||
request.setType(IQ.Type.GET);
|
request.setType(IQ.Type.GET);
|
||||||
request.setTo(workgroupJID);
|
request.setTo(workgroupJID);
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
|
SearchSettings response = (SearchSettings) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
connection.sendPacket(request);
|
|
||||||
|
|
||||||
|
|
||||||
SearchSettings response = (SearchSettings)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -928,20 +847,7 @@ public class AgentSession {
|
||||||
request.setTo(workgroupJID);
|
request.setTo(workgroupJID);
|
||||||
request.setPersonal(!global);
|
request.setPersonal(!global);
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
|
Macros response = (Macros) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
connection.sendPacket(request);
|
|
||||||
|
|
||||||
|
|
||||||
Macros response = (Macros)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return response.getRootGroup();
|
return response.getRootGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -958,20 +864,7 @@ public class AgentSession {
|
||||||
request.setPersonal(true);
|
request.setPersonal(true);
|
||||||
request.setPersonalMacroGroup(group);
|
request.setPersonalMacroGroup(group);
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
|
connection.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
connection.sendPacket(request);
|
|
||||||
|
|
||||||
|
|
||||||
IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -987,20 +880,8 @@ public class AgentSession {
|
||||||
request.setTo(workgroupJID);
|
request.setTo(workgroupJID);
|
||||||
request.setSessionID(sessionID);
|
request.setSessionID(sessionID);
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
|
ChatMetadata response = (ChatMetadata) connection.createPacketCollectorAndSend(request).nextResult();
|
||||||
connection.sendPacket(request);
|
|
||||||
|
|
||||||
|
|
||||||
ChatMetadata response = (ChatMetadata)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return response.getMetadata();
|
return response.getMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1043,19 +924,7 @@ public class AgentSession {
|
||||||
iq.setTo(workgroupJID);
|
iq.setTo(workgroupJID);
|
||||||
iq.setFrom(connection.getUser());
|
iq.setFrom(connection.getUser());
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(iq.getPacketID()));
|
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||||
connection.sendPacket(iq);
|
|
||||||
|
|
||||||
IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1095,19 +964,7 @@ public class AgentSession {
|
||||||
iq.setTo(workgroupJID);
|
iq.setTo(workgroupJID);
|
||||||
iq.setFrom(connection.getUser());
|
iq.setFrom(connection.getUser());
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(iq.getPacketID()));
|
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
|
||||||
connection.sendPacket(iq);
|
|
||||||
|
|
||||||
IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1123,19 +980,8 @@ public class AgentSession {
|
||||||
setting.setType(IQ.Type.GET);
|
setting.setType(IQ.Type.GET);
|
||||||
setting.setTo(workgroupJID);
|
setting.setTo(workgroupJID);
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(setting.getPacketID()));
|
GenericSettings response = (GenericSettings) connection.createPacketCollectorAndSend(
|
||||||
connection.sendPacket(setting);
|
setting).nextResultOrThrow();
|
||||||
|
|
||||||
GenericSettings response = (GenericSettings)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1144,21 +990,8 @@ public class AgentSession {
|
||||||
request.setType(IQ.Type.GET);
|
request.setType(IQ.Type.GET);
|
||||||
request.setTo(workgroupJID);
|
request.setTo(workgroupJID);
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
|
MonitorPacket response = (MonitorPacket) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
connection.sendPacket(request);
|
|
||||||
|
|
||||||
MonitorPacket response = (MonitorPacket)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return response.isMonitor();
|
return response.isMonitor();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void makeRoomOwner(Connection con, String sessionID) throws XMPPException {
|
public void makeRoomOwner(Connection con, String sessionID) throws XMPPException {
|
||||||
|
@ -1167,19 +1000,6 @@ public class AgentSession {
|
||||||
request.setTo(workgroupJID);
|
request.setTo(workgroupJID);
|
||||||
request.setSessionID(sessionID);
|
request.setSessionID(sessionID);
|
||||||
|
|
||||||
|
connection.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
|
|
||||||
connection.sendPacket(request);
|
|
||||||
|
|
||||||
Packet response = collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,8 @@ package org.jivesoftware.smackx.workgroup.agent;
|
||||||
|
|
||||||
import org.jivesoftware.smackx.workgroup.packet.Transcript;
|
import org.jivesoftware.smackx.workgroup.packet.Transcript;
|
||||||
import org.jivesoftware.smackx.workgroup.packet.Transcripts;
|
import org.jivesoftware.smackx.workgroup.packet.Transcripts;
|
||||||
import org.jivesoftware.smack.PacketCollector;
|
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
|
||||||
import org.jivesoftware.smack.Connection;
|
import org.jivesoftware.smack.Connection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A TranscriptManager helps to retrieve the full conversation transcript of a given session
|
* A TranscriptManager helps to retrieve the full conversation transcript of a given session
|
||||||
|
@ -50,20 +47,7 @@ public class TranscriptManager {
|
||||||
public Transcript getTranscript(String workgroupJID, String sessionID) throws XMPPException {
|
public Transcript getTranscript(String workgroupJID, String sessionID) throws XMPPException {
|
||||||
Transcript request = new Transcript(sessionID);
|
Transcript request = new Transcript(sessionID);
|
||||||
request.setTo(workgroupJID);
|
request.setTo(workgroupJID);
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
|
Transcript response = (Transcript) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
// Send the request
|
|
||||||
connection.sendPacket(request);
|
|
||||||
|
|
||||||
Transcript response = (Transcript) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,20 +63,7 @@ public class TranscriptManager {
|
||||||
public Transcripts getTranscripts(String workgroupJID, String userID) throws XMPPException {
|
public Transcripts getTranscripts(String workgroupJID, String userID) throws XMPPException {
|
||||||
Transcripts request = new Transcripts(userID);
|
Transcripts request = new Transcripts(userID);
|
||||||
request.setTo(workgroupJID);
|
request.setTo(workgroupJID);
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
|
Transcripts response = (Transcripts) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
// Send the request
|
|
||||||
connection.sendPacket(request);
|
|
||||||
|
|
||||||
Transcripts response = (Transcripts) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,8 @@ package org.jivesoftware.smackx.workgroup.agent;
|
||||||
import org.jivesoftware.smackx.search.ReportedData;
|
import org.jivesoftware.smackx.search.ReportedData;
|
||||||
import org.jivesoftware.smackx.workgroup.packet.TranscriptSearch;
|
import org.jivesoftware.smackx.workgroup.packet.TranscriptSearch;
|
||||||
import org.jivesoftware.smackx.xdata.Form;
|
import org.jivesoftware.smackx.xdata.Form;
|
||||||
import org.jivesoftware.smack.PacketCollector;
|
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
|
||||||
import org.jivesoftware.smack.Connection;
|
import org.jivesoftware.smack.Connection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,21 +52,8 @@ public class TranscriptSearchManager {
|
||||||
search.setType(IQ.Type.GET);
|
search.setType(IQ.Type.GET);
|
||||||
search.setTo(serviceJID);
|
search.setTo(serviceJID);
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollector(
|
TranscriptSearch response = (TranscriptSearch) connection.createPacketCollectorAndSend(
|
||||||
new PacketIDFilter(search.getPacketID()));
|
search).nextResultOrThrow();
|
||||||
connection.sendPacket(search);
|
|
||||||
|
|
||||||
TranscriptSearch response = (TranscriptSearch) collector.nextResult(
|
|
||||||
SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return Form.getFormFrom(response);
|
return Form.getFormFrom(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,19 +73,8 @@ public class TranscriptSearchManager {
|
||||||
search.setTo(serviceJID);
|
search.setTo(serviceJID);
|
||||||
search.addExtension(completedForm.getDataFormToSend());
|
search.addExtension(completedForm.getDataFormToSend());
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(search.getPacketID()));
|
TranscriptSearch response = (TranscriptSearch) connection.createPacketCollectorAndSend(
|
||||||
connection.sendPacket(search);
|
search).nextResultOrThrow();
|
||||||
|
|
||||||
TranscriptSearch response = (TranscriptSearch) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return ReportedData.getReportedDataFrom(response);
|
return ReportedData.getReportedDataFrom(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,8 +153,9 @@ public class Workgroup {
|
||||||
* available only when agents are available for this workgroup.
|
* available only when agents are available for this workgroup.
|
||||||
*
|
*
|
||||||
* @return true if the workgroup is available for receiving new requests.
|
* @return true if the workgroup is available for receiving new requests.
|
||||||
|
* @throws XMPPException
|
||||||
*/
|
*/
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() throws XMPPException {
|
||||||
Presence directedPresence = new Presence(Presence.Type.available);
|
Presence directedPresence = new Presence(Presence.Type.available);
|
||||||
directedPresence.setTo(workgroupJID);
|
directedPresence.setTo(workgroupJID);
|
||||||
PacketFilter typeFilter = new PacketTypeFilter(Presence.class);
|
PacketFilter typeFilter = new PacketTypeFilter(Presence.class);
|
||||||
|
@ -164,20 +165,9 @@ public class Workgroup {
|
||||||
|
|
||||||
connection.sendPacket(directedPresence);
|
connection.sendPacket(directedPresence);
|
||||||
|
|
||||||
Presence response = (Presence)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
Presence response = (Presence)collector.nextResultOrThrow();
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (response.getError() != null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return Presence.Type.available == response.getType();
|
return Presence.Type.available == response.getType();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the users current position in the workgroup queue. A value of 0 means
|
* Returns the users current position in the workgroup queue. A value of 0 means
|
||||||
|
@ -323,22 +313,7 @@ public class Workgroup {
|
||||||
|
|
||||||
JoinQueuePacket joinPacket = new JoinQueuePacket(workgroupJID, answerForm, userID);
|
JoinQueuePacket joinPacket = new JoinQueuePacket(workgroupJID, answerForm, userID);
|
||||||
|
|
||||||
|
connection.createPacketCollectorAndSend(joinPacket).nextResultOrThrow();
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(joinPacket.getPacketID()));
|
|
||||||
|
|
||||||
this.connection.sendPacket(joinPacket);
|
|
||||||
|
|
||||||
IQ response = (IQ)collector.nextResult(10000);
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from the server.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Notify listeners that we've joined the queue.
|
// Notify listeners that we've joined the queue.
|
||||||
fireQueueJoinedEvent();
|
fireQueueJoinedEvent();
|
||||||
}
|
}
|
||||||
|
@ -418,18 +393,7 @@ public class Workgroup {
|
||||||
}
|
}
|
||||||
|
|
||||||
DepartQueuePacket departPacket = new DepartQueuePacket(this.workgroupJID);
|
DepartQueuePacket departPacket = new DepartQueuePacket(this.workgroupJID);
|
||||||
PacketCollector collector = this.connection.createPacketCollector(new PacketIDFilter(departPacket.getPacketID()));
|
connection.createPacketCollectorAndSend(departPacket).nextResultOrThrow();
|
||||||
|
|
||||||
connection.sendPacket(departPacket);
|
|
||||||
|
|
||||||
IQ response = (IQ)collector.nextResult(5000);
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from the server.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Notify listeners that we're no longer in the queue.
|
// Notify listeners that we're no longer in the queue.
|
||||||
fireQueueDepartedEvent();
|
fireQueueDepartedEvent();
|
||||||
|
@ -670,20 +634,8 @@ public class Workgroup {
|
||||||
request.setType(IQ.Type.GET);
|
request.setType(IQ.Type.GET);
|
||||||
request.setTo(workgroupJID);
|
request.setTo(workgroupJID);
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
|
ChatSettings response = (ChatSettings) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
connection.sendPacket(request);
|
|
||||||
|
|
||||||
|
|
||||||
ChatSettings response = (ChatSettings)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -717,20 +669,8 @@ public class Workgroup {
|
||||||
request.setType(IQ.Type.GET);
|
request.setType(IQ.Type.GET);
|
||||||
request.setTo(workgroupJID);
|
request.setTo(workgroupJID);
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
|
OfflineSettings response = (OfflineSettings) connection.createPacketCollectorAndSend(
|
||||||
connection.sendPacket(request);
|
request).nextResultOrThrow();
|
||||||
|
|
||||||
|
|
||||||
OfflineSettings response = (OfflineSettings)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -745,20 +685,7 @@ public class Workgroup {
|
||||||
request.setType(IQ.Type.GET);
|
request.setType(IQ.Type.GET);
|
||||||
request.setTo(workgroupJID);
|
request.setTo(workgroupJID);
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
|
SoundSettings response = (SoundSettings) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
|
||||||
connection.sendPacket(request);
|
|
||||||
|
|
||||||
|
|
||||||
SoundSettings response = (SoundSettings)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -773,20 +700,8 @@ public class Workgroup {
|
||||||
request.setType(IQ.Type.GET);
|
request.setType(IQ.Type.GET);
|
||||||
request.setTo(workgroupJID);
|
request.setTo(workgroupJID);
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
|
WorkgroupProperties response = (WorkgroupProperties) connection.createPacketCollectorAndSend(
|
||||||
connection.sendPacket(request);
|
request).nextResultOrThrow();
|
||||||
|
|
||||||
|
|
||||||
WorkgroupProperties response = (WorkgroupProperties)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -803,20 +718,8 @@ public class Workgroup {
|
||||||
request.setType(IQ.Type.GET);
|
request.setType(IQ.Type.GET);
|
||||||
request.setTo(workgroupJID);
|
request.setTo(workgroupJID);
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
|
WorkgroupProperties response = (WorkgroupProperties) connection.createPacketCollectorAndSend(
|
||||||
connection.sendPacket(request);
|
request).nextResultOrThrow();
|
||||||
|
|
||||||
|
|
||||||
WorkgroupProperties response = (WorkgroupProperties)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -834,19 +737,8 @@ public class Workgroup {
|
||||||
workgroupForm.setType(IQ.Type.GET);
|
workgroupForm.setType(IQ.Type.GET);
|
||||||
workgroupForm.setTo(workgroupJID);
|
workgroupForm.setTo(workgroupJID);
|
||||||
|
|
||||||
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(workgroupForm.getPacketID()));
|
WorkgroupForm response = (WorkgroupForm) connection.createPacketCollectorAndSend(
|
||||||
connection.sendPacket(workgroupForm);
|
workgroupForm).nextResultOrThrow();
|
||||||
|
|
||||||
WorkgroupForm response = (WorkgroupForm)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
||||||
|
|
||||||
// Cancel the collector.
|
|
||||||
collector.cancel();
|
|
||||||
if (response == null) {
|
|
||||||
throw new XMPPException("No response from server on status set.");
|
|
||||||
}
|
|
||||||
if (response.getError() != null) {
|
|
||||||
throw new XMPPException(response.getError());
|
|
||||||
}
|
|
||||||
return Form.getFormFrom(response);
|
return Form.getFormFrom(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue