diff --git a/core/src/main/java/org/jivesoftware/smack/AccountManager.java b/core/src/main/java/org/jivesoftware/smack/AccountManager.java
index c540ad5cc..0e6f259fd 100644
--- a/core/src/main/java/org/jivesoftware/smack/AccountManager.java
+++ b/core/src/main/java/org/jivesoftware/smack/AccountManager.java
@@ -227,19 +227,7 @@ public class AccountManager {
attributes.put("username",username);
attributes.put("password",password);
reg.setAttributes(attributes);
- PacketFilter filter = 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());
- // 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());
- }
+ connection.createPacketCollectorAndSend(reg).nextResultOrThrow();
}
/**
@@ -262,15 +250,7 @@ public class AccountManager {
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());
- }
+ collector.nextResultOrThrow();
}
/**
@@ -292,19 +272,7 @@ public class AccountManager {
// To delete an account, we add a single attribute, "remove", that is blank.
attributes.put("remove", "");
reg.setAttributes(attributes);
- PacketFilter filter = 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());
- // 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());
- }
+ connection.createPacketCollectorAndSend(reg).nextResultOrThrow();
}
/**
@@ -315,21 +283,6 @@ public class AccountManager {
private synchronized void getRegistrationInfo() throws XMPPException {
Registration reg = new Registration();
reg.setTo(connection.getServiceName());
- PacketFilter filter = 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());
- // 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;
- }
+ info = (Registration) connection.createPacketCollectorAndSend(reg).nextResultOrThrow();
}
}
diff --git a/core/src/main/java/org/jivesoftware/smack/Connection.java b/core/src/main/java/org/jivesoftware/smack/Connection.java
index c150641d0..256798e38 100644
--- a/core/src/main/java/org/jivesoftware/smack/Connection.java
+++ b/core/src/main/java/org/jivesoftware/smack/Connection.java
@@ -37,6 +37,7 @@ import org.jivesoftware.smack.compression.XMPPInputOutputStream;
import org.jivesoftware.smack.compression.Java7ZlibInputOutputStream;
import org.jivesoftware.smack.debugger.SmackDebugger;
import org.jivesoftware.smack.filter.PacketFilter;
+import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
@@ -172,6 +173,11 @@ public abstract class Connection {
*/
private ChatManager chatManager = null;
+ /**
+ *
+ */
+ private long packetReplyTimeout = SmackConfiguration.getDefaultPacketReplyTimeout();
+
/**
* The SmackDebugger allows to log and debug XML traffic.
*/
@@ -563,6 +569,24 @@ public abstract class Connection {
return connectionListeners;
}
+ /**
+ * Creates a new packet collector collecting packets that are replies to packet.
+ * Does also send packet. Note that the packet filter is at the moment created as
+ * ID filter of packet'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
* which packets will be accumulated by the collector. A PacketCollector is
@@ -848,6 +872,10 @@ public abstract class Connection {
rosterVersioningSupported = true;
}
+ public long getPacketReplyTimeout() {
+ return packetReplyTimeout;
+ }
+
/**
* A wrapper class to associate a packet filter with a listener.
*/
diff --git a/core/src/main/java/org/jivesoftware/smack/NonSASLAuthentication.java b/core/src/main/java/org/jivesoftware/smack/NonSASLAuthentication.java
index 0b6aa5ec8..15433b6bf 100644
--- a/core/src/main/java/org/jivesoftware/smack/NonSASLAuthentication.java
+++ b/core/src/main/java/org/jivesoftware/smack/NonSASLAuthentication.java
@@ -17,9 +17,9 @@
package org.jivesoftware.smack;
-import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.Authentication;
import org.jivesoftware.smack.packet.IQ;
+import org.jivesoftware.smack.packet.Packet;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.PasswordCallback;
@@ -60,22 +60,9 @@ class NonSASLAuthentication implements UserAuthentication {
discoveryAuth.setType(IQ.Type.GET);
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.
- Authentication authTypes = (Authentication) response;
- collector.cancel();
+ Authentication authTypes = (Authentication) connection.createPacketCollectorAndSend(
+ discoveryAuth).nextResultOrThrow();
// Now, create the authentication packet we'll send to the server.
Authentication auth = new Authentication();
@@ -94,19 +81,7 @@ class NonSASLAuthentication implements UserAuthentication {
auth.setResource(resource);
- collector = 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.
- 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();
+ Packet response = connection.createPacketCollectorAndSend(auth).nextResultOrThrow();
return response.getTo();
}
@@ -115,20 +90,7 @@ class NonSASLAuthentication implements UserAuthentication {
// Create the authentication packet we'll send to the server.
Authentication auth = new Authentication();
- PacketCollector collector =
- 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();
+ Packet response = connection.createPacketCollectorAndSend(auth).nextResultOrThrow();
if (response.getTo() != null) {
return response.getTo();
diff --git a/core/src/main/java/org/jivesoftware/smack/PacketCollector.java b/core/src/main/java/org/jivesoftware/smack/PacketCollector.java
index 3d92c91f7..38374c53a 100644
--- a/core/src/main/java/org/jivesoftware/smack/PacketCollector.java
+++ b/core/src/main/java/org/jivesoftware/smack/PacketCollector.java
@@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
import org.jivesoftware.smack.filter.PacketFilter;
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
@@ -105,26 +106,35 @@ public class PacketCollector {
}
/**
- * Returns the next available packet. The method call will block (not return)
- * until a packet is available.
- *
+ * Returns the next available packet. The method call will block (not return) until a packet is
+ * available.
+ *
* @return the next available packet.
*/
- public Packet nextResult() {
+ public Packet nextResultBlockForever() {
try {
- return resultQueue.take();
- }
- catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
+ return resultQueue.take();
+ }
+ catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * 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)
- * until a packet is available or the timeout has elapased. If the
+ * until a packet is available or the timeout has elapsed. If the
* timeout elapses without a result, null will be returned.
*
- * @param timeout the amount of time to wait for the next packet (in milleseconds).
* @return the next available packet.
*/
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,
+ * null 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 timeout 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.
* If so, the packet is added to the result queue.
diff --git a/core/src/main/java/org/jivesoftware/smack/PacketReader.java b/core/src/main/java/org/jivesoftware/smack/PacketReader.java
index f391c54ed..3c0d1e4ac 100644
--- a/core/src/main/java/org/jivesoftware/smack/PacketReader.java
+++ b/core/src/main/java/org/jivesoftware/smack/PacketReader.java
@@ -108,7 +108,7 @@ class PacketReader {
// (although this is a rare thing). Therefore, we continue waiting
// until either a connectionID has been set (and hence a notify was
// made) or the total wait time has elapsed.
- int waitTime = SmackConfiguration.getPacketReplyTimeout();
+ int waitTime = SmackConfiguration.getDefaultPacketReplyTimeout();
wait(3 * waitTime);
}
catch (InterruptedException ie) {
diff --git a/core/src/main/java/org/jivesoftware/smack/Roster.java b/core/src/main/java/org/jivesoftware/smack/Roster.java
index 0c2fa74fd..40e1f818d 100644
--- a/core/src/main/java/org/jivesoftware/smack/Roster.java
+++ b/core/src/main/java/org/jivesoftware/smack/Roster.java
@@ -277,19 +277,7 @@ public class Roster {
}
}
rosterPacket.addRosterItem(item);
- // Wait up to a certain number of seconds for a reply from the server.
- 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());
- }
+ connection.createPacketCollectorAndSend(rosterPacket).nextResultOrThrow();
// Create a presence subscription packet and send.
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
item.setItemType(RosterPacket.ItemType.remove);
packet.addRosterItem(item);
- PacketCollector collector = connection.createPacketCollector(
- 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());
- }
+ connection.createPacketCollectorAndSend(packet).nextResultOrThrow();
}
/**
diff --git a/core/src/main/java/org/jivesoftware/smack/RosterGroup.java b/core/src/main/java/org/jivesoftware/smack/RosterGroup.java
index 47c446893..ee3b79049 100644
--- a/core/src/main/java/org/jivesoftware/smack/RosterGroup.java
+++ b/core/src/main/java/org/jivesoftware/smack/RosterGroup.java
@@ -178,15 +178,7 @@ public class RosterGroup {
}
}
if (collector != null) {
- 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());
- }
+ collector.nextResultOrThrow();
}
}
@@ -220,15 +212,7 @@ public class RosterGroup {
}
}
if (collector != null) {
- 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());
- }
+ collector.nextResultOrThrow();
}
}
diff --git a/core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java b/core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java
index 4be0789e4..51fe0c0b7 100644
--- a/core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java
+++ b/core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java
@@ -17,9 +17,7 @@
package org.jivesoftware.smack;
-import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.Bind;
-import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Session;
import org.jivesoftware.smack.sasl.*;
@@ -443,37 +441,12 @@ public class SASLAuthentication implements UserAuthentication {
Bind bindResource = new Bind();
bindResource.setResource(resource);
- PacketCollector collector = connection
- .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());
- }
+ Bind response = (Bind) connection.createPacketCollectorAndSend(bindResource).nextResultOrThrow();
String userJID = response.getJid();
if (sessionSupported) {
Session session = new Session();
- collector = connection.createPacketCollector(new PacketIDFilter(session.getPacketID()));
- // 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());
- }
+ connection.createPacketCollectorAndSend(session).nextResultOrThrow();
}
return userJID;
}
diff --git a/core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java b/core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java
index 6c61007fe..009c5e6cf 100644
--- a/core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java
+++ b/core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java
@@ -58,7 +58,7 @@ public final class SmackConfiguration {
private static InputStream configFileStream;
- private static int packetReplyTimeout = 5000;
+ private static int defaultPacketReplyTimeout = 5000;
private static List defaultMechs = new ArrayList();
private static boolean localSocks5ProxyEnabled = true;
@@ -150,14 +150,14 @@ public final class SmackConfiguration {
*
* @return the milliseconds to wait for a response from the server
*/
- public static int getPacketReplyTimeout() {
+ public static int getDefaultPacketReplyTimeout() {
initialize();
// The timeout value must be greater than 0 otherwise we will answer the default value
- if (packetReplyTimeout <= 0) {
- packetReplyTimeout = 5000;
+ if (defaultPacketReplyTimeout <= 0) {
+ 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
*/
- public static void setPacketReplyTimeout(int timeout) {
+ public static void setDefaultPacketReplyTimeout(int timeout) {
initialize();
if (timeout <= 0) {
throw new IllegalArgumentException();
}
- packetReplyTimeout = timeout;
+ defaultPacketReplyTimeout = timeout;
}
/**
@@ -442,8 +442,8 @@ public final class SmackConfiguration {
else if (parser.getName().equals("optionalStartupClasses")) {
parseClassesToLoad(parser, true);
}
- else if (parser.getName().equals("packetReplyTimeout")) {
- packetReplyTimeout = parseIntProperty(parser, packetReplyTimeout);
+ else if (parser.getName().equals("defaultPacketReplyTimeout")) {
+ defaultPacketReplyTimeout = parseIntProperty(parser, defaultPacketReplyTimeout);
}
else if (parser.getName().equals("mechName")) {
defaultMechs.add(parser.nextText());
diff --git a/core/src/main/java/org/jivesoftware/smack/XMPPConnection.java b/core/src/main/java/org/jivesoftware/smack/XMPPConnection.java
index a84bc0fe7..902dc6a28 100644
--- a/core/src/main/java/org/jivesoftware/smack/XMPPConnection.java
+++ b/core/src/main/java/org/jivesoftware/smack/XMPPConnection.java
@@ -367,7 +367,7 @@ public class XMPPConnection extends Connection {
if (!roster.rosterInitialized) {
try {
synchronized (roster) {
- long waitTime = SmackConfiguration.getPacketReplyTimeout();
+ long waitTime = SmackConfiguration.getDefaultPacketReplyTimeout();
long start = System.currentTimeMillis();
while (!roster.rosterInitialized) {
if (waitTime <= 0) {
@@ -930,7 +930,7 @@ public class XMPPConnection extends Connection {
// Wait until compression is being used or a timeout happened
synchronized (this) {
try {
- this.wait(SmackConfiguration.getPacketReplyTimeout() * 5);
+ this.wait(SmackConfiguration.getDefaultPacketReplyTimeout() * 5);
}
catch (InterruptedException e) {
// Ignore.
diff --git a/core/src/main/java/org/jivesoftware/smack/util/SyncPacketSend.java b/core/src/main/java/org/jivesoftware/smack/util/SyncPacketSend.java
deleted file mode 100644
index 386ddb6d8..000000000
--- a/core/src/main/java/org/jivesoftware/smack/util/SyncPacketSend.java
+++ /dev/null
@@ -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());
- }
-}
diff --git a/core/src/main/resources/org.jivesoftware.smack/smack-config.xml b/core/src/main/resources/org.jivesoftware.smack/smack-config.xml
index b475bbb1d..f998360f5 100644
--- a/core/src/main/resources/org.jivesoftware.smack/smack-config.xml
+++ b/core/src/main/resources/org.jivesoftware.smack/smack-config.xml
@@ -2,8 +2,8 @@
-
- 5000
+
+ 5000true
diff --git a/core/src/test/java/org/jivesoftware/smack/PacketCollectorTest.java b/core/src/test/java/org/jivesoftware/smack/PacketCollectorTest.java
index a7fe81cd0..104595e84 100644
--- a/core/src/test/java/org/jivesoftware/smack/PacketCollectorTest.java
+++ b/core/src/test/java/org/jivesoftware/smack/PacketCollectorTest.java
@@ -38,10 +38,10 @@ public class PacketCollectorTest
}
// Assert that '0' has rolled off
- assertEquals("1", collector.nextResult().getPacketID());
- assertEquals("2", collector.nextResult().getPacketID());
- assertEquals("3", collector.nextResult().getPacketID());
- assertEquals("4", collector.nextResult().getPacketID());
+ assertEquals("1", collector.nextResultBlockForever().getPacketID());
+ assertEquals("2", collector.nextResultBlockForever().getPacketID());
+ assertEquals("3", collector.nextResultBlockForever().getPacketID());
+ assertEquals("4", collector.nextResultBlockForever().getPacketID());
assertEquals("5", collector.pollResult().getPacketID());
assertNull(collector.pollResult());
@@ -51,10 +51,10 @@ public class PacketCollectorTest
collector.processPacket(testPacket);
}
- assertEquals("10", collector.nextResult().getPacketID());
- assertEquals("11", collector.nextResult().getPacketID());
- assertEquals("12", collector.nextResult().getPacketID());
- assertEquals("13", collector.nextResult().getPacketID());
+ assertEquals("10", collector.nextResultBlockForever().getPacketID());
+ assertEquals("11", collector.nextResultBlockForever().getPacketID());
+ assertEquals("12", collector.nextResultBlockForever().getPacketID());
+ assertEquals("13", collector.nextResultBlockForever().getPacketID());
assertEquals("14", collector.pollResult().getPacketID());
assertNull(collector.pollResult());
@@ -87,7 +87,8 @@ public class PacketCollectorTest
catch (InterruptedException e)
{
}
- Packet packet = collector.nextResult();
+ @SuppressWarnings("unused")
+ Packet packet = collector.nextResultBlockForever();
// System.out.println(Thread.currentThread().getName() + " packet: " + packet);
}
}
diff --git a/core/src/test/java/org/jivesoftware/smack/SmackConfigurationTest.java b/core/src/test/java/org/jivesoftware/smack/SmackConfigurationTest.java
index 1bba3c0f4..d8cbd688d 100644
--- a/core/src/test/java/org/jivesoftware/smack/SmackConfigurationTest.java
+++ b/core/src/test/java/org/jivesoftware/smack/SmackConfigurationTest.java
@@ -25,7 +25,7 @@ public class SmackConfigurationTest {
@Test
public void testSmackConfiguration() {
try {
- SmackConfiguration.getPacketReplyTimeout();
+ SmackConfiguration.getDefaultPacketReplyTimeout();
} catch (Throwable t) {
fail("SmackConfiguration threw Throwable");
}
diff --git a/experimental/src/main/java/org/jivesoftware/smackx/carbons/CarbonManager.java b/experimental/src/main/java/org/jivesoftware/smackx/carbons/CarbonManager.java
index 932555d4b..541309c77 100644
--- a/experimental/src/main/java/org/jivesoftware/smackx/carbons/CarbonManager.java
+++ b/experimental/src/main/java/org/jivesoftware/smackx/carbons/CarbonManager.java
@@ -23,9 +23,7 @@ import java.util.WeakHashMap;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.ConnectionCreationListener;
-import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.PacketListener;
-import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
@@ -147,43 +145,36 @@ public class CarbonManager {
* @param new_state whether carbons should be enabled or disabled
*
* @return true if the operation was successful
+ * @throws XMPPException
*/
- public boolean setCarbonsEnabled(final boolean new_state) {
- if (enabled_state == new_state)
- return true;
+ public void setCarbonsEnabled(final boolean new_state) throws XMPPException {
+ if (enabled_state == new_state) return;
Connection connection = weakRefConnection.get();
IQ setIQ = carbonsEnabledIQ(new_state);
- PacketCollector collector =
- 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;
- return true;
- }
- return false;
+ connection.createPacketCollectorAndSend(setIQ).nextResultOrThrow();
+ enabled_state = new_state;
}
/**
* Helper method to enable carbons.
*
* @return true if the operation was successful
+ * @throws XMPPException
*/
- public boolean enableCarbons() {
- return setCarbonsEnabled(true);
+ public void enableCarbons() throws XMPPException {
+ setCarbonsEnabled(true);
}
/**
* Helper method to disable carbons.
*
* @return true if the operation was successful
+ * @throws XMPPException
*/
- public boolean disableCarbons() {
- return setCarbonsEnabled(false);
+ public void disableCarbons() throws XMPPException {
+ setCarbonsEnabled(false);
}
/**
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java b/extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java
index 21bca28d2..d6ad5e51a 100644
--- a/extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java
@@ -30,7 +30,6 @@ import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.XMPPError;
-import org.jivesoftware.smack.util.SyncPacketSend;
import org.jivesoftware.smackx.bytestreams.BytestreamListener;
import org.jivesoftware.smackx.bytestreams.BytestreamManager;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
@@ -428,7 +427,7 @@ public class InBandBytestreamManager implements BytestreamManager {
byteStreamRequest.setTo(targetJID);
// sending packet will throw exception on timeout or error reply
- SyncPacketSend.getReply(this.connection, byteStreamRequest);
+ connection.createPacketCollectorAndSend(byteStreamRequest).nextResultOrThrow();
InBandBytestreamSession inBandBytestreamSession = new InBandBytestreamSession(
this.connection, byteStreamRequest, targetJID);
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java b/extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java
index 482a0e37e..ab5909000 100644
--- a/extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java
@@ -36,7 +36,6 @@ import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.util.StringUtils;
-import org.jivesoftware.smack.util.SyncPacketSend;
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Close;
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.setTo(this.remoteJID);
try {
- SyncPacketSend.getReply(this.connection, close);
+ connection.createPacketCollectorAndSend(close).nextResultOrThrow();
}
catch (XMPPException e) {
throw new IOException("Error while closing stream: " + e.getMessage());
@@ -763,7 +762,7 @@ public class InBandBytestreamSession implements BytestreamSession {
iq.setTo(remoteJID);
try {
- SyncPacketSend.getReply(connection, iq);
+ connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
}
catch (XMPPException e) {
// close session unless it is already closed
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java b/extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java
index 67210d6a1..0e2299df8 100644
--- a/extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java
@@ -36,7 +36,6 @@ import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.XMPPError;
-import org.jivesoftware.smack.util.SyncPacketSend;
import org.jivesoftware.smackx.bytestreams.BytestreamListener;
import org.jivesoftware.smackx.bytestreams.BytestreamManager;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
@@ -481,7 +480,7 @@ public final class Socks5BytestreamManager implements BytestreamManager {
Bytestream initiation = createBytestreamInitiation(sessionID, targetJID, streamHosts);
// send initiation packet
- Packet response = SyncPacketSend.getReply(this.connection, initiation,
+ Packet response = connection.createPacketCollectorAndSend(initiation).nextResultOrThrow(
getTargetResponseTimeout());
// extract used stream host from response
@@ -612,8 +611,8 @@ public final class Socks5BytestreamManager implements BytestreamManager {
for (String proxy : proxies) {
Bytestream streamHostRequest = createStreamHostRequest(proxy);
try {
- Bytestream response = (Bytestream) SyncPacketSend.getReply(this.connection,
- streamHostRequest);
+ Bytestream response = (Bytestream) connection.createPacketCollectorAndSend(
+ streamHostRequest).nextResultOrThrow();
streamHosts.addAll(response.getStreamHosts());
}
catch (XMPPException e) {
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java b/extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java
index 1359bd4e1..3b08468ce 100644
--- a/extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java
@@ -23,7 +23,6 @@ import java.util.concurrent.TimeoutException;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
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.StreamHost;
@@ -97,8 +96,8 @@ class Socks5ClientForInitiator extends Socks5Client {
*/
private void activate() throws XMPPException {
Bytestream activate = createStreamHostActivation();
- // if activation fails #getReply throws an exception
- SyncPacketSend.getReply(this.connection, activate);
+ // if activation fails #nextResultOrThrow() throws an exception
+ connection.createPacketCollectorAndSend(activate).nextResultOrThrow();
}
/**
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/commands/RemoteCommand.java b/extensions/src/main/java/org/jivesoftware/smackx/commands/RemoteCommand.java
index eea0804c1..2fb866c95 100755
--- a/extensions/src/main/java/org/jivesoftware/smackx/commands/RemoteCommand.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/commands/RemoteCommand.java
@@ -17,13 +17,10 @@
package org.jivesoftware.smackx.commands;
-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.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
-import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smackx.commands.packet.AdHocCommandData;
import org.jivesoftware.smackx.xdata.Form;
@@ -79,7 +76,7 @@ public class RemoteCommand extends AdHocCommand {
this.connection = connection;
this.jid = jid;
this.setNode(node);
- this.packetReplyTimeout = SmackConfiguration.getPacketReplyTimeout();
+ this.packetReplyTimeout = SmackConfiguration.getDefaultPacketReplyTimeout();
}
@Override
@@ -148,23 +145,9 @@ public class RemoteCommand extends AdHocCommand {
data.setForm(form.getDataFormToSend());
}
- PacketCollector collector = connection.createPacketCollector(
- new PacketIDFilter(data.getPacketID()));
+ AdHocCommandData responseData = (AdHocCommandData) connection.createPacketCollectorAndSend(
+ 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();
super.setData(responseData);
}
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java b/extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java
index c23f1689c..f5f44e938 100644
--- a/extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java
@@ -19,7 +19,6 @@ package org.jivesoftware.smackx.disco;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.filter.PacketFilter;
-import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.IQ;
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
* disco request.
*/
+ @SuppressWarnings("deprecation")
public void setIdentityType(String type) {
identity.setType(type);
renewEntityCapsVersion();
@@ -541,22 +541,8 @@ public class ServiceDiscoveryManager {
disco.setTo(entityID);
disco.setNode(node);
- // Create a packet collector to listen for a response.
- PacketCollector collector =
- connection.createPacketCollector(new PacketIDFilter(disco.getPacketID()));
+ Packet result = connection.createPacketCollectorAndSend(disco).nextResultOrThrow();
- 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;
}
@@ -591,22 +577,7 @@ public class ServiceDiscoveryManager {
disco.setTo(entityID);
disco.setNode(node);
- // Create a packet collector to listen for a response.
- 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());
- }
+ Packet result = connection.createPacketCollectorAndSend(disco).nextResultOrThrow();
return (DiscoverItems) result;
}
@@ -673,22 +644,7 @@ public class ServiceDiscoveryManager {
discoverItems.setTo(entityID);
discoverItems.setNode(node);
- // Create a packet collector to listen for a response.
- 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());
- }
+ connection.createPacketCollectorAndSend(discoverItems).nextResultOrThrow();
}
/**
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java b/extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java
index cde211bf0..b791de15c 100644
--- a/extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java
@@ -17,7 +17,6 @@
package org.jivesoftware.smackx.filetransfer;
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.OrFilter;
@@ -171,8 +170,7 @@ public class FaultTolerantNegotiator extends StreamNegotiator {
}
public InputStream call() throws Exception {
- Packet streamInitiation = collector.nextResult(
- SmackConfiguration.getPacketReplyTimeout() * 2);
+ Packet streamInitiation = collector.nextResult();
if (streamInitiation == null) {
throw new XMPPException("No response from remote client");
}
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java b/extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java
index 3b9c66336..b08ba7a4b 100644
--- a/extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java
@@ -17,7 +17,6 @@
package org.jivesoftware.smackx.filetransfer;
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;
@@ -87,8 +86,7 @@ public abstract class StreamNegotiator {
.createPacketCollector(getInitiationPacketFilter(initiation.getFrom(), initiation.getSessionID()));
connection.sendPacket(response);
- Packet streamMethodInitiation = collector
- .nextResult(SmackConfiguration.getPacketReplyTimeout());
+ Packet streamMethodInitiation = collector.nextResult();
collector.cancel();
if (streamMethodInitiation == null) {
throw new XMPPException("No response from file transfer initiator");
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/iqlast/LastActivityManager.java b/extensions/src/main/java/org/jivesoftware/smackx/iqlast/LastActivityManager.java
index 381ec3fb0..c5d39eb1a 100644
--- a/extensions/src/main/java/org/jivesoftware/smackx/iqlast/LastActivityManager.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/iqlast/LastActivityManager.java
@@ -19,13 +19,10 @@ package org.jivesoftware.smackx.iqlast;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.ConnectionCreationListener;
-import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.PacketListener;
-import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.IQTypeFilter;
-import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Message;
@@ -199,19 +196,7 @@ public class LastActivityManager {
LastActivity activity = new LastActivity();
activity.setTo(jid);
- PacketCollector collector = con.createPacketCollector(new PacketIDFilter(activity.getPacketID()));
- 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());
- }
+ LastActivity response = (LastActivity) con.createPacketCollectorAndSend(activity).nextResultOrThrow();
return response;
}
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/iqlast/packet/LastActivity.java b/extensions/src/main/java/org/jivesoftware/smackx/iqlast/packet/LastActivity.java
index 36aa7f4ed..1b19dbc7a 100644
--- a/extensions/src/main/java/org/jivesoftware/smackx/iqlast/packet/LastActivity.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/iqlast/packet/LastActivity.java
@@ -19,11 +19,8 @@ package org.jivesoftware.smackx.iqlast.packet;
import java.io.IOException;
-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.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.util.StringUtils;
@@ -143,19 +140,7 @@ public class LastActivity extends IQ {
jid = StringUtils.parseBareAddress(jid);
activity.setTo(jid);
- PacketCollector collector = con.createPacketCollector(new PacketIDFilter(activity.getPacketID()));
- 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());
- }
+ LastActivity response = (LastActivity) con.createPacketCollectorAndSend(activity).nextResultOrThrow();
return response;
}
}
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/iqprivate/PrivateDataManager.java b/extensions/src/main/java/org/jivesoftware/smackx/iqprivate/PrivateDataManager.java
index 108260148..b56b0de7a 100644
--- a/extensions/src/main/java/org/jivesoftware/smackx/iqprivate/PrivateDataManager.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/iqprivate/PrivateDataManager.java
@@ -17,11 +17,8 @@
package org.jivesoftware.smackx.iqprivate;
-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.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.iqprivate.packet.DefaultPrivateData;
@@ -191,25 +188,9 @@ public class PrivateDataManager {
privateDataGet.setTo(user);
}
- // Setup a listener for the reply to the set operation.
- String packetID = privateDataGet.getPacketID();
- PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(packetID));
-
- // 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();
+ PrivateDataResult response = (PrivateDataResult) connection.createPacketCollectorAndSend(
+ privateDataGet).nextResultOrThrow();
+ return response.getPrivateData();
}
/**
@@ -237,24 +218,7 @@ public class PrivateDataManager {
privateDataSet.setTo(user);
}
- // Setup a listener for the reply to the set operation.
- 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());
- }
+ connection.createPacketCollectorAndSend(privateDataSet).nextResultOrThrow();
}
/**
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java b/extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java
index 1108d43e8..1f761c77c 100644
--- a/extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java
@@ -47,7 +47,6 @@ import org.jivesoftware.smack.filter.FromMatchesFilter;
import org.jivesoftware.smack.filter.MessageTypeFilter;
import org.jivesoftware.smack.filter.PacketExtensionFilter;
import org.jivesoftware.smack.filter.PacketFilter;
-import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Message;
@@ -355,17 +354,8 @@ public class MultiUserChat {
// Send create & join packet.
connection.sendPacket(joinPresence);
// Wait up to a certain number of seconds for a reply.
- Presence presence =
- (Presence) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
- // Stop queuing results
- response.cancel();
+ Presence presence = (Presence) response.nextResultOrThrow();
- 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
this.nickname = nickname;
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.
*/
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.
*/
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 PacketTypeFilter(Presence.class));
PacketCollector response = null;
- Presence presence;
- try {
- response = connection.createPacketCollector(responseFilter);
- // Send join packet.
- connection.sendPacket(joinPresence);
- // Wait up to a certain number of seconds for a reply.
- presence = (Presence) response.nextResult(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());
- }
+ response = connection.createPacketCollector(responseFilter);
+ // Send join packet.
+ connection.sendPacket(joinPresence);
+ // Wait up to a certain number of seconds for a reply.
+ response.nextResultOrThrow(timeout);
+
this.nickname = nickname;
joined = true;
userHasJoined();
@@ -564,22 +540,7 @@ public class MultiUserChat {
iq.setTo(room);
iq.setType(IQ.Type.GET);
- // Filter packets looking for an answer from the server.
- 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());
- }
+ IQ answer = (IQ) connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
return Form.getFormFrom(answer);
}
@@ -597,22 +558,7 @@ public class MultiUserChat {
iq.setType(IQ.Type.SET);
iq.addExtension(form.getDataFormToSend());
- // Filter packets looking for an answer from the server.
- 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());
- }
+ connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
}
/**
@@ -634,18 +580,7 @@ public class MultiUserChat {
reg.setType(IQ.Type.GET);
reg.setTo(room);
- PacketFilter filter =
- 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());
- }
+ IQ result = (IQ) connection.createPacketCollectorAndSend(reg).nextResultOrThrow();
return Form.getFormFrom(result);
}
@@ -669,18 +604,7 @@ public class MultiUserChat {
reg.setTo(room);
reg.addExtension(form.getDataFormToSend());
- PacketFilter filter =
- 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());
- }
+ connection.createPacketCollectorAndSend(reg).nextResultOrThrow();
}
/**
@@ -706,22 +630,8 @@ public class MultiUserChat {
destroy.setJid(alternateJID);
iq.setDestroy(destroy);
- // Wait for a presence packet back from the server.
- 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();
+ connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
- if (answer == null) {
- throw new XMPPException("No response from server.");
- }
- else if (answer.getError() != null) {
- throw new XMPPException(answer.getError());
- }
// Reset occupant information.
occupantsMap.clear();
nickname = null;
@@ -1013,18 +923,10 @@ public class MultiUserChat {
PacketCollector response = connection.createPacketCollector(responseFilter);
// Send join packet.
connection.sendPacket(joinPresence);
- // Wait up to a certain number of seconds for a reply.
- Presence presence =
- (Presence) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
- // Stop queuing results
- response.cancel();
+ // Wait up to a certain number of seconds for a reply. If there is a negative reply, an
+ // exception will be thrown
+ response.nextResultOrThrow();
- if (presence == null) {
- throw new XMPPException("No response from server.");
- }
- else if (presence.getError() != null) {
- throw new XMPPException(presence.getError());
- }
this.nickname = nickname;
}
@@ -1385,22 +1287,7 @@ public class MultiUserChat {
item.setJid(jid);
iq.addItem(item);
- // Wait for a response packet back from the server.
- 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());
- }
+ connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
}
private void changeAffiliationByOwner(Collection jids, String affiliation)
@@ -1415,22 +1302,7 @@ public class MultiUserChat {
iq.addItem(item);
}
- // Wait for a response packet back from the server.
- 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());
- }
+ connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
}
/**
@@ -1452,22 +1324,7 @@ public class MultiUserChat {
item.setReason(reason);
iq.addItem(item);
- // Wait for a response packet back from the server.
- 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());
- }
+ connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
}
private void changeAffiliationByAdmin(Collection jids, String affiliation)
@@ -1482,22 +1339,7 @@ public class MultiUserChat {
iq.addItem(item);
}
- // Wait for a response packet back from the server.
- 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());
- }
+ connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
}
private void changeRole(String nickname, String role, String reason) throws XMPPException {
@@ -1510,22 +1352,7 @@ public class MultiUserChat {
item.setReason(reason);
iq.addItem(item);
- // Wait for a response packet back from the server.
- 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());
- }
+ connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
}
private void changeRole(Collection nicknames, String role) throws XMPPException {
@@ -1539,22 +1366,7 @@ public class MultiUserChat {
iq.addItem(item);
}
- // Wait for a response packet back from the server.
- 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());
- }
+ connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
}
/**
@@ -1703,22 +1515,8 @@ public class MultiUserChat {
MUCOwner.Item item = new MUCOwner.Item(affiliation);
iq.addItem(item);
- // Wait for a response packet back from the server.
- 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();
+ MUCOwner answer = (MUCOwner) connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
- 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
List affiliates = new ArrayList();
for (Iterator it = answer.getItems(); it.hasNext();) {
@@ -1744,22 +1542,8 @@ public class MultiUserChat {
MUCAdmin.Item item = new MUCAdmin.Item(affiliation, null);
iq.addItem(item);
- // Wait for a response packet back from the server.
- 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();
+ MUCAdmin answer = (MUCAdmin) connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
- 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
List affiliates = new ArrayList();
for (Iterator it = answer.getItems(); it.hasNext();) {
@@ -1806,22 +1590,7 @@ public class MultiUserChat {
MUCAdmin.Item item = new MUCAdmin.Item(null, role);
iq.addItem(item);
- // Wait for a response packet back from the server.
- 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());
- }
+ MUCAdmin answer = (MUCAdmin) connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
// Get the list of participants from the server's answer
List participants = new ArrayList();
for (Iterator it = answer.getItems(); it.hasNext();) {
@@ -1968,17 +1737,7 @@ public class MultiUserChat {
// Send change subject packet.
connection.sendPacket(message);
// Wait up to a certain number of seconds for a reply.
- Message answer =
- (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());
- }
+ response.nextResultOrThrow();
}
/**
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java b/extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java
index 76aa750a6..1a668e3fa 100644
--- a/extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java
@@ -21,8 +21,10 @@ 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.*;
-import org.jivesoftware.smack.packet.IQ;
+import org.jivesoftware.smack.filter.AndFilter;
+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.Packet;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
@@ -139,9 +141,8 @@ public class OfflineMessageManager {
item.setAction("view");
request.addItem(item);
}
- // Filter packets looking for an answer from the server.
- PacketFilter responseFilter = new PacketIDFilter(request.getPacketID());
- PacketCollector response = connection.createPacketCollector(responseFilter);
+ connection.createPacketCollectorAndSend(request).nextResultOrThrow();
+
// Filter offline messages that were requested by this request
PacketFilter messageFilter = new AndFilter(packetFilter, new PacketFilter() {
public boolean accept(Packet packet) {
@@ -151,27 +152,13 @@ public class OfflineMessageManager {
}
});
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
- Message message = (Message) messageCollector.nextResult(
- SmackConfiguration.getPacketReplyTimeout());
+ Message message = (Message) messageCollector.nextResult();
while (message != null) {
messages.add(message);
message =
(Message) messageCollector.nextResult(
- SmackConfiguration.getPacketReplyTimeout());
+ SmackConfiguration.getDefaultPacketReplyTimeout());
}
// Stop queuing offline messages
messageCollector.cancel();
@@ -191,32 +178,16 @@ public class OfflineMessageManager {
List messages = new ArrayList();
OfflineMessageRequest request = new OfflineMessageRequest();
request.setFetch(true);
- // Filter packets looking for an answer from the server.
- PacketFilter responseFilter = new PacketIDFilter(request.getPacketID());
- PacketCollector response = connection.createPacketCollector(responseFilter);
- // Filter offline messages that were requested by this request
+ connection.createPacketCollectorAndSend(request).nextResultOrThrow();
+
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
- Message message = (Message) messageCollector.nextResult(
- SmackConfiguration.getPacketReplyTimeout());
+ Message message = (Message) messageCollector.nextResult();
while (message != null) {
messages.add(message);
message =
(Message) messageCollector.nextResult(
- SmackConfiguration.getPacketReplyTimeout());
+ SmackConfiguration.getDefaultPacketReplyTimeout());
}
// Stop queuing offline messages
messageCollector.cancel();
@@ -238,21 +209,7 @@ public class OfflineMessageManager {
item.setAction("remove");
request.addItem(item);
}
- // Filter packets looking for an answer from the server.
- 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());
- }
+ connection.createPacketCollectorAndSend(request).nextResultOrThrow();
}
/**
@@ -264,20 +221,6 @@ public class OfflineMessageManager {
public void deleteMessages() throws XMPPException {
OfflineMessageRequest request = new OfflineMessageRequest();
request.setPurge(true);
- // Filter packets looking for an answer from the server.
- 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());
- }
+ connection.createPacketCollectorAndSend(request).nextResultOrThrow();
}
}
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java b/extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java
index 7ef616e88..5d71f04af 100644
--- a/extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java
@@ -34,7 +34,6 @@ import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.IQ.Type;
-import org.jivesoftware.smack.util.SyncPacketSend;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.jivesoftware.smackx.ping.packet.Ping;
@@ -120,7 +119,7 @@ public class PingManager {
Ping ping = new Ping(jid);
Connection connection = weakRefConnection.get();
try {
- SyncPacketSend.getReply(connection, ping);
+ connection.createPacketCollectorAndSend(ping).nextResultOrThrow();
}
catch (XMPPException exc) {
@@ -137,7 +136,7 @@ public class PingManager {
* @return true if a reply was received from the entity, false otherwise.
*/
public boolean ping(String jid) {
- return ping(jid, SmackConfiguration.getPacketReplyTimeout());
+ return ping(jid, SmackConfiguration.getDefaultPacketReplyTimeout());
}
/**
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/privacy/PrivacyListManager.java b/extensions/src/main/java/org/jivesoftware/smackx/privacy/PrivacyListManager.java
index c8b51ea81..f3468be6d 100644
--- a/extensions/src/main/java/org/jivesoftware/smackx/privacy/PrivacyListManager.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/privacy/PrivacyListManager.java
@@ -18,9 +18,7 @@ package org.jivesoftware.smackx.privacy;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.ConnectionCreationListener;
-import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.PacketListener;
-import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.*;
import org.jivesoftware.smack.packet.IQ;
@@ -153,68 +151,30 @@ public class PrivacyListManager {
// The request is a get iq type
requestPrivacy.setType(Privacy.Type.GET);
requestPrivacy.setFrom(this.getUser());
-
- // Filter packets looking for an answer from the server.
- 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());
- }
+ Privacy privacyAnswer = (Privacy) connection.createPacketCollectorAndSend(requestPrivacy).nextResultOrThrow();
return privacyAnswer;
}
-
- /**
- * Send the {@link Privacy} packet to the server in order to modify the server privacy and
- * waits for the answer.
- *
- * @param requestPrivacy is the {@link Privacy} packet configured properly whose xml will be sent
- * to 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.
- */
- private Packet setRequest(Privacy requestPrivacy) throws XMPPException {
+
+ /**
+ * Send the {@link Privacy} packet to the server in order to modify the server privacy and waits
+ * for the answer.
+ *
+ * @param requestPrivacy is the {@link Privacy} packet configured properly whose xml will be
+ * sent to 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.
+ */
+ private Packet setRequest(Privacy requestPrivacy) throws XMPPException {
Connection connection = PrivacyListManager.this.connection.get();
- if (connection == null) throw new XMPPException("Connection instance already gc'ed");
- // The request is a get iq type
- requestPrivacy.setType(Privacy.Type.SET);
- requestPrivacy.setFrom(this.getUser());
-
- // Filter packets looking for an answer from the server.
- 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();
+ if (connection == null)
+ throw new XMPPException("Connection instance already gc'ed");
+ // The request is a get iq type
+ requestPrivacy.setType(Privacy.Type.SET);
+ requestPrivacy.setFrom(this.getUser());
- // 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 connection.createPacketCollectorAndSend(requestPrivacy).nextResultOrThrow();
+ }
/**
* Answer a privacy containing the list structre without {@link PrivacyItem}.
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/pubsub/LeafNode.java b/extensions/src/main/java/org/jivesoftware/smackx/pubsub/LeafNode.java
index a650bba21..af34e99bf 100644
--- a/extensions/src/main/java/org/jivesoftware/smackx/pubsub/LeafNode.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/pubsub/LeafNode.java
@@ -25,7 +25,6 @@ import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
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
@@ -56,7 +55,7 @@ public class LeafNode extends Node
DiscoverItems items = new DiscoverItems();
items.setTo(to);
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 result = (PubSub)SyncPacketSend.getReply(con, request);
+ PubSub result = (PubSub) con.createPacketCollectorAndSend(request).nextResultOrThrow();
ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS);
return (List)itemsElem.getItems();
}
@@ -94,7 +93,7 @@ public class LeafNode extends Node
{
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);
return (List)itemsElem.getItems();
}
@@ -124,7 +123,7 @@ public class LeafNode extends Node
}
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);
return (List)itemsElem.getItems();
}
@@ -144,7 +143,7 @@ public class LeafNode extends Node
{
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);
return (List)itemsElem.getItems();
}
@@ -167,7 +166,7 @@ public class LeafNode extends Node
{
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);
return (List)itemsElem.getItems();
}
@@ -253,7 +252,7 @@ public class LeafNode extends Node
{
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(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());
- SyncPacketSend.getReply(con, request);
+ con.createPacketCollectorAndSend(request).nextResultOrThrow();
}
/**
@@ -357,6 +356,6 @@ public class LeafNode extends Node
items.add(new Item(id));
}
PubSub request = createPubsubPacket(Type.SET, new ItemsExtension(ItemsExtension.ItemsElementType.retract, getId(), items));
- SyncPacketSend.getReply(con, request);
+ con.createPacketCollectorAndSend(request).nextResultOrThrow();
}
}
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java b/extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java
index 5944976ea..67337d060 100644
--- a/extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java
@@ -38,7 +38,6 @@ import org.jivesoftware.smackx.pubsub.listener.ItemEventListener;
import org.jivesoftware.smackx.pubsub.listener.NodeConfigListener;
import org.jivesoftware.smackx.pubsub.packet.PubSub;
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.shim.packet.Header;
import org.jivesoftware.smackx.shim.packet.HeadersExtension;
@@ -109,7 +108,7 @@ abstract public class Node
throws XMPPException
{
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();
info.setTo(to);
info.setNode(getId());
- return (DiscoverInfo)SyncPacketSend.getReply(con, info);
+ return (DiscoverInfo) con.createPacketCollectorAndSend(info).nextResultOrThrow();
}
/**
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java b/extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java
index d56cc3a92..a02c2f987 100644
--- a/extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java
@@ -30,7 +30,6 @@ import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
import org.jivesoftware.smackx.pubsub.packet.PubSub;
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.xdata.Form;
import org.jivesoftware.smackx.xdata.FormField;
@@ -164,7 +163,7 @@ final public class PubSubManager
info.setTo(to);
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()))
node = new LeafNode(con, id);
@@ -198,7 +197,7 @@ final public class PubSubManager
if (nodeId != null)
items.setNode(nodeId);
items.setTo(to);
- DiscoverItems nodeItems = (DiscoverItems)SyncPacketSend.getReply(con, items);
+ DiscoverItems nodeItems = (DiscoverItems) con.createPacketCollectorAndSend(items).nextResultOrThrow();
return nodeItems;
}
@@ -315,7 +314,7 @@ final public class PubSubManager
static Packet sendPubsubPacket(Connection con, String to, Type type, PacketExtension ext, PubSubNamespace ns)
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)
@@ -327,7 +326,7 @@ final public class PubSubManager
static Packet sendPubsubPacket(Connection con, String to, Type type, PubSub packet, PubSubNamespace ns)
throws XMPPException
{
- return SyncPacketSend.getReply(con, packet);
+ return con.createPacketCollectorAndSend(packet).nextResultOrThrow();
}
}
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/SyncPacketSend.java b/extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/SyncPacketSend.java
deleted file mode 100644
index 291bfdbe6..000000000
--- a/extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/SyncPacketSend.java
+++ /dev/null
@@ -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());
- }
-}
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java b/extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java
index affb0df2c..3b860548c 100644
--- a/extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java
@@ -16,11 +16,8 @@
*/
package org.jivesoftware.smackx.search;
-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.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.util.PacketParserUtils;
@@ -69,19 +66,7 @@ public class UserSearch extends IQ {
search.setType(IQ.Type.GET);
search.setTo(searchService);
- PacketCollector collector = con.createPacketCollector(new PacketIDFilter(search.getPacketID()));
- 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());
- }
+ IQ response = (IQ) con.createPacketCollectorAndSend(search).nextResultOrThrow();
return Form.getFormFrom(response);
}
@@ -101,22 +86,7 @@ public class UserSearch extends IQ {
search.setTo(searchService);
search.addExtension(searchForm.getDataFormToSend());
- PacketCollector collector = con.createPacketCollector(new PacketIDFilter(search.getPacketID()));
-
- 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);
- }
-
-
+ IQ response = (IQ) con.createPacketCollectorAndSend(search).nextResultOrThrow();
return ReportedData.getReportedDataFrom(response);
}
@@ -136,25 +106,8 @@ public class UserSearch extends IQ {
search.setType(IQ.Type.SET);
search.setTo(searchService);
- PacketCollector collector = con.createPacketCollector(new PacketIDFilter(search.getPacketID()));
-
- 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;
+ SimpleUserSearch response = (SimpleUserSearch) con.createPacketCollectorAndSend(search).nextResultOrThrow();
+ return response.getReportedData();
}
/**
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/sharedgroups/SharedGroupManager.java b/extensions/src/main/java/org/jivesoftware/smackx/sharedgroups/SharedGroupManager.java
index c2dc5477f..3216a1bda 100644
--- a/extensions/src/main/java/org/jivesoftware/smackx/sharedgroups/SharedGroupManager.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/sharedgroups/SharedGroupManager.java
@@ -17,10 +17,7 @@
package org.jivesoftware.smackx.sharedgroups;
import org.jivesoftware.smack.Connection;
-import org.jivesoftware.smack.PacketCollector;
-import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPException;
-import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.sharedgroups.packet.SharedGroupsInfo;
@@ -48,22 +45,7 @@ public class SharedGroupManager {
SharedGroupsInfo info = new SharedGroupsInfo();
info.setType(IQ.Type.GET);
- // Create a packet collector to listen for a response.
- PacketCollector collector =
- 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();
+ SharedGroupsInfo result = (SharedGroupsInfo) connection.createPacketCollectorAndSend(info).nextResultOrThrow();
+ return result.getGroups();
}
}
diff --git a/extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java b/extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java
index 08a98e54d..11c633692 100644
--- a/extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java
+++ b/extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java
@@ -34,13 +34,8 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.Connection;
-import org.jivesoftware.smack.PacketCollector;
-import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPException;
-import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
-import org.jivesoftware.smack.packet.Packet;
-import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.util.StringUtils;
/**
@@ -526,19 +521,7 @@ public class VCard extends IQ {
setType(IQ.Type.SET);
setFrom(connection.getUser());
- PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(getPacketID()));
- 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());
- }
+ connection.createPacketCollectorAndSend(this).nextResultOrThrow();
}
/**
@@ -564,29 +547,7 @@ public class VCard extends IQ {
private void doLoad(Connection connection, String user) throws XMPPException {
setType(Type.GET);
- PacketCollector collector = connection.createPacketCollector(
- 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;
- }
-
+ VCard result = (VCard) connection.createPacketCollectorAndSend(this).nextResultOrThrow();
copyFieldsFrom(result);
}
diff --git a/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManagerTest.java b/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManagerTest.java
index 551357304..77e4d2279 100644
--- a/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManagerTest.java
+++ b/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManagerTest.java
@@ -54,9 +54,10 @@ public class InBandBytestreamManagerTest {
/**
* Initialize fields used in the tests.
+ * @throws XMPPException
*/
@Before
- public void setup() {
+ public void setup() throws XMPPException {
// build protocol verifier
protocol = new Protocol();
diff --git a/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java b/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java
index b1cbb3758..3cd6591c6 100644
--- a/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java
+++ b/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java
@@ -25,6 +25,7 @@ import java.util.Random;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.PacketListener;
+import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.util.StringUtils;
@@ -71,9 +72,10 @@ public class InBandBytestreamSessionMessageTest {
/**
* Initialize fields used in the tests.
+ * @throws XMPPException
*/
@Before
- public void setup() {
+ public void setup() throws XMPPException {
// build protocol verifier
protocol = new Protocol();
diff --git a/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java b/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java
index 5d893091e..43a0cb636 100644
--- a/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java
+++ b/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java
@@ -25,6 +25,7 @@ import java.util.Random;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.PacketListener;
+import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.util.StringUtils;
@@ -72,9 +73,10 @@ public class InBandBytestreamSessionTest {
/**
* Initialize fields used in the tests.
+ * @throws XMPPException
*/
@Before
- public void setup() {
+ public void setup() throws XMPPException {
// build protocol verifier
protocol = new Protocol();
diff --git a/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java b/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java
index 1004df0b0..d1bfb110b 100644
--- a/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java
+++ b/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java
@@ -71,9 +71,10 @@ public class Socks5ByteStreamManagerTest {
/**
* Initialize fields used in the tests.
+ * @throws XMPPException
*/
@Before
- public void setup() {
+ public void setup() throws XMPPException {
// build protocol verifier
protocol = new Protocol();
diff --git a/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamRequestTest.java b/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamRequestTest.java
index 2dda5b9ab..a87e06da7 100644
--- a/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamRequestTest.java
+++ b/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamRequestTest.java
@@ -60,9 +60,10 @@ public class Socks5ByteStreamRequestTest {
/**
* Initialize fields used in the tests.
+ * @throws XMPPException
*/
@Before
- public void setup() {
+ public void setup() throws XMPPException {
// build protocol verifier
protocol = new Protocol();
diff --git a/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiatorTest.java b/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiatorTest.java
index a6bcf3abd..1f1c1a8fc 100644
--- a/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiatorTest.java
+++ b/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiatorTest.java
@@ -65,9 +65,10 @@ public class Socks5ClientForInitiatorTest {
/**
* Initialize fields used in the tests.
+ * @throws XMPPException
*/
@Before
- public void setup() {
+ public void setup() throws XMPPException {
// build protocol verifier
protocol = new Protocol();
diff --git a/extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java b/extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java
index 02f285c38..939ee0a03 100644
--- a/extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java
+++ b/extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java
@@ -83,7 +83,7 @@ public class ConfigureFormTest
Node node = mgr.getNode("princely_musings");
- SmackConfiguration.setPacketReplyTimeout(100);
+ SmackConfiguration.setDefaultPacketReplyTimeout(100);
con.setTimeout();
node.getNodeConfiguration();
diff --git a/extensions/src/test/java/org/jivesoftware/util/ConnectionUtils.java b/extensions/src/test/java/org/jivesoftware/util/ConnectionUtils.java
index 45c1ea8de..48fd46a9a 100644
--- a/extensions/src/test/java/org/jivesoftware/util/ConnectionUtils.java
+++ b/extensions/src/test/java/org/jivesoftware/util/ConnectionUtils.java
@@ -21,8 +21,10 @@ import static org.mockito.Mockito.*;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.Connection;
+import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Packet;
+import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -54,9 +56,10 @@ public class ConnectionUtils {
* @param initiatorJID the user associated to the XMPP connection
* @param xmppServer the XMPP server associated to the XMPP connection
* @return a mocked XMPP connection
+ * @throws XMPPException
*/
public static Connection createMockedConnection(final Protocol protocol,
- String initiatorJID, String xmppServer) {
+ String initiatorJID, String xmppServer) throws XMPPException {
// mock XMPP connection
Connection connection = mock(Connection.class);
@@ -64,29 +67,49 @@ public class ConnectionUtils {
when(connection.getServiceName()).thenReturn(xmppServer);
// mock packet collector
- PacketCollector collector = mock(PacketCollector.class);
+ final PacketCollector collector = mock(PacketCollector.class);
when(connection.createPacketCollector(isA(PacketFilter.class))).thenReturn(
collector);
- Answer