1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-26 00:02:06 +01:00

Improve packet send and result collecting API

Instead of repeating the same pattern, when sending an IQ get/set packet
and collecting the response

PacketFilter filter = new PacketIDFilter(request.getPacketID()),
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
if (result == null) {
    throw new XMPPException("No response from server.");
}
else if (result.getType() == IQ.Type.ERROR) {
    throw new XMPPException(result.getError());
}

the API got redesigned, so that the above code block can be replaced
with

Packet result = connection.createPacketCollectorAndSend(request).nextResultOrThrow();
This commit is contained in:
Florian Schmaus 2014-02-18 15:05:19 +01:00
parent e6d5385129
commit 7bd7b3d24c
50 changed files with 333 additions and 1489 deletions

View file

@ -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();
}
}

View file

@ -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 <code>packet</code>.
* Does also send <code>packet</code>. Note that the packet filter is at the moment created as
* ID filter of <code>packet</code>'s ID. This may change in the future to also check the
* correct "from JID" value.
*
* @param packet the packet to filter responses from
* @return a new packet collector.
*/
public PacketCollector createPacketCollectorAndSend(Packet packet) {
PacketFilter packetFilter = new PacketIDFilter(packet.getPacketID());
// Create the packet collector before sending the packet
PacketCollector packetCollector = createPacketCollector(packetFilter);
// Now we can send the packet as the collector has been created
sendPacket(packet);
return packetCollector;
}
/**
* Creates a new packet collector for this connection. A packet filter determines
* 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.
*/

View file

@ -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();

View file

@ -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 <tt>timeout</tt> has elapased. If the
* until a packet is available or the <tt>timeout</tt> has elapsed. If the
* timeout elapses without a result, <tt>null</tt> will be returned.
*
* @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,
* <tt>null</tt> will be returned. This method does also cancel the PacketCollector.
*
* @return the next available packet.
* @throws XMPPException
*/
public Packet nextResultOrThrow() throws XMPPException {
return nextResultOrThrow(connection.getPacketReplyTimeout());
}
/**
* Returns the next available packet. The method call will block until a packet is available or
* the <tt>timeout</tt> has elapsed. This method does also cancel the PacketCollector.
*
* @param timeout the amount of time to wait for the next packet (in milleseconds).
* @return the next available packet.
* @throws XMPPException in case of no response or error response
*/
public Packet nextResultOrThrow(long timeout) throws XMPPException {
Packet result = nextResult(timeout);
cancel();
if (result == null) {
throw new XMPPException(SmackError.NO_RESPONSE_FROM_SERVER);
}
XMPPError xmppError = result.getError();
if (xmppError != null) {
throw new XMPPException(xmppError);
}
return result;
}
/**
* Processes a packet to see if it meets the criteria for this packet collector.
* If so, the packet is added to the result queue.

View file

@ -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) {

View file

@ -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();
}
/**

View file

@ -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();
}
}

View file

@ -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;
}

View file

@ -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<String> defaultMechs = new ArrayList<String>();
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());

View file

@ -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.

View file

@ -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());
}
}

View file

@ -2,8 +2,8 @@
<!-- Smack configuration file. -->
<smack>
<!-- Packet reply timeout in milliseconds -->
<packetReplyTimeout>5000</packetReplyTimeout>
<!-- Default Packet reply timeout in milliseconds -->
<defaultPacketReplyTimeout>5000</defaultPacketReplyTimeout>
<!-- Enable/Disable local Socks5 proxy -->
<localSocks5ProxyEnabled>true</localSocks5ProxyEnabled>

View file

@ -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);
}
}

View file

@ -25,7 +25,7 @@ public class SmackConfigurationTest {
@Test
public void testSmackConfiguration() {
try {
SmackConfiguration.getPacketReplyTimeout();
SmackConfiguration.getDefaultPacketReplyTimeout();
} catch (Throwable t) {
fail("SmackConfiguration threw Throwable");
}

View file

@ -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);
}
/**

View file

@ -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);

View file

@ -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

View file

@ -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) {

View file

@ -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();
}
/**

View file

@ -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);
}

View file

@ -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();
}
/**

View file

@ -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");
}

View file

@ -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");

View file

@ -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;
}

View file

@ -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;
}
}

View file

@ -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();
}
/**

View file

@ -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<String> 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<String> 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<String> 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<Affiliate> affiliates = new ArrayList<Affiliate>();
for (Iterator<MUCOwner.Item> 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<Affiliate> affiliates = new ArrayList<Affiliate>();
for (Iterator<MUCAdmin.Item> 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<Occupant> participants = new ArrayList<Occupant>();
for (Iterator<MUCAdmin.Item> 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();
}
/**

View file

@ -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<Message> messages = new ArrayList<Message>();
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();
}
}

View file

@ -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());
}
/**

View file

@ -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}.

View file

@ -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<T>)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<T>)itemsElem.getItems();
}
@ -124,7 +123,7 @@ public class LeafNode extends Node
}
PubSub request = createPubsubPacket(Type.GET, new ItemsExtension(ItemsExtension.ItemsElementType.items, getId(), itemList));
PubSub result = (PubSub)SyncPacketSend.getReply(con, request);
PubSub result = (PubSub) con.createPacketCollectorAndSend(request).nextResultOrThrow();
ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS);
return (List<T>)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<T>)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<T>)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<T>(getId(), items));
SyncPacketSend.getReply(con, packet);
con.createPacketCollectorAndSend(packet).nextResultOrThrow();
}
/**
@ -322,7 +321,7 @@ public class LeafNode extends Node
{
PubSub request = createPubsubPacket(Type.SET, new NodeExtension(PubSubElementType.PURGE_OWNER, getId()), PubSubElementType.PURGE_OWNER.getNamespace());
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();
}
}

View file

@ -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();
}
/**

View file

@ -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();
}
}

View file

@ -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());
}
}

View file

@ -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();
}
/**

View file

@ -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();
}
}

View file

@ -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);
}

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -83,7 +83,7 @@ public class ConfigureFormTest
Node node = mgr.getNode("princely_musings");
SmackConfiguration.setPacketReplyTimeout(100);
SmackConfiguration.setDefaultPacketReplyTimeout(100);
con.setTimeout();
node.getNodeConfiguration();

View file

@ -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<Object> addIncoming = new Answer<Object>() {
Answer<PacketCollector> collectorAndSend = new Answer<PacketCollector>() {
@Override
public PacketCollector answer(InvocationOnMock invocation) throws Throwable {
Packet packet = (Packet) invocation.getArguments()[0];
protocol.getRequests().add(packet);
return collector;
}
};
when(connection.createPacketCollectorAndSend(isA(Packet.class))).thenAnswer(collectorAndSend);
// mock send method
Answer<Object> addIncoming = new Answer<Object>() {
public Object answer(InvocationOnMock invocation) throws Throwable {
protocol.getRequests().add((Packet) invocation.getArguments()[0]);
return null;
}
};
// mock send method
doAnswer(addIncoming).when(connection).sendPacket(isA(Packet.class));
Answer<Packet> answer = new Answer<Packet>() {
// mock receive methods
Answer<Packet> answer = new Answer<Packet>() {
public Packet answer(InvocationOnMock invocation) throws Throwable {
return protocol.getResponses().poll();
}
};
// mock nextResult method
when(collector.nextResult(anyInt())).thenAnswer(answer);
when(collector.nextResult()).thenAnswer(answer);
Answer<Packet> answerOrThrow = new Answer<Packet>() {
@Override
public Packet answer(InvocationOnMock invocation) throws Throwable {
Packet packet = protocol.getResponses().poll();
if (packet == null) return packet;
XMPPError xmppError = packet.getError();
if (xmppError != null) throw new XMPPException(xmppError);
return packet;
}
};
when(collector.nextResultOrThrow()).thenAnswer(answerOrThrow);
when(collector.nextResultOrThrow(anyLong())).thenAnswer(answerOrThrow);
// initialize service discovery manager for this connection
ServiceDiscoveryManager.getInstanceFor(connection);

View file

@ -19,11 +19,8 @@ package org.jivesoftware.smackx.workgroup.agent;
import org.jivesoftware.smackx.workgroup.packet.AgentInfo;
import org.jivesoftware.smackx.workgroup.packet.AgentWorkgroups;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
import java.util.Collection;
@ -40,20 +37,7 @@ public class Agent {
public static Collection<String> getWorkgroups(String serviceJID, String agentJID, Connection connection) throws XMPPException {
AgentWorkgroups request = new AgentWorkgroups(agentJID);
request.setTo(serviceJID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
// Send the request
connection.sendPacket(request);
AgentWorkgroups response = (AgentWorkgroups)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server on status set.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
AgentWorkgroups response = (AgentWorkgroups) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
return response.getWorkgroups();
}
@ -84,20 +68,7 @@ public class Agent {
agentInfo.setType(IQ.Type.GET);
agentInfo.setTo(workgroupJID);
agentInfo.setFrom(getUser());
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(agentInfo.getPacketID()));
// Send the request
connection.sendPacket(agentInfo);
AgentInfo response = (AgentInfo)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server on status set.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
AgentInfo response = (AgentInfo) connection.createPacketCollectorAndSend(agentInfo).nextResultOrThrow();
return response.getName();
}
@ -117,20 +88,6 @@ public class Agent {
agentInfo.setTo(workgroupJID);
agentInfo.setFrom(getUser());
agentInfo.setName(newName);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(agentInfo.getPacketID()));
// Send the request
connection.sendPacket(agentInfo);
IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server on status set.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
return;
connection.createPacketCollectorAndSend(agentInfo).nextResultOrThrow();
}
}

View file

@ -266,15 +266,7 @@ public class AgentSession {
connection.sendPacket(presence);
presence = (Presence)collector.nextResult(5000);
collector.cancel();
if (!presence.isAvailable()) {
throw new XMPPException("No response from server on status set.");
}
if (presence.getError() != null) {
throw new XMPPException(presence.getError());
}
presence = (Presence)collector.nextResultOrThrow();
// We can safely update this iv since we didn't get any error
this.online = online;
@ -371,15 +363,7 @@ public class AgentSession {
this.connection.sendPacket(presence);
presence = (Presence)collector.nextResult(5000);
collector.cancel();
if (!presence.isAvailable()) {
throw new XMPPException("No response from server on status set.");
}
if (presence.getError() != null) {
throw new XMPPException(presence.getError());
}
collector.nextResultOrThrow();
}
/**
@ -422,15 +406,7 @@ public class AgentSession {
this.connection.sendPacket(presence);
presence = (Presence)collector.nextResult(5000);
collector.cancel();
if (!presence.isAvailable()) {
throw new XMPPException("No response from server on status set.");
}
if (presence.getError() != null) {
throw new XMPPException(presence.getError());
}
collector.nextResultOrThrow();
}
/**
@ -513,19 +489,7 @@ public class AgentSession {
request.setType(IQ.Type.GET);
request.setTo(workgroupJID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
connection.sendPacket(request);
OccupantsInfo response = (OccupantsInfo)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
OccupantsInfo response = (OccupantsInfo) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
return response;
}
@ -809,16 +773,7 @@ public class AgentSession {
// Send the request
connection.sendPacket(notes);
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());
}
collector.nextResultOrThrow();
}
/**
@ -834,21 +789,8 @@ public class AgentSession {
request.setTo(workgroupJID);
request.setSessionID(sessionID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
connection.sendPacket(request);
ChatNotes response = (ChatNotes)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
ChatNotes response = (ChatNotes) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
return response;
}
/**
@ -871,19 +813,9 @@ public class AgentSession {
request.setType(IQ.Type.GET);
request.setTo(workgroupJID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
connection.sendPacket(request);
AgentChatHistory response = (AgentChatHistory) connection.createPacketCollectorAndSend(
request).nextResult();
AgentChatHistory response = (AgentChatHistory)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
return response;
}
@ -898,20 +830,7 @@ public class AgentSession {
request.setType(IQ.Type.GET);
request.setTo(workgroupJID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
connection.sendPacket(request);
SearchSettings response = (SearchSettings)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
SearchSettings response = (SearchSettings) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
return response;
}
@ -928,20 +847,7 @@ public class AgentSession {
request.setTo(workgroupJID);
request.setPersonal(!global);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
connection.sendPacket(request);
Macros response = (Macros)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
Macros response = (Macros) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
return response.getRootGroup();
}
@ -958,20 +864,7 @@ public class AgentSession {
request.setPersonal(true);
request.setPersonalMacroGroup(group);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
connection.sendPacket(request);
IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server on status set.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
connection.createPacketCollectorAndSend(request).nextResultOrThrow();
}
/**
@ -987,20 +880,8 @@ public class AgentSession {
request.setTo(workgroupJID);
request.setSessionID(sessionID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
connection.sendPacket(request);
ChatMetadata response = (ChatMetadata) connection.createPacketCollectorAndSend(request).nextResult();
ChatMetadata response = (ChatMetadata)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
return response.getMetadata();
}
@ -1043,19 +924,7 @@ public class AgentSession {
iq.setTo(workgroupJID);
iq.setFrom(connection.getUser());
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(iq.getPacketID()));
connection.sendPacket(iq);
IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
}
/**
@ -1095,19 +964,7 @@ public class AgentSession {
iq.setTo(workgroupJID);
iq.setFrom(connection.getUser());
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(iq.getPacketID()));
connection.sendPacket(iq);
IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
}
/**
@ -1123,19 +980,8 @@ public class AgentSession {
setting.setType(IQ.Type.GET);
setting.setTo(workgroupJID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(setting.getPacketID()));
connection.sendPacket(setting);
GenericSettings response = (GenericSettings)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server on status set.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
GenericSettings response = (GenericSettings) connection.createPacketCollectorAndSend(
setting).nextResultOrThrow();
return response;
}
@ -1144,21 +990,8 @@ public class AgentSession {
request.setType(IQ.Type.GET);
request.setTo(workgroupJID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
connection.sendPacket(request);
MonitorPacket response = (MonitorPacket)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server on status set.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
MonitorPacket response = (MonitorPacket) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
return response.isMonitor();
}
public void makeRoomOwner(Connection con, String sessionID) throws XMPPException {
@ -1167,19 +1000,6 @@ public class AgentSession {
request.setTo(workgroupJID);
request.setSessionID(sessionID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
connection.sendPacket(request);
Packet response = collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server on status set.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
connection.createPacketCollectorAndSend(request).nextResultOrThrow();
}
}

View file

@ -19,11 +19,8 @@ package org.jivesoftware.smackx.workgroup.agent;
import org.jivesoftware.smackx.workgroup.packet.Transcript;
import org.jivesoftware.smackx.workgroup.packet.Transcripts;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
/**
* A TranscriptManager helps to retrieve the full conversation transcript of a given session
@ -50,20 +47,7 @@ public class TranscriptManager {
public Transcript getTranscript(String workgroupJID, String sessionID) throws XMPPException {
Transcript request = new Transcript(sessionID);
request.setTo(workgroupJID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
// Send the request
connection.sendPacket(request);
Transcript response = (Transcript) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server on status set.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
Transcript response = (Transcript) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
return response;
}
@ -79,20 +63,7 @@ public class TranscriptManager {
public Transcripts getTranscripts(String workgroupJID, String userID) throws XMPPException {
Transcripts request = new Transcripts(userID);
request.setTo(workgroupJID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
// Send the request
connection.sendPacket(request);
Transcripts response = (Transcripts) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server on status set.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
Transcripts response = (Transcripts) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
return response;
}
}

View file

@ -20,11 +20,8 @@ package org.jivesoftware.smackx.workgroup.agent;
import org.jivesoftware.smackx.search.ReportedData;
import org.jivesoftware.smackx.workgroup.packet.TranscriptSearch;
import org.jivesoftware.smackx.xdata.Form;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
/**
@ -55,21 +52,8 @@ public class TranscriptSearchManager {
search.setType(IQ.Type.GET);
search.setTo(serviceJID);
PacketCollector collector = connection.createPacketCollector(
new PacketIDFilter(search.getPacketID()));
connection.sendPacket(search);
TranscriptSearch response = (TranscriptSearch) collector.nextResult(
SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server on status set.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
TranscriptSearch response = (TranscriptSearch) connection.createPacketCollectorAndSend(
search).nextResultOrThrow();
return Form.getFormFrom(response);
}
@ -89,19 +73,8 @@ public class TranscriptSearchManager {
search.setTo(serviceJID);
search.addExtension(completedForm.getDataFormToSend());
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(search.getPacketID()));
connection.sendPacket(search);
TranscriptSearch response = (TranscriptSearch) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server on status set.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
TranscriptSearch response = (TranscriptSearch) connection.createPacketCollectorAndSend(
search).nextResultOrThrow();
return ReportedData.getReportedDataFrom(response);
}
}

View file

@ -153,8 +153,9 @@ public class Workgroup {
* available only when agents are available for this workgroup.
*
* @return true if the workgroup is available for receiving new requests.
* @throws XMPPException
*/
public boolean isAvailable() {
public boolean isAvailable() throws XMPPException {
Presence directedPresence = new Presence(Presence.Type.available);
directedPresence.setTo(workgroupJID);
PacketFilter typeFilter = new PacketTypeFilter(Presence.class);
@ -164,19 +165,8 @@ public class Workgroup {
connection.sendPacket(directedPresence);
Presence response = (Presence)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
return false;
}
else if (response.getError() != null) {
return false;
}
else {
return Presence.Type.available == response.getType();
}
Presence response = (Presence)collector.nextResultOrThrow();
return Presence.Type.available == response.getType();
}
/**
@ -323,22 +313,7 @@ public class Workgroup {
JoinQueuePacket joinPacket = new JoinQueuePacket(workgroupJID, answerForm, userID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(joinPacket.getPacketID()));
this.connection.sendPacket(joinPacket);
IQ response = (IQ)collector.nextResult(10000);
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from the server.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
connection.createPacketCollectorAndSend(joinPacket).nextResultOrThrow();
// Notify listeners that we've joined the queue.
fireQueueJoinedEvent();
}
@ -418,18 +393,7 @@ public class Workgroup {
}
DepartQueuePacket departPacket = new DepartQueuePacket(this.workgroupJID);
PacketCollector collector = this.connection.createPacketCollector(new PacketIDFilter(departPacket.getPacketID()));
connection.sendPacket(departPacket);
IQ response = (IQ)collector.nextResult(5000);
collector.cancel();
if (response == null) {
throw new XMPPException("No response from the server.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
connection.createPacketCollectorAndSend(departPacket).nextResultOrThrow();
// Notify listeners that we're no longer in the queue.
fireQueueDepartedEvent();
@ -670,20 +634,8 @@ public class Workgroup {
request.setType(IQ.Type.GET);
request.setTo(workgroupJID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
connection.sendPacket(request);
ChatSettings response = (ChatSettings) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
ChatSettings response = (ChatSettings)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
return response;
}
@ -717,20 +669,8 @@ public class Workgroup {
request.setType(IQ.Type.GET);
request.setTo(workgroupJID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
connection.sendPacket(request);
OfflineSettings response = (OfflineSettings)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
OfflineSettings response = (OfflineSettings) connection.createPacketCollectorAndSend(
request).nextResultOrThrow();
return response;
}
@ -745,20 +685,7 @@ public class Workgroup {
request.setType(IQ.Type.GET);
request.setTo(workgroupJID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
connection.sendPacket(request);
SoundSettings response = (SoundSettings)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
SoundSettings response = (SoundSettings) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
return response;
}
@ -773,20 +700,8 @@ public class Workgroup {
request.setType(IQ.Type.GET);
request.setTo(workgroupJID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
connection.sendPacket(request);
WorkgroupProperties response = (WorkgroupProperties)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
WorkgroupProperties response = (WorkgroupProperties) connection.createPacketCollectorAndSend(
request).nextResultOrThrow();
return response;
}
@ -803,20 +718,8 @@ public class Workgroup {
request.setType(IQ.Type.GET);
request.setTo(workgroupJID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
connection.sendPacket(request);
WorkgroupProperties response = (WorkgroupProperties)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
WorkgroupProperties response = (WorkgroupProperties) connection.createPacketCollectorAndSend(
request).nextResultOrThrow();
return response;
}
@ -834,19 +737,8 @@ public class Workgroup {
workgroupForm.setType(IQ.Type.GET);
workgroupForm.setTo(workgroupJID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(workgroupForm.getPacketID()));
connection.sendPacket(workgroupForm);
WorkgroupForm response = (WorkgroupForm)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Cancel the collector.
collector.cancel();
if (response == null) {
throw new XMPPException("No response from server on status set.");
}
if (response.getError() != null) {
throw new XMPPException(response.getError());
}
WorkgroupForm response = (WorkgroupForm) connection.createPacketCollectorAndSend(
workgroupForm).nextResultOrThrow();
return Form.getFormFrom(response);
}
}