mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 09:09:38 +02:00
Add StanzaIdFilter, deprecate PacketIDFilter
This commit is contained in:
parent
2856b8ace6
commit
7ebea7ce94
10 changed files with 73 additions and 29 deletions
|
@ -57,7 +57,7 @@ import org.jivesoftware.smack.compression.XMPPInputOutputStream;
|
|||
import org.jivesoftware.smack.debugger.SmackDebugger;
|
||||
import org.jivesoftware.smack.filter.IQReplyFilter;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
||||
import org.jivesoftware.smack.filter.StanzaIdFilter;
|
||||
import org.jivesoftware.smack.iqrequest.IQRequestHandler;
|
||||
import org.jivesoftware.smack.packet.Bind;
|
||||
import org.jivesoftware.smack.packet.ErrorIQ;
|
||||
|
@ -539,7 +539,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
// Note that we can not use IQReplyFilter here, since the users full JID is not yet
|
||||
// available. It will become available right after the resource has been successfully bound.
|
||||
Bind bindResource = Bind.newSet(resource);
|
||||
PacketCollector packetCollector = createPacketCollectorAndSend(new PacketIDFilter(bindResource), bindResource);
|
||||
PacketCollector packetCollector = createPacketCollectorAndSend(new StanzaIdFilter(bindResource), bindResource);
|
||||
Bind response = packetCollector.nextResultOrThrow();
|
||||
// Set the connections user to the result of resource binding. It is important that we don't infer the user
|
||||
// from the login() arguments and the configurations service name, as, for example, when SASL External is used,
|
||||
|
@ -552,7 +552,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
// For more information see http://tools.ietf.org/html/draft-cridland-xmpp-session-01
|
||||
if (sessionFeature != null && !sessionFeature.isOptional() && !getConfiguration().isLegacySessionDisabled()) {
|
||||
Session session = new Session();
|
||||
packetCollector = createPacketCollectorAndSend(new PacketIDFilter(session), session);
|
||||
packetCollector = createPacketCollectorAndSend(new StanzaIdFilter(session), session);
|
||||
packetCollector.nextResultOrThrow();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ public class IQReplyFilter implements PacketFilter {
|
|||
packetId = iqPacket.getStanzaId();
|
||||
|
||||
PacketFilter iqFilter = new OrFilter(IQTypeFilter.ERROR, IQTypeFilter.RESULT);
|
||||
PacketFilter idFilter = new PacketIDFilter(iqPacket);
|
||||
PacketFilter idFilter = new StanzaIdFilter(iqPacket);
|
||||
iqAndIdFilter = new AndFilter(iqFilter, idFilter);
|
||||
fromFilter = new OrFilter();
|
||||
fromFilter.addFilter(FromMatchesFilter.createFull(to));
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.jivesoftware.smack.packet.Stanza;
|
|||
* packet filtering by using the {@link org.jivesoftware.smack.filter.AndFilter AndFilter} and
|
||||
* {@link org.jivesoftware.smack.filter.OrFilter OrFilter} filters. It's also possible to define
|
||||
* your own filters by implementing this interface. The code example below creates a trivial filter
|
||||
* for packets with a specific ID (real code should use {@link PacketIDFilter} instead).
|
||||
* for packets with a specific ID (real code should use {@link StanzaIdFilter} instead).
|
||||
*
|
||||
* <pre>
|
||||
* // Use an anonymous inner class to define a packet filter that returns
|
||||
|
|
|
@ -24,7 +24,9 @@ import org.jivesoftware.smack.util.StringUtils;
|
|||
* Filters for packets with a particular packet ID.
|
||||
*
|
||||
* @author Matt Tucker
|
||||
* @deprecated use {@link StanzaIdFilter} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public class PacketIDFilter implements PacketFilter {
|
||||
|
||||
private final String packetID;
|
||||
|
@ -33,7 +35,9 @@ public class PacketIDFilter implements PacketFilter {
|
|||
* Creates a new packet ID filter using the specified packet's ID.
|
||||
*
|
||||
* @param packet the packet which the ID is taken from.
|
||||
* @deprecated use {@link StanzaIdfilter(Stanza)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public PacketIDFilter(Stanza packet) {
|
||||
this(packet.getStanzaId());
|
||||
}
|
||||
|
@ -42,7 +46,9 @@ public class PacketIDFilter implements PacketFilter {
|
|||
* Creates a new packet ID filter using the specified packet ID.
|
||||
*
|
||||
* @param packetID the packet ID to filter for.
|
||||
* @deprecated use {@link StanzaIdFilter(String)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public PacketIDFilter(String packetID) {
|
||||
StringUtils.requireNotNullOrEmpty(packetID, "Packet ID must not be null or empty.");
|
||||
this.packetID = packetID;
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2007 Jive Software.
|
||||
*
|
||||
* 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.filter;
|
||||
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Filters for Stanzas with a particular stanza ID.
|
||||
*
|
||||
* @author Matt Tucker
|
||||
*/
|
||||
public class StanzaIdFilter implements PacketFilter {
|
||||
|
||||
private final String stanzaId;
|
||||
|
||||
/**
|
||||
* Creates a new stanza ID filter using the specified stanza's ID.
|
||||
*
|
||||
* @param stanza the stanza which the ID is taken from.
|
||||
*/
|
||||
public StanzaIdFilter(Stanza stanza) {
|
||||
this(stanza.getStanzaId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new stanza ID filter using the specified stanza ID.
|
||||
*
|
||||
* @param stanzaID the stanza ID to filter for.
|
||||
*/
|
||||
public StanzaIdFilter(String stanzaID) {
|
||||
this.stanzaId = StringUtils.requireNotNullOrEmpty(stanzaID, "Stanza ID must not be null or empty.");
|
||||
}
|
||||
|
||||
public boolean accept(Stanza stanza) {
|
||||
return stanzaId.equals(stanza.getStanzaId());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + ": id=" + stanzaId;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue