mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-10 02:39:42 +02:00
Add IQ request handler API
This also moves the logic to send error IQ replies from "when there is no IQ provider registerd" to "when there is no IQ request handler registered". Which has for example the advantage that IQ parsing no longer asks for a connection instance.
This commit is contained in:
parent
fcb4844d10
commit
bb8dcc9874
28 changed files with 533 additions and 317 deletions
|
@ -16,13 +16,9 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.bytestreams.ibb;
|
||||
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.filter.AndFilter;
|
||||
import org.jivesoftware.smack.filter.IQTypeFilter;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.packet.Close;
|
||||
|
||||
/**
|
||||
|
@ -34,45 +30,44 @@ import org.jivesoftware.smackx.bytestreams.ibb.packet.Close;
|
|||
*
|
||||
* @author Henning Staib
|
||||
*/
|
||||
class CloseListener implements PacketListener {
|
||||
class CloseListener extends AbstractIqRequestHandler {
|
||||
|
||||
/* manager containing the listeners and the XMPP connection */
|
||||
private final InBandBytestreamManager manager;
|
||||
|
||||
/* packet filter for all In-Band Bytestream close requests */
|
||||
private final PacketFilter closeFilter = new AndFilter(new PacketTypeFilter(
|
||||
Close.class), IQTypeFilter.SET);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param manager the In-Band Bytestream manager
|
||||
*/
|
||||
protected CloseListener(InBandBytestreamManager manager) {
|
||||
super(Close.ELEMENT, Close.NAMESPACE, IQ.Type.set, Mode.async);
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
public void processPacket(Packet packet) throws NotConnectedException {
|
||||
Close closeRequest = (Close) packet;
|
||||
@Override
|
||||
public IQ handleIQRequest(IQ iqRequest) {
|
||||
Close closeRequest = (Close) iqRequest;
|
||||
InBandBytestreamSession ibbSession = this.manager.getSessions().get(
|
||||
closeRequest.getSessionID());
|
||||
if (ibbSession == null) {
|
||||
this.manager.replyItemNotFoundPacket(closeRequest);
|
||||
try {
|
||||
this.manager.replyItemNotFoundPacket(closeRequest);
|
||||
}
|
||||
catch (NotConnectedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ibbSession.closeByPeer(closeRequest);
|
||||
try {
|
||||
ibbSession.closeByPeer(closeRequest);
|
||||
}
|
||||
catch (NotConnectedException e) {
|
||||
return null;
|
||||
}
|
||||
this.manager.getSessions().remove(closeRequest.getSessionID());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the packet filter for In-Band Bytestream close requests.
|
||||
*
|
||||
* @return the packet filter for In-Band Bytestream close requests
|
||||
*/
|
||||
protected PacketFilter getFilter() {
|
||||
return this.closeFilter;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -210,8 +210,7 @@ public class InBandBytestreamManager implements BytestreamManager {
|
|||
|
||||
// register bytestream open packet listener
|
||||
this.initiationListener = new InitiationListener(this);
|
||||
this.connection.addAsyncPacketListener(this.initiationListener,
|
||||
this.initiationListener.getFilter());
|
||||
connection.registerIQRequestHandler(initiationListener);
|
||||
|
||||
// register bytestream data packet listener
|
||||
this.dataListener = new DataListener(this);
|
||||
|
@ -219,8 +218,7 @@ public class InBandBytestreamManager implements BytestreamManager {
|
|||
|
||||
// register bytestream close packet listener
|
||||
this.closeListener = new CloseListener(this);
|
||||
this.connection.addSyncPacketListener(this.closeListener, this.closeListener.getFilter());
|
||||
|
||||
connection.registerIQRequestHandler(closeListener);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -543,9 +541,9 @@ public class InBandBytestreamManager implements BytestreamManager {
|
|||
managers.remove(connection);
|
||||
|
||||
// remove all listeners registered by this manager
|
||||
this.connection.removeAsyncPacketListener(this.initiationListener);
|
||||
connection.unregisterIQRequestHandler(initiationListener);
|
||||
this.connection.removeSyncPacketListener(this.dataListener);
|
||||
this.connection.removeSyncPacketListener(this.closeListener);
|
||||
connection.unregisterIQRequestHandler(closeListener);
|
||||
|
||||
// shutdown threads
|
||||
this.initiationListener.shutdown();
|
||||
|
|
|
@ -21,12 +21,9 @@ import java.util.concurrent.Executors;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.filter.AndFilter;
|
||||
import org.jivesoftware.smack.filter.IQTypeFilter;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||
import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamListener;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
|
||||
|
@ -44,16 +41,12 @@ import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
|
|||
*
|
||||
* @author Henning Staib
|
||||
*/
|
||||
class InitiationListener implements PacketListener {
|
||||
class InitiationListener extends AbstractIqRequestHandler {
|
||||
private static final Logger LOGGER = Logger.getLogger(InitiationListener.class.getName());
|
||||
|
||||
/* manager containing the listeners and the XMPP connection */
|
||||
private final InBandBytestreamManager manager;
|
||||
|
||||
/* packet filter for all In-Band Bytestream requests */
|
||||
private final PacketFilter initFilter = new AndFilter(new PacketTypeFilter(Open.class),
|
||||
IQTypeFilter.SET);
|
||||
|
||||
/* executor service to process incoming requests concurrently */
|
||||
private final ExecutorService initiationListenerExecutor;
|
||||
|
||||
|
@ -63,11 +56,13 @@ class InitiationListener implements PacketListener {
|
|||
* @param manager the In-Band Bytestream manager
|
||||
*/
|
||||
protected InitiationListener(InBandBytestreamManager manager) {
|
||||
super(Open.ELEMENT, Open.NAMESPACE, IQ.Type.set, Mode.async);
|
||||
this.manager = manager;
|
||||
initiationListenerExecutor = Executors.newCachedThreadPool();
|
||||
}
|
||||
}
|
||||
|
||||
public void processPacket(final Packet packet) {
|
||||
@Override
|
||||
public IQ handleIQRequest(final IQ packet) {
|
||||
initiationListenerExecutor.execute(new Runnable() {
|
||||
|
||||
public void run() {
|
||||
|
@ -79,6 +74,7 @@ class InitiationListener implements PacketListener {
|
|||
}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
private void processRequest(Packet packet) throws NotConnectedException {
|
||||
|
@ -120,15 +116,6 @@ class InitiationListener implements PacketListener {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the packet filter for In-Band Bytestream open requests.
|
||||
*
|
||||
* @return the packet filter for In-Band Bytestream open requests
|
||||
*/
|
||||
protected PacketFilter getFilter() {
|
||||
return this.initFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuts down the listeners executor service.
|
||||
*/
|
||||
|
|
|
@ -21,12 +21,9 @@ import java.util.concurrent.Executors;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.filter.AndFilter;
|
||||
import org.jivesoftware.smack.filter.IQTypeFilter;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||
import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamListener;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||
|
@ -39,16 +36,12 @@ import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
|||
*
|
||||
* @author Henning Staib
|
||||
*/
|
||||
final class InitiationListener implements PacketListener {
|
||||
final class InitiationListener extends AbstractIqRequestHandler {
|
||||
private static final Logger LOGGER = Logger.getLogger(InitiationListener.class.getName());
|
||||
|
||||
/* manager containing the listeners and the XMPP connection */
|
||||
private final Socks5BytestreamManager manager;
|
||||
|
||||
/* packet filter for all SOCKS5 Bytestream requests */
|
||||
private final PacketFilter initFilter = new AndFilter(new PacketTypeFilter(Bytestream.class),
|
||||
IQTypeFilter.SET);
|
||||
|
||||
/* executor service to process incoming requests concurrently */
|
||||
private final ExecutorService initiationListenerExecutor;
|
||||
|
||||
|
@ -58,11 +51,14 @@ final class InitiationListener implements PacketListener {
|
|||
* @param manager the SOCKS5 Bytestream manager
|
||||
*/
|
||||
protected InitiationListener(Socks5BytestreamManager manager) {
|
||||
super(Bytestream.ELEMENT, Bytestream.NAMESPACE, IQ.Type.set, Mode.async);
|
||||
this.manager = manager;
|
||||
initiationListenerExecutor = Executors.newCachedThreadPool();
|
||||
}
|
||||
|
||||
public void processPacket(final Packet packet) {
|
||||
|
||||
@Override
|
||||
public IQ handleIQRequest(final IQ packet) {
|
||||
initiationListenerExecutor.execute(new Runnable() {
|
||||
|
||||
public void run() {
|
||||
|
@ -74,6 +70,8 @@ final class InitiationListener implements PacketListener {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void processRequest(Packet packet) throws NotConnectedException {
|
||||
|
@ -111,15 +109,6 @@ final class InitiationListener implements PacketListener {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the packet filter for SOCKS5 Bytestream initialization requests.
|
||||
*
|
||||
* @return the packet filter for SOCKS5 Bytestream initialization requests
|
||||
*/
|
||||
protected PacketFilter getFilter() {
|
||||
return this.initFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuts down the listeners executor service.
|
||||
*/
|
||||
|
|
|
@ -284,7 +284,7 @@ public final class Socks5BytestreamManager implements BytestreamManager {
|
|||
public synchronized void disableService() {
|
||||
|
||||
// remove initiation packet listener
|
||||
this.connection.removeAsyncPacketListener(this.initiationListener);
|
||||
connection.unregisterIQRequestHandler(initiationListener);
|
||||
|
||||
// shutdown threads
|
||||
this.initiationListener.shutdown();
|
||||
|
@ -713,8 +713,7 @@ public final class Socks5BytestreamManager implements BytestreamManager {
|
|||
*/
|
||||
private void activate() {
|
||||
// register bytestream initiation packet listener
|
||||
this.connection.addAsyncPacketListener(this.initiationListener,
|
||||
this.initiationListener.getFilter());
|
||||
connection.registerIQRequestHandler(initiationListener);
|
||||
|
||||
// enable SOCKS5 feature
|
||||
enableService();
|
||||
|
|
|
@ -28,7 +28,6 @@ import java.util.logging.Logger;
|
|||
|
||||
import org.jivesoftware.smack.ConnectionCreationListener;
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
|
@ -36,12 +35,9 @@ import org.jivesoftware.smack.XMPPConnection;
|
|||
import org.jivesoftware.smack.XMPPConnectionRegistry;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smack.filter.AndFilter;
|
||||
import org.jivesoftware.smack.filter.IQTypeFilter;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||
import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
|
||||
import org.jivesoftware.smack.iqrequest.IQRequestHandler.Mode;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smackx.commands.AdHocCommand.Action;
|
||||
|
@ -73,9 +69,6 @@ public class AdHocCommandManager extends Manager {
|
|||
*/
|
||||
private static final int SESSION_TIMEOUT = 2 * 60;
|
||||
|
||||
private static final PacketFilter AD_HOC_COMMAND_FILTER = new AndFilter(
|
||||
new PacketTypeFilter(AdHocCommandData.class), IQTypeFilter.SET);
|
||||
|
||||
/**
|
||||
* Map a XMPPConnection with it AdHocCommandManager. This map have a key-value
|
||||
* pair for every active connection.
|
||||
|
@ -174,19 +167,20 @@ public class AdHocCommandManager extends Manager {
|
|||
|
||||
// The packet listener and the filter for processing some AdHoc Commands
|
||||
// Packets
|
||||
PacketListener listener = new PacketListener() {
|
||||
public void processPacket(Packet packet) {
|
||||
AdHocCommandData requestData = (AdHocCommandData) packet;
|
||||
connection.registerIQRequestHandler(new AbstractIqRequestHandler(AdHocCommandData.ELEMENT,
|
||||
AdHocCommandData.NAMESPACE, IQ.Type.set, Mode.async) {
|
||||
@Override
|
||||
public IQ handleIQRequest(IQ iqRequest) {
|
||||
AdHocCommandData requestData = (AdHocCommandData) iqRequest;
|
||||
try {
|
||||
processAdHocCommand(requestData);
|
||||
return processAdHocCommand(requestData);
|
||||
}
|
||||
catch (NotConnectedException | NoResponseException e) {
|
||||
catch (NoResponseException | NotConnectedException e) {
|
||||
LOGGER.log(Level.INFO, "processAdHocCommand threw exceptino", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
connection.addAsyncPacketListener(listener, AD_HOC_COMMAND_FILTER);
|
||||
});
|
||||
|
||||
sessionsSweeper = null;
|
||||
}
|
||||
|
@ -325,7 +319,7 @@ public class AdHocCommandManager extends Manager {
|
|||
* @throws NotConnectedException
|
||||
* @throws NoResponseException
|
||||
*/
|
||||
private void processAdHocCommand(AdHocCommandData requestData) throws NotConnectedException, NoResponseException {
|
||||
private IQ processAdHocCommand(AdHocCommandData requestData) throws NoResponseException, NotConnectedException {
|
||||
// Creates the response with the corresponding data
|
||||
AdHocCommandData response = new AdHocCommandData();
|
||||
response.setTo(requestData.getFrom());
|
||||
|
@ -342,8 +336,7 @@ public class AdHocCommandManager extends Manager {
|
|||
if (!commands.containsKey(commandNode)) {
|
||||
// Requested command does not exist so return
|
||||
// item_not_found error.
|
||||
respondError(response, XMPPError.Condition.item_not_found);
|
||||
return;
|
||||
return respondError(response, XMPPError.Condition.item_not_found);
|
||||
}
|
||||
|
||||
// Create new session ID
|
||||
|
@ -361,24 +354,21 @@ public class AdHocCommandManager extends Manager {
|
|||
// Answer forbidden error if requester permissions are not
|
||||
// enough to execute the requested command
|
||||
if (!command.hasPermission(requestData.getFrom())) {
|
||||
respondError(response, XMPPError.Condition.forbidden);
|
||||
return;
|
||||
return respondError(response, XMPPError.Condition.forbidden);
|
||||
}
|
||||
|
||||
Action action = requestData.getAction();
|
||||
|
||||
// If the action is unknown then respond an error.
|
||||
if (action != null && action.equals(Action.unknown)) {
|
||||
respondError(response, XMPPError.Condition.bad_request,
|
||||
return respondError(response, XMPPError.Condition.bad_request,
|
||||
AdHocCommand.SpecificErrorCondition.malformedAction);
|
||||
return;
|
||||
}
|
||||
|
||||
// If the action is not execute, then it is an invalid action.
|
||||
if (action != null && !action.equals(Action.execute)) {
|
||||
respondError(response, XMPPError.Condition.bad_request,
|
||||
return respondError(response, XMPPError.Condition.bad_request,
|
||||
AdHocCommand.SpecificErrorCondition.badAction);
|
||||
return;
|
||||
}
|
||||
|
||||
// Increase the state number, so the command knows in witch
|
||||
|
@ -441,7 +431,7 @@ public class AdHocCommandManager extends Manager {
|
|||
}
|
||||
|
||||
// Sends the response packet
|
||||
connection().sendPacket(response);
|
||||
return response;
|
||||
|
||||
}
|
||||
catch (XMPPErrorException e) {
|
||||
|
@ -457,7 +447,7 @@ public class AdHocCommandManager extends Manager {
|
|||
response.setStatus(Status.canceled);
|
||||
executingCommands.remove(sessionId);
|
||||
}
|
||||
respondError(response, error);
|
||||
return respondError(response, error);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -467,9 +457,8 @@ public class AdHocCommandManager extends Manager {
|
|||
// This also handles if the command was removed in the meanwhile
|
||||
// of getting the key and the value of the map.
|
||||
if (command == null) {
|
||||
respondError(response, XMPPError.Condition.bad_request,
|
||||
return respondError(response, XMPPError.Condition.bad_request,
|
||||
AdHocCommand.SpecificErrorCondition.badSessionid);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the Session data has expired (default is 10 minutes)
|
||||
|
@ -479,9 +468,8 @@ public class AdHocCommandManager extends Manager {
|
|||
executingCommands.remove(sessionId);
|
||||
|
||||
// Answer a not_allowed error (session-expired)
|
||||
respondError(response, XMPPError.Condition.not_allowed,
|
||||
return respondError(response, XMPPError.Condition.not_allowed,
|
||||
AdHocCommand.SpecificErrorCondition.sessionExpired);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -494,9 +482,8 @@ public class AdHocCommandManager extends Manager {
|
|||
|
||||
// If the action is unknown the respond an error
|
||||
if (action != null && action.equals(Action.unknown)) {
|
||||
respondError(response, XMPPError.Condition.bad_request,
|
||||
return respondError(response, XMPPError.Condition.bad_request,
|
||||
AdHocCommand.SpecificErrorCondition.malformedAction);
|
||||
return;
|
||||
}
|
||||
|
||||
// If the user didn't specify an action or specify the execute
|
||||
|
@ -508,9 +495,8 @@ public class AdHocCommandManager extends Manager {
|
|||
// Check that the specified action was previously
|
||||
// offered
|
||||
if (!command.isValidAction(action)) {
|
||||
respondError(response, XMPPError.Condition.bad_request,
|
||||
return respondError(response, XMPPError.Condition.bad_request,
|
||||
AdHocCommand.SpecificErrorCondition.badAction);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -556,7 +542,7 @@ public class AdHocCommandManager extends Manager {
|
|||
executingCommands.remove(sessionId);
|
||||
}
|
||||
|
||||
connection().sendPacket(response);
|
||||
return response;
|
||||
}
|
||||
catch (XMPPErrorException e) {
|
||||
// If there is an exception caused by the next, complete,
|
||||
|
@ -571,7 +557,7 @@ public class AdHocCommandManager extends Manager {
|
|||
response.setStatus(Status.canceled);
|
||||
executingCommands.remove(sessionId);
|
||||
}
|
||||
respondError(response, error);
|
||||
return respondError(response, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -584,9 +570,9 @@ public class AdHocCommandManager extends Manager {
|
|||
* @param condition the condition of the error.
|
||||
* @throws NotConnectedException
|
||||
*/
|
||||
private void respondError(AdHocCommandData response,
|
||||
XMPPError.Condition condition) throws NotConnectedException {
|
||||
respondError(response, new XMPPError(condition));
|
||||
private IQ respondError(AdHocCommandData response,
|
||||
XMPPError.Condition condition) {
|
||||
return respondError(response, new XMPPError(condition));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -597,11 +583,11 @@ public class AdHocCommandManager extends Manager {
|
|||
* @param specificCondition the adhoc command error condition.
|
||||
* @throws NotConnectedException
|
||||
*/
|
||||
private void respondError(AdHocCommandData response, XMPPError.Condition condition,
|
||||
AdHocCommand.SpecificErrorCondition specificCondition) throws NotConnectedException
|
||||
private static IQ respondError(AdHocCommandData response, XMPPError.Condition condition,
|
||||
AdHocCommand.SpecificErrorCondition specificCondition)
|
||||
{
|
||||
XMPPError error = new XMPPError(condition, new AdHocCommandData.SpecificError(specificCondition));
|
||||
respondError(response, error);
|
||||
return respondError(response, error);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -611,10 +597,10 @@ public class AdHocCommandManager extends Manager {
|
|||
* @param error the error to send.
|
||||
* @throws NotConnectedException
|
||||
*/
|
||||
private void respondError(AdHocCommandData response, XMPPError error) throws NotConnectedException {
|
||||
private static IQ respondError(AdHocCommandData response, XMPPError error) {
|
||||
response.setType(IQ.Type.error);
|
||||
response.setError(error);
|
||||
connection().sendPacket(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,13 +21,10 @@ import org.jivesoftware.smack.SmackException.NotConnectedException;
|
|||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.ConnectionCreationListener;
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.XMPPConnectionRegistry;
|
||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smack.filter.AndFilter;
|
||||
import org.jivesoftware.smack.filter.IQTypeFilter;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||
import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
|
||||
import org.jivesoftware.smack.iqrequest.IQRequestHandler.Mode;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
|
@ -67,9 +64,6 @@ public class ServiceDiscoveryManager extends Manager {
|
|||
|
||||
private static final Logger LOGGER = Logger.getLogger(ServiceDiscoveryManager.class.getName());
|
||||
|
||||
private static final PacketFilter GET_DISCOVER_ITEMS = new AndFilter(IQTypeFilter.GET, new PacketTypeFilter(DiscoverItems.class));
|
||||
private static final PacketFilter GET_DISCOVER_INFO = new AndFilter(IQTypeFilter.GET, new PacketTypeFilter(DiscoverInfo.class));
|
||||
|
||||
private static final String DEFAULT_IDENTITY_NAME = "Smack";
|
||||
private static final String DEFAULT_IDENTITY_CATEGORY = "client";
|
||||
private static final String DEFAULT_IDENTITY_TYPE = "pc";
|
||||
|
@ -122,9 +116,10 @@ public class ServiceDiscoveryManager extends Manager {
|
|||
addFeature(DiscoverItems.NAMESPACE);
|
||||
|
||||
// Listen for disco#items requests and answer with an empty result
|
||||
PacketListener packetListener = new PacketListener() {
|
||||
public void processPacket(Packet packet) throws NotConnectedException {
|
||||
DiscoverItems discoverItems = (DiscoverItems) packet;
|
||||
connection.registerIQRequestHandler(new AbstractIqRequestHandler(DiscoverItems.ELEMENT, DiscoverItems.NAMESPACE, IQ.Type.get, Mode.async) {
|
||||
@Override
|
||||
public IQ handleIQRequest(IQ iqRequest) {
|
||||
DiscoverItems discoverItems = (DiscoverItems) iqRequest;
|
||||
DiscoverItems response = new DiscoverItems();
|
||||
response.setType(IQ.Type.result);
|
||||
response.setTo(discoverItems.getFrom());
|
||||
|
@ -145,16 +140,16 @@ public class ServiceDiscoveryManager extends Manager {
|
|||
response.setType(IQ.Type.error);
|
||||
response.setError(new XMPPError(XMPPError.Condition.item_not_found));
|
||||
}
|
||||
connection().sendPacket(response);
|
||||
return response;
|
||||
}
|
||||
};
|
||||
connection.addAsyncPacketListener(packetListener, GET_DISCOVER_ITEMS);
|
||||
});
|
||||
|
||||
// Listen for disco#info requests and answer the client's supported features
|
||||
// To add a new feature as supported use the #addFeature message
|
||||
packetListener = new PacketListener() {
|
||||
public void processPacket(Packet packet) throws NotConnectedException {
|
||||
DiscoverInfo discoverInfo = (DiscoverInfo) packet;
|
||||
connection.registerIQRequestHandler(new AbstractIqRequestHandler(DiscoverInfo.ELEMENT, DiscoverInfo.NAMESPACE, IQ.Type.get, Mode.async) {
|
||||
@Override
|
||||
public IQ handleIQRequest(IQ iqRequest) {
|
||||
DiscoverInfo discoverInfo = (DiscoverInfo) iqRequest;
|
||||
// Answer the client's supported features if the request is of the GET type
|
||||
DiscoverInfo response = new DiscoverInfo();
|
||||
response.setType(IQ.Type.result);
|
||||
|
@ -184,10 +179,9 @@ public class ServiceDiscoveryManager extends Manager {
|
|||
response.setError(new XMPPError(XMPPError.Condition.item_not_found));
|
||||
}
|
||||
}
|
||||
connection().sendPacket(response);
|
||||
return response;
|
||||
}
|
||||
};
|
||||
connection.addAsyncPacketListener(packetListener, GET_DISCOVER_INFO);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,14 +28,16 @@ import org.jivesoftware.smack.PacketListener;
|
|||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.XMPPConnectionRegistry;
|
||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smack.filter.AndFilter;
|
||||
import org.jivesoftware.smack.filter.IQTypeFilter;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||
import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
|
||||
import org.jivesoftware.smack.iqrequest.IQRequestHandler.Mode;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.IQ.Type;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.packet.XMPPError.Condition;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.iqlast.packet.LastActivity;
|
||||
|
||||
|
@ -89,8 +91,8 @@ import org.jivesoftware.smackx.iqlast.packet.LastActivity;
|
|||
|
||||
public class LastActivityManager extends Manager {
|
||||
private static final Map<XMPPConnection, LastActivityManager> instances = new WeakHashMap<XMPPConnection, LastActivityManager>();
|
||||
private static final PacketFilter IQ_GET_LAST_FILTER = new AndFilter(IQTypeFilter.GET,
|
||||
new PacketTypeFilter(LastActivity.class));
|
||||
// private static final PacketFilter IQ_GET_LAST_FILTER = new AndFilter(IQTypeFilter.GET,
|
||||
// new PacketTypeFilter(LastActivity.class));
|
||||
|
||||
private static boolean enabledPerDefault = true;
|
||||
|
||||
|
@ -160,21 +162,22 @@ public class LastActivityManager extends Manager {
|
|||
}, PacketTypeFilter.MESSAGE);
|
||||
|
||||
// Register a listener for a last activity query
|
||||
connection.addAsyncPacketListener(new PacketListener() {
|
||||
|
||||
public void processPacket(Packet packet) throws NotConnectedException {
|
||||
if (!enabled) return;
|
||||
connection.registerIQRequestHandler(new AbstractIqRequestHandler(LastActivity.ELEMENT, LastActivity.NAMESPACE,
|
||||
Type.get, Mode.async) {
|
||||
@Override
|
||||
public IQ handleIQRequest(IQ iqRequest) {
|
||||
if (!enabled)
|
||||
return IQ.createErrorResponse(iqRequest, new XMPPError(Condition.not_acceptable));
|
||||
LastActivity message = new LastActivity();
|
||||
message.setType(IQ.Type.result);
|
||||
message.setTo(packet.getFrom());
|
||||
message.setFrom(packet.getTo());
|
||||
message.setPacketID(packet.getPacketID());
|
||||
message.setTo(iqRequest.getFrom());
|
||||
message.setFrom(iqRequest.getTo());
|
||||
message.setPacketID(iqRequest.getPacketID());
|
||||
message.setLastActivity(getIdleTime());
|
||||
|
||||
connection().sendPacket(message);
|
||||
return message;
|
||||
}
|
||||
|
||||
}, IQ_GET_LAST_FILTER);
|
||||
});
|
||||
|
||||
if (enabledPerDefault) {
|
||||
enable();
|
||||
|
|
|
@ -26,14 +26,13 @@ import org.jivesoftware.smack.SmackException.NotConnectedException;
|
|||
import org.jivesoftware.smack.ConnectionCreationListener;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.XMPPConnectionRegistry;
|
||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smack.filter.AndFilter;
|
||||
import org.jivesoftware.smack.filter.IQTypeFilter;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
|
||||
import org.jivesoftware.smack.iqrequest.IQRequestHandler.Mode;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.packet.XMPPError.Condition;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.iqversion.packet.Version;
|
||||
|
||||
|
@ -56,8 +55,6 @@ import org.jivesoftware.smackx.iqversion.packet.Version;
|
|||
public class VersionManager extends Manager {
|
||||
private static final Map<XMPPConnection, VersionManager> INSTANCES = new WeakHashMap<XMPPConnection, VersionManager>();
|
||||
|
||||
private static final PacketFilter PACKET_FILTER = new AndFilter(new PacketTypeFilter(Version.class), IQTypeFilter.GET);
|
||||
|
||||
private static Version defaultVersion;
|
||||
|
||||
private Version ourVersion = defaultVersion;
|
||||
|
@ -86,19 +83,17 @@ public class VersionManager extends Manager {
|
|||
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
|
||||
sdm.addFeature(Version.NAMESPACE);
|
||||
|
||||
connection.addAsyncPacketListener(new PacketListener() {
|
||||
/**
|
||||
* Sends a Version reply on request
|
||||
* @throws NotConnectedException
|
||||
*/
|
||||
public void processPacket(Packet packet) throws NotConnectedException {
|
||||
if (ourVersion == null)
|
||||
return;
|
||||
connection.registerIQRequestHandler(new AbstractIqRequestHandler(Version.ELEMENT, Version.NAMESPACE, IQ.Type.get,
|
||||
Mode.async) {
|
||||
@Override
|
||||
public IQ handleIQRequest(IQ iqRequest) {
|
||||
if (ourVersion == null) {
|
||||
return IQ.createErrorResponse(iqRequest, new XMPPError(Condition.not_acceptable));
|
||||
}
|
||||
|
||||
connection().sendPacket(Version.createResultFor(packet, ourVersion));
|
||||
return Version.createResultFor(iqRequest, ourVersion);
|
||||
}
|
||||
}
|
||||
, PACKET_FILTER);
|
||||
});
|
||||
}
|
||||
|
||||
public static synchronized VersionManager getInstanceFor(XMPPConnection connection) {
|
||||
|
|
|
@ -35,15 +35,13 @@ import org.jivesoftware.smack.SmackException.NotConnectedException;
|
|||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.ConnectionCreationListener;
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.XMPPConnectionRegistry;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smack.filter.AndFilter;
|
||||
import org.jivesoftware.smack.filter.IQTypeFilter;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
|
||||
import org.jivesoftware.smack.iqrequest.IQRequestHandler.Mode;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.IQ.Type;
|
||||
import org.jivesoftware.smack.util.SmackExecutorThreadFactory;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.ping.packet.Ping;
|
||||
|
@ -66,9 +64,6 @@ public class PingManager extends Manager {
|
|||
|
||||
private static final Map<XMPPConnection, PingManager> INSTANCES = new WeakHashMap<XMPPConnection, PingManager>();
|
||||
|
||||
private static final PacketFilter PING_PACKET_FILTER = new AndFilter(
|
||||
new PacketTypeFilter(Ping.class), IQTypeFilter.GET);
|
||||
|
||||
static {
|
||||
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
|
||||
public void connectionCreated(XMPPConnection connection) {
|
||||
|
@ -127,14 +122,13 @@ public class PingManager extends Manager {
|
|||
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
|
||||
sdm.addFeature(Ping.NAMESPACE);
|
||||
|
||||
connection.addAsyncPacketListener(new PacketListener() {
|
||||
// Send a Pong for every Ping
|
||||
connection.registerIQRequestHandler(new AbstractIqRequestHandler(Ping.ELEMENT, Ping.NAMESPACE, Type.get, Mode.async) {
|
||||
@Override
|
||||
public void processPacket(Packet packet) throws NotConnectedException {
|
||||
Ping ping = (Ping) packet;
|
||||
connection().sendPacket(ping.getPong());
|
||||
public IQ handleIQRequest(IQ iqRequest) {
|
||||
Ping ping = (Ping) iqRequest;
|
||||
return ping.getPong();
|
||||
}
|
||||
}, PING_PACKET_FILTER);
|
||||
});
|
||||
connection.addConnectionListener(new AbstractConnectionClosedListener() {
|
||||
@Override
|
||||
public void authenticated(XMPPConnection connection, boolean resumed) {
|
||||
|
|
|
@ -37,6 +37,8 @@ import org.jivesoftware.smack.filter.IQResultReplyFilter;
|
|||
import org.jivesoftware.smack.filter.IQTypeFilter;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||
import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
|
||||
import org.jivesoftware.smack.iqrequest.IQRequestHandler.Mode;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
|
@ -65,8 +67,6 @@ public class PrivacyListManager extends Manager {
|
|||
|
||||
public static final PacketFilter PRIVACY_FILTER = new PacketTypeFilter(Privacy.class);
|
||||
|
||||
private static final PacketFilter PRIVACY_SET = new AndFilter(IQTypeFilter.SET, PRIVACY_FILTER);
|
||||
|
||||
private static final PacketFilter PRIVACY_RESULT = new AndFilter(IQTypeFilter.RESULT, PRIVACY_FILTER);
|
||||
|
||||
// Keep the list of instances of this class.
|
||||
|
@ -97,10 +97,11 @@ public class PrivacyListManager extends Manager {
|
|||
private PrivacyListManager(XMPPConnection connection) {
|
||||
super(connection);
|
||||
|
||||
connection.addSyncPacketListener(new PacketListener() {
|
||||
connection.registerIQRequestHandler(new AbstractIqRequestHandler(Privacy.ELEMENT, Privacy.NAMESPACE,
|
||||
IQ.Type.set, Mode.sync) {
|
||||
@Override
|
||||
public void processPacket(Packet packet) throws NotConnectedException {
|
||||
Privacy privacy = (Privacy) packet;
|
||||
public IQ handleIQRequest(IQ iqRequest) {
|
||||
Privacy privacy = (Privacy) iqRequest;
|
||||
|
||||
// Notifies the event to the listeners.
|
||||
for (PrivacyListListener listener : listeners) {
|
||||
|
@ -117,11 +118,9 @@ public class PrivacyListManager extends Manager {
|
|||
}
|
||||
}
|
||||
|
||||
// Send a result package acknowledging the reception of a privacy package.
|
||||
IQ iq = IQ.createResultIQ(privacy);
|
||||
connection().sendPacket(iq);
|
||||
return IQ.createResultIQ(privacy);
|
||||
}
|
||||
}, PRIVACY_SET);
|
||||
});
|
||||
|
||||
// cached(Active|Default)ListName handling
|
||||
connection.addPacketSendingListener(new PacketListener() {
|
||||
|
|
|
@ -24,14 +24,14 @@ import org.jivesoftware.smack.SmackException.NotConnectedException;
|
|||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.ConnectionCreationListener;
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.XMPPConnectionRegistry;
|
||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smack.filter.AndFilter;
|
||||
import org.jivesoftware.smack.filter.IQTypeFilter;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
|
||||
import org.jivesoftware.smack.iqrequest.IQRequestHandler.Mode;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.IQ.Type;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.packet.XMPPError.Condition;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.time.packet.Time;
|
||||
|
||||
|
@ -39,9 +39,6 @@ public class EntityTimeManager extends Manager {
|
|||
|
||||
private static final Map<XMPPConnection, EntityTimeManager> INSTANCES = new WeakHashMap<XMPPConnection, EntityTimeManager>();
|
||||
|
||||
private static final PacketFilter TIME_PACKET_FILTER = new AndFilter(new PacketTypeFilter(
|
||||
Time.class), IQTypeFilter.GET);
|
||||
|
||||
private static boolean autoEnable = true;
|
||||
|
||||
static {
|
||||
|
@ -72,14 +69,18 @@ public class EntityTimeManager extends Manager {
|
|||
if (autoEnable)
|
||||
enable();
|
||||
|
||||
connection.addAsyncPacketListener(new PacketListener() {
|
||||
connection.registerIQRequestHandler(new AbstractIqRequestHandler(Time.ELEMENT, Time.NAMESPACE, Type.get,
|
||||
Mode.async) {
|
||||
@Override
|
||||
public void processPacket(Packet packet) throws NotConnectedException {
|
||||
if (!enabled)
|
||||
return;
|
||||
connection().sendPacket(Time.createResponse(packet));
|
||||
public IQ handleIQRequest(IQ iqRequest) {
|
||||
if (enabled) {
|
||||
return Time.createResponse(iqRequest);
|
||||
}
|
||||
else {
|
||||
return IQ.createErrorResponse(iqRequest, new XMPPError(Condition.not_acceptable));
|
||||
}
|
||||
}
|
||||
}, TIME_PACKET_FILTER);
|
||||
});
|
||||
}
|
||||
|
||||
public synchronized void enable() {
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.jivesoftware.smackx.time.packet;
|
||||
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jxmpp.util.XmppDateTime;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
@ -123,7 +122,7 @@ public class Time extends IQ {
|
|||
this.tzo = tzo;
|
||||
}
|
||||
|
||||
public static Time createResponse(Packet request) {
|
||||
public static Time createResponse(IQ request) {
|
||||
Time time = new Time(Calendar.getInstance());
|
||||
time.setType(Type.result);
|
||||
time.setTo(request.getFrom());
|
||||
|
|
|
@ -61,7 +61,7 @@ public class CloseListenerTest {
|
|||
close.setFrom(initiatorJID);
|
||||
close.setTo(targetJID);
|
||||
|
||||
closeListener.processPacket(close);
|
||||
closeListener.handleIQRequest(close);
|
||||
|
||||
// wait because packet is processed in an extra thread
|
||||
Thread.sleep(200);
|
||||
|
|
|
@ -79,7 +79,7 @@ public class InitiationListenerTest {
|
|||
public void shouldRespondWithError() throws Exception {
|
||||
|
||||
// run the listener with the initiation packet
|
||||
initiationListener.processPacket(initBytestream);
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
||||
// wait because packet is processed in an extra thread
|
||||
Thread.sleep(200);
|
||||
|
@ -107,7 +107,7 @@ public class InitiationListenerTest {
|
|||
byteStreamManager.setMaximumBlockSize(1024);
|
||||
|
||||
// run the listener with the initiation packet
|
||||
initiationListener.processPacket(initBytestream);
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
||||
// wait because packet is processed in an extra thread
|
||||
Thread.sleep(200);
|
||||
|
@ -137,7 +137,7 @@ public class InitiationListenerTest {
|
|||
byteStreamManager.addIncomingBytestreamListener(listener);
|
||||
|
||||
// run the listener with the initiation packet
|
||||
initiationListener.processPacket(initBytestream);
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
||||
// wait because packet is processed in an extra thread
|
||||
Thread.sleep(200);
|
||||
|
@ -165,7 +165,7 @@ public class InitiationListenerTest {
|
|||
byteStreamManager.addIncomingBytestreamListener(listener, initiatorJID);
|
||||
|
||||
// run the listener with the initiation packet
|
||||
initiationListener.processPacket(initBytestream);
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
||||
// wait because packet is processed in an extra thread
|
||||
Thread.sleep(200);
|
||||
|
@ -193,7 +193,7 @@ public class InitiationListenerTest {
|
|||
byteStreamManager.addIncomingBytestreamListener(listener, "other_" + initiatorJID);
|
||||
|
||||
// run the listener with the initiation packet
|
||||
initiationListener.processPacket(initBytestream);
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
||||
// wait because packet is processed in an extra thread
|
||||
Thread.sleep(200);
|
||||
|
@ -231,7 +231,7 @@ public class InitiationListenerTest {
|
|||
byteStreamManager.addIncomingBytestreamListener(userRequestsListener, initiatorJID);
|
||||
|
||||
// run the listener with the initiation packet
|
||||
initiationListener.processPacket(initBytestream);
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
||||
// wait because packet is processed in an extra thread
|
||||
Thread.sleep(200);
|
||||
|
@ -265,7 +265,7 @@ public class InitiationListenerTest {
|
|||
+ initiatorJID);
|
||||
|
||||
// run the listener with the initiation packet
|
||||
initiationListener.processPacket(initBytestream);
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
||||
// wait because packet is processed in an extra thread
|
||||
Thread.sleep(200);
|
||||
|
@ -300,7 +300,7 @@ public class InitiationListenerTest {
|
|||
byteStreamManager.ignoreBytestreamRequestOnce(sessionID);
|
||||
|
||||
// run the listener with the initiation packet
|
||||
initiationListener.processPacket(initBytestream);
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
||||
// wait because packet is processed in an extra thread
|
||||
Thread.sleep(200);
|
||||
|
@ -314,7 +314,7 @@ public class InitiationListenerTest {
|
|||
verify(allRequestsListener, never()).incomingBytestreamRequest(byteStreamRequest.capture());
|
||||
|
||||
// run the listener with the initiation packet again
|
||||
initiationListener.processPacket(initBytestream);
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
||||
// wait because packet is processed in an extra thread
|
||||
Thread.sleep(200);
|
||||
|
|
|
@ -86,7 +86,7 @@ public class InitiationListenerTest {
|
|||
public void shouldRespondWithError() throws Exception {
|
||||
|
||||
// run the listener with the initiation packet
|
||||
initiationListener.processPacket(initBytestream);
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
||||
// wait because packet is processed in an extra thread
|
||||
Thread.sleep(200);
|
||||
|
@ -116,7 +116,7 @@ public class InitiationListenerTest {
|
|||
byteStreamManager.addIncomingBytestreamListener(listener);
|
||||
|
||||
// run the listener with the initiation packet
|
||||
initiationListener.processPacket(initBytestream);
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
||||
// wait because packet is processed in an extra thread
|
||||
Thread.sleep(200);
|
||||
|
@ -144,7 +144,7 @@ public class InitiationListenerTest {
|
|||
byteStreamManager.addIncomingBytestreamListener(listener, initiatorJID);
|
||||
|
||||
// run the listener with the initiation packet
|
||||
initiationListener.processPacket(initBytestream);
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
||||
// wait because packet is processed in an extra thread
|
||||
Thread.sleep(200);
|
||||
|
@ -172,7 +172,7 @@ public class InitiationListenerTest {
|
|||
byteStreamManager.addIncomingBytestreamListener(listener, "other_" + initiatorJID);
|
||||
|
||||
// run the listener with the initiation packet
|
||||
initiationListener.processPacket(initBytestream);
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
||||
// wait because packet is processed in an extra thread
|
||||
Thread.sleep(200);
|
||||
|
@ -210,7 +210,7 @@ public class InitiationListenerTest {
|
|||
byteStreamManager.addIncomingBytestreamListener(userRequestsListener, initiatorJID);
|
||||
|
||||
// run the listener with the initiation packet
|
||||
initiationListener.processPacket(initBytestream);
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
||||
// wait because packet is processed in an extra thread
|
||||
Thread.sleep(200);
|
||||
|
@ -244,7 +244,7 @@ public class InitiationListenerTest {
|
|||
+ initiatorJID);
|
||||
|
||||
// run the listener with the initiation packet
|
||||
initiationListener.processPacket(initBytestream);
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
||||
// wait because packet is processed in an extra thread
|
||||
Thread.sleep(200);
|
||||
|
@ -279,7 +279,7 @@ public class InitiationListenerTest {
|
|||
byteStreamManager.ignoreBytestreamRequestOnce(sessionID);
|
||||
|
||||
// run the listener with the initiation packet
|
||||
initiationListener.processPacket(initBytestream);
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
||||
// wait because packet is processed in an extra thread
|
||||
Thread.sleep(200);
|
||||
|
@ -293,7 +293,7 @@ public class InitiationListenerTest {
|
|||
verify(allRequestsListener, never()).incomingBytestreamRequest(byteStreamRequest.capture());
|
||||
|
||||
// run the listener with the initiation packet again
|
||||
initiationListener.processPacket(initBytestream);
|
||||
initiationListener.handleIQRequest(initBytestream);
|
||||
|
||||
// wait because packet is processed in an extra thread
|
||||
Thread.sleep(200);
|
||||
|
|
|
@ -45,7 +45,7 @@ public class PubSubProviderTest {
|
|||
"</iq>";
|
||||
// @formatter:on
|
||||
XmlPullParser parser = TestUtils.getIQParser(resultStanza);
|
||||
PubSub pubsubResult = (PubSub) PacketParserUtils.parse(parser, null);
|
||||
PubSub pubsubResult = (PubSub) PacketParserUtils.parseIQ(parser);
|
||||
SubscriptionsExtension subElem = pubsubResult.getExtension(PubSubElementType.SUBSCRIPTIONS);
|
||||
List<Subscription> subscriptions = subElem.getSubscriptions();
|
||||
assertEquals(2, subscriptions.size());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue