- * To establish a SOCKS5 Bytestream invoke the {@link #establishSession(String)} method. This will
+ * To establish a SOCKS5 Bytestream invoke the {@link #establishSession(Jid)} method. This will
* negotiate a SOCKS5 Bytestream with the given target JID and return a socket.
*
* If a session ID for the SOCKS5 Bytestream was already negotiated (e.g. while negotiating a file
- * transfer) invoke {@link #establishSession(String, String)}.
+ * transfer) invoke {@link #establishSession(Jid, String)}.
*
* To handle incoming SOCKS5 Bytestream requests add an {@link Socks5BytestreamListener} to the
* manager. There are two ways to add this listener. If you want to be informed about incoming
* SOCKS5 Bytestreams from a specific user add the listener by invoking
- * {@link #addIncomingBytestreamListener(BytestreamListener, String)}. If the listener should
+ * {@link #addIncomingBytestreamListener(BytestreamListener, Jid)}. If the listener should
* respond to all SOCKS5 Bytestream requests invoke
* {@link #addIncomingBytestreamListener(BytestreamListener)}.
*
@@ -135,7 +138,7 @@ public final class Socks5BytestreamManager implements BytestreamManager {
* assigns a user to a listener that is informed if a bytestream request for this user is
* received
*/
- private final Map userListeners = new ConcurrentHashMap();
+ private final Map userListeners = new ConcurrentHashMap<>();
/*
* list of listeners that respond to all bytestream requests if there are not user specific
@@ -153,10 +156,10 @@ public final class Socks5BytestreamManager implements BytestreamManager {
private int proxyConnectionTimeout = 10000;
/* blacklist of errornous SOCKS5 proxies */
- private final List proxyBlacklist = Collections.synchronizedList(new LinkedList());
+ private final Set proxyBlacklist = Collections.synchronizedSet(new HashSet());
/* remember the last proxy that worked to prioritize it */
- private String lastWorkingProxy = null;
+ private Jid lastWorkingProxy;
/* flag to enable/disable prioritization of last working proxy */
private boolean proxyPrioritizationEnabled = true;
@@ -246,7 +249,7 @@ public final class Socks5BytestreamManager implements BytestreamManager {
* @param listener the listener to register
* @param initiatorJID the JID of the user that wants to establish a SOCKS5 Bytestream
*/
- public void addIncomingBytestreamListener(BytestreamListener listener, String initiatorJID) {
+ public void addIncomingBytestreamListener(BytestreamListener listener, Jid initiatorJID) {
this.userListeners.put(initiatorJID, listener);
}
@@ -392,7 +395,7 @@ public final class Socks5BytestreamManager implements BytestreamManager {
* the data to be sent.
*
* To establish a SOCKS5 Bytestream after negotiation the kind of data to be sent (e.g. file
- * transfer) use {@link #establishSession(String, String)}.
+ * transfer) use {@link #establishSession(Jid, String)}.
*
* @param targetJID the JID of the user a SOCKS5 Bytestream should be established
* @return the Socket to send/receive data to/from the user
@@ -402,7 +405,7 @@ public final class Socks5BytestreamManager implements BytestreamManager {
* @throws InterruptedException if the current thread was interrupted while waiting
* @throws SmackException if there was no response from the server.
*/
- public Socks5BytestreamSession establishSession(String targetJID) throws XMPPException,
+ public Socks5BytestreamSession establishSession(Jid targetJID) throws XMPPException,
IOException, InterruptedException, SmackException {
String sessionID = getNextSessionID();
return establishSession(targetJID, sessionID);
@@ -421,7 +424,7 @@ public final class Socks5BytestreamManager implements BytestreamManager {
* @throws SmackException if the target does not support SOCKS5.
* @throws XMPPException
*/
- public Socks5BytestreamSession establishSession(String targetJID, String sessionID)
+ public Socks5BytestreamSession establishSession(Jid targetJID, String sessionID)
throws IOException, InterruptedException, NoResponseException, SmackException, XMPPException{
XMPPErrorException discoveryException = null;
@@ -430,7 +433,7 @@ public final class Socks5BytestreamManager implements BytestreamManager {
throw new FeatureNotSupportedException("SOCKS5 Bytestream", targetJID);
}
- List proxies = new ArrayList();
+ List proxies = new ArrayList<>();
// determine SOCKS5 proxies from XMPP-server
try {
proxies.addAll(determineProxies());
@@ -529,7 +532,7 @@ public final class Socks5BytestreamManager implements BytestreamManager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- private boolean supportsSocks5(String targetJID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ private boolean supportsSocks5(Jid targetJID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(connection).supportsFeature(targetJID, Bytestream.NAMESPACE);
}
@@ -543,10 +546,10 @@ public final class Socks5BytestreamManager implements BytestreamManager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- private List determineProxies() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ private List determineProxies() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(this.connection);
- List proxies = new ArrayList();
+ List proxies = new ArrayList<>();
// get all items from XMPP server
DiscoverItems discoverItems = serviceDiscoveryManager.discoverItems(this.connection.getServiceName());
@@ -591,7 +594,7 @@ public final class Socks5BytestreamManager implements BytestreamManager {
* @param proxies a list of SOCKS5 proxy JIDs
* @return a list of stream hosts containing the IP address an the port
*/
- private List determineStreamHostInfos(List proxies) {
+ private List determineStreamHostInfos(List proxies) {
List streamHosts = new ArrayList();
// add local proxy on first position if exists
@@ -601,7 +604,7 @@ public final class Socks5BytestreamManager implements BytestreamManager {
}
// query SOCKS5 proxies for network settings
- for (String proxy : proxies) {
+ for (Jid proxy : proxies) {
Bytestream streamHostRequest = createStreamHostRequest(proxy);
try {
Bytestream response = (Bytestream) connection.createPacketCollectorAndSend(
@@ -623,7 +626,7 @@ public final class Socks5BytestreamManager implements BytestreamManager {
* @param proxy the proxy to query
* @return IQ packet to query a SOCKS5 proxy its network settings
*/
- private Bytestream createStreamHostRequest(String proxy) {
+ private Bytestream createStreamHostRequest(Jid proxy) {
Bytestream request = new Bytestream();
request.setType(IQ.Type.get);
request.setTo(proxy);
@@ -678,7 +681,7 @@ public final class Socks5BytestreamManager implements BytestreamManager {
* @param streamHosts a list of SOCKS5 proxies the target should connect to
* @return a SOCKS5 Bytestream initialization request packet
*/
- private Bytestream createBytestreamInitiation(String sessionID, String targetJID,
+ private Bytestream createBytestreamInitiation(String sessionID, Jid targetJID,
List streamHosts) {
Bytestream initiation = new Bytestream(sessionID);
@@ -758,7 +761,7 @@ public final class Socks5BytestreamManager implements BytestreamManager {
* @param initiator the initiator's JID
* @return the listener
*/
- protected BytestreamListener getUserListener(String initiator) {
+ protected BytestreamListener getUserListener(Jid initiator) {
return this.userListeners.get(initiator);
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamRequest.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamRequest.java
index 71050178a..fe810e2b1 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamRequest.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamRequest.java
@@ -30,6 +30,7 @@ import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.bytestreams.BytestreamRequest;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost;
+import org.jxmpp.jid.Jid;
import org.jxmpp.util.cache.Cache;
import org.jxmpp.util.cache.ExpirationCache;
@@ -169,7 +170,7 @@ public class Socks5BytestreamRequest implements BytestreamRequest {
*
* @return the sender of the SOCKS5 Bytestream initialization request.
*/
- public String getFrom() {
+ public Jid getFrom() {
return this.bytestreamRequest.getFrom();
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java
index 6849c4f03..a6f33a91d 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java
@@ -29,6 +29,7 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost;
+import org.jxmpp.jid.Jid;
/**
* Implementation of a SOCKS5 client used on the initiators side. This is needed because connecting
@@ -47,7 +48,8 @@ class Socks5ClientForInitiator extends Socks5Client {
private String sessionID;
/* the target JID used to activate SOCKS5 stream */
- private String target;
+ // TODO fullJid?
+ private final Jid target;
/**
* Creates a new SOCKS5 client for the initiators side.
@@ -59,7 +61,7 @@ class Socks5ClientForInitiator extends Socks5Client {
* @param target the target JID of the SOCKS5 Bytestream
*/
public Socks5ClientForInitiator(StreamHost streamHost, String digest, XMPPConnection connection,
- String sessionID, String target) {
+ String sessionID, Jid target) {
super(streamHost, digest);
this.connection = connection;
this.sessionID = sessionID;
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java
index 152922300..70e4bbe21 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java
@@ -54,7 +54,7 @@ import org.jivesoftware.smack.SmackException;
*
* The local SOCKS5 proxy server refuses all connections except the ones that are explicitly allowed
* in the process of establishing a SOCKS5 Bytestream (
- * {@link Socks5BytestreamManager#establishSession(String)}).
+ * {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid)}).
*
* This Implementation has the following limitations:
*
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Utils.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Utils.java
index f06ec1938..f5b048631 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Utils.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Utils.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.util.SHA1;
+import org.jxmpp.jid.Jid;
/**
* A collection of utility methods for SOcKS5 messages.
@@ -38,7 +39,7 @@ class Socks5Utils {
* @param targetJID JID of the target of a SOCKS5 Bytestream
* @return SHA-1 digest of the given parameters
*/
- public static String createDigest(String sessionID, String initiatorJID, String targetJID) {
+ public static String createDigest(String sessionID, Jid initiatorJID, Jid targetJID) {
StringBuilder b = new StringBuilder();
b.append(sessionID).append(initiatorJID).append(targetJID);
return SHA1.hex(b.toString());
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/packet/Bytestream.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/packet/Bytestream.java
index 8f76afc71..eae4c928e 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/packet/Bytestream.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/packet/Bytestream.java
@@ -23,6 +23,7 @@ import java.util.List;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.NamedElement;
import org.jivesoftware.smack.util.XmlStringBuilder;
+import org.jxmpp.jid.Jid;
/**
* A packet representing part of a SOCKS5 Bytestream negotiation.
@@ -113,7 +114,7 @@ public class Bytestream extends IQ {
* @param address The internet address of the stream host.
* @return The added stream host.
*/
- public StreamHost addStreamHost(final String JID, final String address) {
+ public StreamHost addStreamHost(final Jid JID, final String address) {
return addStreamHost(JID, address, 0);
}
@@ -125,7 +126,7 @@ public class Bytestream extends IQ {
* @param port The port on which the remote host is seeking connections.
* @return The added stream host.
*/
- public StreamHost addStreamHost(final String JID, final String address, final int port) {
+ public StreamHost addStreamHost(final Jid JID, final String address, final int port) {
StreamHost host = new StreamHost(JID, address, port);
addStreamHost(host);
@@ -156,7 +157,7 @@ public class Bytestream extends IQ {
* @param JID The JID of the desired stream host.
* @return Returns the stream host related to the given JID, or null if there is none.
*/
- public StreamHost getStreamHost(final String JID) {
+ public StreamHost getStreamHost(final Jid JID) {
if (JID == null) {
return null;
}
@@ -184,7 +185,7 @@ public class Bytestream extends IQ {
*
* @param JID The JID of the used host.
*/
- public void setUsedHost(final String JID) {
+ public void setUsedHost(final Jid JID) {
this.usedHost = new StreamHostUsed(JID);
}
@@ -215,7 +216,7 @@ public class Bytestream extends IQ {
*
* @param targetID The JID of the target of the file transfer.
*/
- public void setToActivate(final String targetID) {
+ public void setToActivate(final Jid targetID) {
this.toActivate = new Activate(targetID);
}
@@ -265,13 +266,13 @@ public class Bytestream extends IQ {
public static String ELEMENTNAME = "streamhost";
- private final String JID;
+ private final Jid JID;
private final String addy;
private final int port;
- public StreamHost(String jid, String address) {
+ public StreamHost(Jid jid, String address) {
this(jid, address, 0);
}
@@ -281,7 +282,7 @@ public class Bytestream extends IQ {
* @param JID The JID of the stream host.
* @param address The internet address of the stream host.
*/
- public StreamHost(final String JID, final String address, int port) {
+ public StreamHost(final Jid JID, final String address, int port) {
this.JID = JID;
this.addy = address;
this.port = port;
@@ -292,7 +293,7 @@ public class Bytestream extends IQ {
*
* @return Returns the JID of the stream host.
*/
- public String getJID() {
+ public Jid getJID() {
return JID;
}
@@ -343,14 +344,14 @@ public class Bytestream extends IQ {
public static String ELEMENTNAME = "streamhost-used";
- private final String JID;
+ private final Jid JID;
/**
* Default constructor.
*
* @param JID The JID of the selected stream host.
*/
- public StreamHostUsed(final String JID) {
+ public StreamHostUsed(final Jid JID) {
this.JID = JID;
}
@@ -359,7 +360,7 @@ public class Bytestream extends IQ {
*
* @return Returns the JID of the selected stream host.
*/
- public String getJID() {
+ public Jid getJID() {
return JID;
}
@@ -385,14 +386,14 @@ public class Bytestream extends IQ {
public static String ELEMENTNAME = "activate";
- private final String target;
+ private final Jid target;
/**
* Default constructor specifying the target of the stream.
*
* @param target The target of the stream.
*/
- public Activate(final String target) {
+ public Activate(final Jid target) {
this.target = target;
}
@@ -401,7 +402,7 @@ public class Bytestream extends IQ {
*
* @return Returns the target of the activation.
*/
- public String getTarget() {
+ public Jid getTarget() {
return target;
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/provider/BytestreamsProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/provider/BytestreamsProvider.java
index 18feb3228..a4312d269 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/provider/BytestreamsProvider.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/provider/BytestreamsProvider.java
@@ -19,7 +19,9 @@ package org.jivesoftware.smackx.bytestreams.socks5.provider;
import java.io.IOException;
import org.jivesoftware.smack.provider.IQProvider;
+import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
+import org.jxmpp.jid.Jid;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -41,7 +43,7 @@ public class BytestreamsProvider extends IQProvider {
String mode = parser.getAttributeValue("", "mode");
// streamhost
- String JID = null;
+ Jid JID = null;
String host = null;
String port = null;
@@ -52,15 +54,15 @@ public class BytestreamsProvider extends IQProvider {
elementName = parser.getName();
if (eventType == XmlPullParser.START_TAG) {
if (elementName.equals(Bytestream.StreamHost.ELEMENTNAME)) {
- JID = parser.getAttributeValue("", "jid");
+ JID = ParserUtils.getJidAttribute(parser);
host = parser.getAttributeValue("", "host");
port = parser.getAttributeValue("", "port");
}
else if (elementName.equals(Bytestream.StreamHostUsed.ELEMENTNAME)) {
- toReturn.setUsedHost(parser.getAttributeValue("", "jid"));
+ toReturn.setUsedHost(ParserUtils.getJidAttribute(parser));
}
else if (elementName.equals(Bytestream.Activate.ELEMENTNAME)) {
- toReturn.setToActivate(parser.getAttributeValue("", "jid"));
+ toReturn.setToActivate(ParserUtils.getJidAttribute(parser));
}
}
else if (eventType == XmlPullParser.END_TAG) {
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java
index 9b41096dc..55aa489b6 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java
@@ -45,6 +45,8 @@ import org.jivesoftware.smackx.disco.packet.DiscoverInfo.Feature;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity;
import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.packet.DataForm;
+import org.jxmpp.jid.DomainBareJid;
+import org.jxmpp.jid.Jid;
import org.jxmpp.util.cache.LruCache;
import java.util.Comparator;
@@ -107,7 +109,7 @@ public class EntityCapsManager extends Manager {
* link-local connection the key is formed as user@host (no resource) In
* case of a server or component the key is formed as domain
*/
- private static final LruCache JID_TO_NODEVER_CACHE = new LruCache(10000);
+ private static final LruCache JID_TO_NODEVER_CACHE = new LruCache<>(10000);
static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@@ -166,7 +168,7 @@ public class EntityCapsManager extends Manager {
}
}
- public static NodeVerHash getNodeVerHashByJid(String jid) {
+ public static NodeVerHash getNodeVerHashByJid(Jid jid) {
return JID_TO_NODEVER_CACHE.get(jid);
}
@@ -179,7 +181,7 @@ public class EntityCapsManager extends Manager {
* user name (Full JID)
* @return the discovered info
*/
- public static DiscoverInfo getDiscoverInfoByUser(String user) {
+ public static DiscoverInfo getDiscoverInfoByUser(Jid user) {
NodeVerHash nvh = JID_TO_NODEVER_CACHE.get(user);
if (nvh == null)
return null;
@@ -242,7 +244,7 @@ public class EntityCapsManager extends Manager {
CAPS_CACHE.clear();
}
- private static void addCapsExtensionInfo(String from, CapsExtension capsExtension) {
+ private static void addCapsExtensionInfo(Jid from, CapsExtension capsExtension) {
String capsExtensionHash = capsExtension.getHash();
String hashInUppercase = capsExtensionHash.toUpperCase(Locale.US);
// SUPPORTED_HASHES uses the format of MessageDigest, which is uppercase, e.g. "SHA-1" instead of "sha-1"
@@ -300,7 +302,7 @@ public class EntityCapsManager extends Manager {
if (capsExtension == null) {
return;
}
- String from = connection.getServiceName();
+ DomainBareJid from = connection.getServiceName();
addCapsExtensionInfo(from, capsExtension);
}
});
@@ -320,7 +322,7 @@ public class EntityCapsManager extends Manager {
return;
CapsExtension capsExtension = CapsExtension.from(packet);
- String from = packet.getFrom();
+ Jid from = packet.getFrom();
addCapsExtensionInfo(from, capsExtension);
}
@@ -331,7 +333,7 @@ public class EntityCapsManager extends Manager {
public void processPacket(Stanza packet) {
// always remove the JID from the map, even if entityCaps are
// disabled
- String from = packet.getFrom();
+ Jid from = packet.getFrom();
JID_TO_NODEVER_CACHE.remove(from);
}
}, PRESENCES_WITHOUT_CAPS);
@@ -436,7 +438,7 @@ public class EntityCapsManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public boolean areEntityCapsSupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public boolean areEntityCapsSupported(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return sdm.supportsFeature(jid, NAMESPACE);
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommand.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommand.java
index 0b894d7ed..feaba1328 100755
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommand.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommand.java
@@ -22,6 +22,7 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.commands.packet.AdHocCommandData;
import org.jivesoftware.smackx.xdata.Form;
+import org.jxmpp.jid.Jid;
import java.util.List;
@@ -146,7 +147,7 @@ public abstract class AdHocCommand {
*
* @return the owner JID.
*/
- public abstract String getOwnerJID();
+ public abstract Jid getOwnerJID();
/**
* Returns the notes that the command has at the current stage.
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommandManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommandManager.java
index b550a3670..c209c7634 100755
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommandManager.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommandManager.java
@@ -48,6 +48,7 @@ import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
import org.jivesoftware.smackx.xdata.Form;
+import org.jxmpp.jid.Jid;
/**
* An AdHocCommandManager is responsible for keeping the list of available
@@ -254,7 +255,7 @@ public class AdHocCommandManager extends Manager {
* @throws SmackException if there was no response from the server.
* @throws InterruptedException
*/
- public DiscoverItems discoverCommands(String jid) throws XMPPException, SmackException, InterruptedException {
+ public DiscoverItems discoverCommands(Jid jid) throws XMPPException, SmackException, InterruptedException {
return serviceDiscoveryManager.discoverItems(jid, NAMESPACE);
}
@@ -266,7 +267,7 @@ public class AdHocCommandManager extends Manager {
* @throws SmackException if there was no response from the server.
* @throws InterruptedException
*/
- public void publishCommands(String jid) throws XMPPException, SmackException, InterruptedException {
+ public void publishCommands(Jid jid) throws XMPPException, SmackException, InterruptedException {
// Collects the commands to publish as items
DiscoverItems discoverItems = new DiscoverItems();
Collection xCommandsList = getRegisteredCommands();
@@ -291,7 +292,7 @@ public class AdHocCommandManager extends Manager {
* @param node the identifier of the command
* @return a local instance equivalent to the remote command.
*/
- public RemoteCommand getRemoteCommand(String jid, String node) {
+ public RemoteCommand getRemoteCommand(Jid jid, String node) {
return new RemoteCommand(connection(), node, jid);
}
@@ -652,10 +653,10 @@ public class AdHocCommandManager extends Manager {
private String node;
private String name;
- private String ownerJID;
+ private final Jid ownerJID;
private LocalCommandFactory factory;
- public AdHocCommandInfo(String node, String name, String ownerJID,
+ public AdHocCommandInfo(String node, String name, Jid ownerJID,
LocalCommandFactory factory)
{
this.node = node;
@@ -678,7 +679,7 @@ public class AdHocCommandManager extends Manager {
return node;
}
- public String getOwnerJID() {
+ public Jid getOwnerJID() {
return ownerJID;
}
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/LocalCommand.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/LocalCommand.java
index 457a0edb8..7d0e86d5e 100755
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/LocalCommand.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/LocalCommand.java
@@ -18,6 +18,7 @@
package org.jivesoftware.smackx.commands;
import org.jivesoftware.smackx.commands.packet.AdHocCommandData;
+import org.jxmpp.jid.Jid;
/**
* Represents a command that can be executed locally from a remote location. This
@@ -52,7 +53,7 @@ public abstract class LocalCommand extends AdHocCommand {
/**
* The full JID of the host of the command.
*/
- private String ownerJID;
+ private Jid ownerJID;
/**
* The number of the current stage.
@@ -91,12 +92,12 @@ public abstract class LocalCommand extends AdHocCommand {
*
* @param ownerJID the JID of the owner.
*/
- public void setOwnerJID(String ownerJID) {
+ public void setOwnerJID(Jid ownerJID) {
this.ownerJID = ownerJID;
}
@Override
- public String getOwnerJID() {
+ public Jid getOwnerJID() {
return ownerJID;
}
@@ -128,7 +129,7 @@ public abstract class LocalCommand extends AdHocCommand {
* @param jid the JID to check permissions on.
* @return true if the user has permission to execute this action.
*/
- public abstract boolean hasPermission(String jid);
+ public abstract boolean hasPermission(Jid jid);
/**
* Returns the currently executing stage number. The first stage number is
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/RemoteCommand.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/RemoteCommand.java
index ff62d5f6c..e438a1a15 100755
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/RemoteCommand.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/RemoteCommand.java
@@ -23,6 +23,7 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.commands.packet.AdHocCommandData;
import org.jivesoftware.smackx.xdata.Form;
+import org.jxmpp.jid.Jid;
/**
* Represents a command that is in a remote location. Invoking one of the
@@ -48,7 +49,7 @@ public class RemoteCommand extends AdHocCommand {
/**
* The full JID of the command host
*/
- private String jid;
+ private Jid jid;
/**
* The session ID of this execution.
@@ -64,7 +65,7 @@ public class RemoteCommand extends AdHocCommand {
* @param node the identifier of the command.
* @param jid the JID of the host.
*/
- protected RemoteCommand(XMPPConnection connection, String node, String jid) {
+ protected RemoteCommand(XMPPConnection connection, String node, Jid jid) {
super();
this.connection = connection;
this.jid = jid;
@@ -150,7 +151,7 @@ public class RemoteCommand extends AdHocCommand {
}
@Override
- public String getOwnerJID() {
+ public Jid getOwnerJID() {
return jid;
}
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/packet/AdHocCommandData.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/packet/AdHocCommandData.java
index fc58c8088..9265aa092 100755
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/packet/AdHocCommandData.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/packet/AdHocCommandData.java
@@ -24,6 +24,7 @@ import org.jivesoftware.smackx.commands.AdHocCommand.Action;
import org.jivesoftware.smackx.commands.AdHocCommand.SpecificErrorCondition;
import org.jivesoftware.smackx.commands.AdHocCommandNote;
import org.jivesoftware.smackx.xdata.packet.DataForm;
+import org.jxmpp.jid.Jid;
import java.util.ArrayList;
import java.util.List;
@@ -39,7 +40,7 @@ public class AdHocCommandData extends IQ {
public static final String NAMESPACE = "http://jabber.org/protocol/commands";
/* JID of the command host */
- private String id;
+ private Jid id;
/* Command name */
private String name;
@@ -114,11 +115,11 @@ public class AdHocCommandData extends IQ {
*
* @return the JID of the command host.
*/
- public String getId() {
+ public Jid getId() {
return id;
}
- public void setId(String id) {
+ public void setId(Jid id) {
this.id = id;
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java
index 0f0eee27d..24740af9a 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java
@@ -34,6 +34,8 @@ import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity;
import org.jivesoftware.smackx.xdata.packet.DataForm;
+import org.jxmpp.jid.DomainBareJid;
+import org.jxmpp.jid.Jid;
import org.jxmpp.util.cache.Cache;
import org.jxmpp.util.cache.ExpirationCache;
@@ -477,7 +479,7 @@ public class ServiceDiscoveryManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public DiscoverInfo discoverInfo(String entityID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public DiscoverInfo discoverInfo(Jid entityID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
if (entityID == null)
return discoverInfo(null, null);
@@ -523,7 +525,7 @@ public class ServiceDiscoveryManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public DiscoverInfo discoverInfo(String entityID, String node) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public DiscoverInfo discoverInfo(Jid entityID, String node) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
// Discover the entity's info
DiscoverInfo disco = new DiscoverInfo();
disco.setType(IQ.Type.get);
@@ -545,7 +547,7 @@ public class ServiceDiscoveryManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public DiscoverItems discoverItems(String entityID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public DiscoverItems discoverItems(Jid entityID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return discoverItems(entityID, null);
}
@@ -562,7 +564,7 @@ public class ServiceDiscoveryManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public DiscoverItems discoverItems(String entityID, String node) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public DiscoverItems discoverItems(Jid entityID, String node) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
// Discover the entity's items
DiscoverItems disco = new DiscoverItems();
disco.setType(IQ.Type.get);
@@ -586,7 +588,7 @@ public class ServiceDiscoveryManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public boolean canPublishItems(String entityID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public boolean canPublishItems(Jid entityID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
DiscoverInfo info = discoverInfo(entityID);
return canPublishItems(info);
}
@@ -617,7 +619,7 @@ public class ServiceDiscoveryManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void publishItems(String entityID, DiscoverItems discoverItems) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public void publishItems(Jid entityID, DiscoverItems discoverItems) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
publishItems(entityID, null, discoverItems);
}
@@ -635,7 +637,7 @@ public class ServiceDiscoveryManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void publishItems(String entityID, String node, DiscoverItems discoverItems) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
+ public void publishItems(Jid entityID, String node, DiscoverItems discoverItems) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
discoverItems.setType(IQ.Type.set);
discoverItems.setTo(entityID);
@@ -671,7 +673,7 @@ public class ServiceDiscoveryManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public boolean supportsFeature(String jid, String feature) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public boolean supportsFeature(Jid jid, String feature) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
DiscoverInfo result = discoverInfo(jid);
return result.containsFeature(feature);
}
@@ -680,7 +682,7 @@ public class ServiceDiscoveryManager extends Manager {
* Create a cache to hold the 25 most recently lookup services for a given feature for a period
* of 24 hours.
*/
- private Cache> services = new ExpirationCache>(25,
+ private Cache> services = new ExpirationCache<>(25,
24 * 60 * 60 * 1000);
/**
@@ -695,17 +697,17 @@ public class ServiceDiscoveryManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public List findServices(String feature, boolean stopOnFirst, boolean useCache)
+ public List findServices(String feature, boolean stopOnFirst, boolean useCache)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
- List serviceAddresses = null;
- String serviceName = connection().getServiceName();
+ List serviceAddresses = null;
+ DomainBareJid serviceName = connection().getServiceName();
if (useCache) {
- serviceAddresses = (List) services.get(feature);
+ serviceAddresses = services.get(feature);
if (serviceAddresses != null) {
return serviceAddresses;
}
}
- serviceAddresses = new LinkedList();
+ serviceAddresses = new LinkedList<>();
// Send the disco packet to the server itself
DiscoverInfo info;
try {
@@ -748,7 +750,7 @@ public class ServiceDiscoveryManager extends Manager {
continue;
}
if (info.containsFeature(feature)) {
- serviceAddresses.add(item.getEntityID());
+ serviceAddresses.add(item.getEntityID().asDomainBareJid());
if (stopOnFirst) {
break;
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverItems.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverItems.java
index 50636e616..a61aefddf 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverItems.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverItems.java
@@ -18,6 +18,7 @@ package org.jivesoftware.smackx.disco.packet;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.XmlStringBuilder;
+import org.jxmpp.jid.Jid;
import java.util.Collection;
import java.util.Collections;
@@ -134,7 +135,7 @@ public class DiscoverItems extends IQ {
*/
public static final String REMOVE_ACTION = "remove";
- private String entityID;
+ private final Jid entityID;
private String name;
private String node;
private String action;
@@ -144,7 +145,7 @@ public class DiscoverItems extends IQ {
*
* @param entityID the id of the entity that contains the item
*/
- public Item(String entityID) {
+ public Item(Jid entityID) {
this.entityID = entityID;
}
@@ -153,7 +154,7 @@ public class DiscoverItems extends IQ {
*
* @return the entity's ID.
*/
- public String getEntityID() {
+ public Jid getEntityID() {
return entityID;
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/provider/DiscoverItemsProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/provider/DiscoverItemsProvider.java
index cfec90a04..18ddf97a8 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/provider/DiscoverItemsProvider.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/provider/DiscoverItemsProvider.java
@@ -20,7 +20,9 @@ package org.jivesoftware.smackx.disco.provider;
import java.io.IOException;
import org.jivesoftware.smack.provider.IQProvider;
+import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
+import org.jxmpp.jid.Jid;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -37,7 +39,7 @@ public class DiscoverItemsProvider extends IQProvider {
DiscoverItems discoverItems = new DiscoverItems();
boolean done = false;
DiscoverItems.Item item;
- String jid = "";
+ Jid jid = null;
String name = "";
String action = "";
String node = "";
@@ -47,7 +49,7 @@ public class DiscoverItemsProvider extends IQProvider {
if (eventType == XmlPullParser.START_TAG && "item".equals(parser.getName())) {
// Initialize the variables from the parsed XML
- jid = parser.getAttributeValue("", "jid");
+ jid = ParserUtils.getJidAttribute(parser);
name = parser.getAttributeValue("", "name");
node = parser.getAttributeValue("", "node");
action = parser.getAttributeValue("", "action");
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java
index 312d48414..adae5be86 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java
@@ -39,6 +39,7 @@ import org.jivesoftware.smack.filter.OrFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smackx.si.packet.StreamInitiation;
+import org.jxmpp.jid.Jid;
/**
@@ -61,7 +62,7 @@ public class FaultTolerantNegotiator extends StreamNegotiator {
this.connection = connection;
}
- public PacketFilter getInitiationPacketFilter(String from, String streamID) {
+ public PacketFilter getInitiationPacketFilter(Jid from, String streamID) {
if (primaryFilter == null || secondaryFilter == null) {
primaryFilter = primaryNegotiator.getInitiationPacketFilter(from, streamID);
secondaryFilter = secondaryNegotiator.getInitiationPacketFilter(from, streamID);
@@ -143,7 +144,7 @@ public class FaultTolerantNegotiator extends StreamNegotiator {
return primaryFilter.accept(streamInitiation) ? primaryNegotiator : secondaryNegotiator;
}
- public OutputStream createOutgoingStream(String streamID, String initiator, String target)
+ public OutputStream createOutgoingStream(String streamID, Jid initiator, Jid target)
throws SmackException, XMPPException, InterruptedException {
OutputStream stream;
try {
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java
index 586c934cd..77eb55e6e 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java
@@ -20,6 +20,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import org.jxmpp.jid.Jid;
+
/**
* Contains the generic file information and progress related to a particular
* file transfer.
@@ -35,7 +37,7 @@ public abstract class FileTransfer {
private long fileSize;
- private String peer;
+ private Jid peer;
private Status status = Status.initial;
@@ -56,7 +58,7 @@ public abstract class FileTransfer {
*/
private static final int BUFFER_SIZE = 8192;
- protected FileTransfer(String peer, String streamID,
+ protected FileTransfer(Jid peer, String streamID,
FileTransferNegotiator negotiator) {
this.peer = peer;
this.streamID = streamID;
@@ -106,7 +108,7 @@ public abstract class FileTransfer {
*
* @return Returns the JID of the peer for this file transfer.
*/
- public String getPeer() {
+ public Jid getPeer() {
return peer;
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferManager.java
index 05931cb31..223ee9cd6 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferManager.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferManager.java
@@ -24,7 +24,7 @@ import org.jivesoftware.smack.iqrequest.IQRequestHandler.Mode;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.si.packet.StreamInitiation;
-import org.jxmpp.util.XmppStringUtils;
+import org.jxmpp.jid.FullJid;
import java.util.List;
import java.util.Map;
@@ -33,7 +33,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
/**
* The file transfer manager class handles the sending and recieving of files.
- * To send a file invoke the {@link #createOutgoingFileTransfer(String)} method.
+ * To send a file invoke the {@link #createOutgoingFileTransfer(FullJid)} method.
*
* And to recieve a file add a file transfer listener to the manager. The
* listener will notify you when there is a new file transfer request. To create
@@ -117,15 +117,12 @@ public class FileTransferManager extends Manager {
* @return The send file object on which the negotiated transfer can be run.
* @exception IllegalArgumentException if userID is null or not a full JID
*/
- public OutgoingFileTransfer createOutgoingFileTransfer(String userID) {
- if (userID == null) {
- throw new IllegalArgumentException("userID was null");
- }
+ public OutgoingFileTransfer createOutgoingFileTransfer(FullJid userID) {
// We need to create outgoing file transfers with a full JID since this method will later
// use XEP-0095 to negotiate the stream. This is done with IQ stanzas that need to be addressed to a full JID
// in order to reach an client entity.
- else if (!XmppStringUtils.isFullJID(userID)) {
- throw new IllegalArgumentException("The provided user id was not a full JID (i.e. with resource part)");
+ if (userID == null) {
+ throw new IllegalArgumentException("userID was null");
}
return new OutgoingFileTransfer(connection().getUser(), userID,
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java
index f678c051d..726ad6f15 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java
@@ -42,6 +42,7 @@ import org.jivesoftware.smackx.filetransfer.FileTransferException.NoStreamMethod
import org.jivesoftware.smackx.si.packet.StreamInitiation;
import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.packet.DataForm;
+import org.jxmpp.jid.Jid;
/**
* Manages the negotiation of file transfers according to XEP-0096. If a file is
@@ -302,7 +303,7 @@ public class FileTransferNegotiator extends Manager {
* @throws NoAcceptableTransferMechanisms
* @throws InterruptedException
*/
- public StreamNegotiator negotiateOutgoingTransfer(final String userID,
+ public StreamNegotiator negotiateOutgoingTransfer(final Jid userID,
final String streamID, final String fileName, final long size,
final String desc, int responseTimeout) throws XMPPErrorException, NotConnectedException, NoResponseException, NoAcceptableTransferMechanisms, InterruptedException {
StreamInitiation si = new StreamInitiation();
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferRequest.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferRequest.java
index 75f672264..ea5e2447d 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferRequest.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferRequest.java
@@ -18,6 +18,7 @@ package org.jivesoftware.smackx.filetransfer;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smackx.si.packet.StreamInitiation;
+import org.jxmpp.jid.Jid;
/**
* A request to send a file recieved from another user.
@@ -88,7 +89,7 @@ public class FileTransferRequest {
* @return Returns the fully-qualified jabber ID of the user that requested
* this file transfer.
*/
- public String getRequestor() {
+ public Jid getRequestor() {
return streamInitiation.getFrom();
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/IBBTransferNegotiator.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/IBBTransferNegotiator.java
index 2cee14b03..ee8465911 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/IBBTransferNegotiator.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/IBBTransferNegotiator.java
@@ -35,6 +35,7 @@ import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamSession;
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
import org.jivesoftware.smackx.si.packet.StreamInitiation;
+import org.jxmpp.jid.Jid;
/**
* The In-Band Bytestream file transfer method, or IBB for short, transfers the
@@ -62,8 +63,8 @@ public class IBBTransferNegotiator extends StreamNegotiator {
this.manager = InBandBytestreamManager.getByteStreamManager(connection);
}
- public OutputStream createOutgoingStream(String streamID, String initiator,
- String target) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public OutputStream createOutgoingStream(String streamID, Jid initiator,
+ Jid target) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
InBandBytestreamSession session = this.manager.establishSession(target, streamID);
session.setCloseBothStreamsEnabled(true);
return session.getOutputStream();
@@ -81,7 +82,7 @@ public class IBBTransferNegotiator extends StreamNegotiator {
return negotiateIncomingStream(streamInitiation);
}
- public PacketFilter getInitiationPacketFilter(String from, String streamID) {
+ public PacketFilter getInitiationPacketFilter(Jid from, String streamID) {
/*
* this method is always called prior to #negotiateIncomingStream() so
* the In-Band Bytestream initiation listener must ignore the next
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/OutgoingFileTransfer.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/OutgoingFileTransfer.java
index ed7207fe1..b00542526 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/OutgoingFileTransfer.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/OutgoingFileTransfer.java
@@ -30,6 +30,7 @@ import org.jivesoftware.smack.SmackException.IllegalStateChangeException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.packet.XMPPError;
+import org.jxmpp.jid.Jid;
/**
* Handles the sending of a file to another user. File transfer's in jabber have
@@ -70,11 +71,11 @@ public class OutgoingFileTransfer extends FileTransfer {
private OutputStream outputStream;
- private String initiator;
+ private Jid initiator;
private Thread transferThread;
- protected OutgoingFileTransfer(String initiator, String target,
+ protected OutgoingFileTransfer(Jid initiator, Jid target,
String streamID, FileTransferNegotiator transferNegotiator) {
super(target, streamID, transferNegotiator);
this.initiator = initiator;
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiator.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiator.java
index 4dc0cb39e..1ebf2d614 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiator.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiator.java
@@ -37,6 +37,7 @@ import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamRequest;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamSession;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
import org.jivesoftware.smackx.si.packet.StreamInitiation;
+import org.jxmpp.jid.Jid;
/**
* Negotiates a SOCKS5 Bytestream to be used for file transfers. The implementation is based on the
@@ -57,7 +58,7 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
}
@Override
- public OutputStream createOutgoingStream(String streamID, String initiator, String target) throws NoResponseException, SmackException, XMPPException
+ public OutputStream createOutgoingStream(String streamID, Jid initiator, Jid target) throws NoResponseException, SmackException, XMPPException
{
try {
return this.manager.establishSession(target, streamID).getOutputStream();
@@ -84,7 +85,7 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
}
@Override
- public PacketFilter getInitiationPacketFilter(final String from, String streamID) {
+ public PacketFilter getInitiationPacketFilter(final Jid from, String streamID) {
/*
* this method is always called prior to #negotiateIncomingStream() so the SOCKS5
* InitiationListener must ignore the next SOCKS5 Bytestream request with the given session
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java
index 50d649857..fd16368e9 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/StreamNegotiator.java
@@ -29,6 +29,7 @@ import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smackx.si.packet.StreamInitiation;
import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.packet.DataForm;
+import org.jxmpp.jid.Jid;
import java.io.InputStream;
import java.io.OutputStream;
@@ -94,7 +95,7 @@ public abstract class StreamNegotiator {
* @return The PacketFilter that will return the packet relatable to the stream
* initiation.
*/
- public abstract PacketFilter getInitiationPacketFilter(String from, String streamID);
+ public abstract PacketFilter getInitiationPacketFilter(Jid from, String streamID);
abstract InputStream negotiateIncomingStream(Stanza streamInitiation) throws XMPPErrorException,
@@ -137,7 +138,7 @@ public abstract class StreamNegotiator {
* @throws InterruptedException
*/
public abstract OutputStream createOutgoingStream(String streamID,
- String initiator, String target) throws XMPPErrorException, NoResponseException, SmackException, XMPPException, InterruptedException;
+ Jid initiator, Jid target) throws XMPPErrorException, NoResponseException, SmackException, XMPPException, InterruptedException;
/**
* Returns the XMPP namespace reserved for this particular type of file
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/LastActivityManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/LastActivityManager.java
index 6e8b03fae..a3a1d1b2c 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/LastActivityManager.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/LastActivityManager.java
@@ -40,6 +40,7 @@ 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;
+import org.jxmpp.jid.Jid;
/**
* A last activity manager for handling information about the last activity
@@ -233,7 +234,7 @@ public class LastActivityManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public LastActivity getLastActivity(String jid) throws NoResponseException, XMPPErrorException,
+ public LastActivity getLastActivity(Jid jid) throws NoResponseException, XMPPErrorException,
NotConnectedException, InterruptedException {
LastActivity activity = new LastActivity(jid);
return (LastActivity) connection().createPacketCollectorAndSend(activity).nextResultOrThrow();
@@ -249,7 +250,7 @@ public class LastActivityManager extends Manager {
* @throws NoResponseException
* @throws InterruptedException
*/
- public boolean isLastActivitySupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public boolean isLastActivitySupported(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, LastActivity.NAMESPACE);
}
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/packet/LastActivity.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/packet/LastActivity.java
index b4cd6fcd6..43e9de00e 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/packet/LastActivity.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqlast/packet/LastActivity.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
+import org.jxmpp.jid.Jid;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -47,7 +48,7 @@ public class LastActivity extends IQ {
setType(IQ.Type.get);
}
- public LastActivity(String to) {
+ public LastActivity(Jid to) {
this();
setTo(to);
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/AccountManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/AccountManager.java
index f3296c867..d673f9753 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/AccountManager.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/AccountManager.java
@@ -34,7 +34,6 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.iqregister.packet.Registration;
-import org.jxmpp.util.XmppStringUtils;
/**
* Allows creation and management of accounts on an XMPP server.
@@ -253,7 +252,7 @@ public class AccountManager extends Manager {
*/
public void changePassword(String newPassword) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
Map map = new HashMap();
- map.put("username",XmppStringUtils.parseLocalpart(connection().getUser()));
+ map.put("username", connection().getUser().getLocalpart().toString());
map.put("password",newPassword);
Registration reg = new Registration(map);
reg.setType(IQ.Type.set);
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/VersionManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/VersionManager.java
index 2681d9b2d..8f081e679 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/VersionManager.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/VersionManager.java
@@ -35,6 +35,7 @@ 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;
+import org.jxmpp.jid.Jid;
/**
* A Version Manager that automatically responds to version IQs with a predetermined reply.
@@ -123,7 +124,7 @@ public class VersionManager extends Manager {
ourVersion = null;
}
- public boolean isSupported(String jid) throws NoResponseException, XMPPErrorException,
+ public boolean isSupported(Jid jid) throws NoResponseException, XMPPErrorException,
NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid,
Version.NAMESPACE);
@@ -139,7 +140,7 @@ public class VersionManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public Version getVersion(String jid) throws NoResponseException, XMPPErrorException,
+ public Version getVersion(Jid jid) throws NoResponseException, XMPPErrorException,
NotConnectedException, InterruptedException {
if (!isSupported(jid)) {
return null;
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/packet/Version.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/packet/Version.java
index 58e592849..6a72a919f 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/packet/Version.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqversion/packet/Version.java
@@ -21,6 +21,7 @@ package org.jivesoftware.smackx.iqversion.packet;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.util.StringUtils;
+import org.jxmpp.jid.Jid;
/**
* A Version IQ packet, which is used by XMPP clients to discover version information
@@ -68,7 +69,7 @@ public class Version extends IQ {
*
* @param to the jid where to request version from
*/
- public Version(String to) {
+ public Version(Jid to) {
this();
setTo(to);
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/Affiliate.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/Affiliate.java
index 8177a75c0..1a41c59e5 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/Affiliate.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/Affiliate.java
@@ -18,6 +18,8 @@
package org.jivesoftware.smackx.muc;
import org.jivesoftware.smackx.muc.packet.MUCItem;
+import org.jxmpp.jid.Jid;
+import org.jxmpp.jid.parts.Resourcepart;
/**
* Represents an affiliation of a user to a given room. The affiliate's information will always have
@@ -28,12 +30,12 @@ import org.jivesoftware.smackx.muc.packet.MUCItem;
*/
public class Affiliate {
// Fields that must have a value
- private final String jid;
+ private final Jid jid;
private final MUCAffiliation affiliation;
// Fields that may have a value
private final MUCRole role;
- private final String nick;
+ private final Resourcepart nick;
Affiliate(MUCItem item) {
this.jid = item.getJid();
@@ -47,7 +49,7 @@ public class Affiliate {
*
* @return the bare JID of the affiliated user.
*/
- public String getJid() {
+ public Jid getJid() {
return jid;
}
@@ -79,7 +81,7 @@ public class Affiliate {
* @return the current nickname of the affiliated user in the room or null if the user is not in
* the room.
*/
- public String getNick() {
+ public Resourcepart getNick() {
return nick;
}
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DefaultParticipantStatusListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DefaultParticipantStatusListener.java
index 258ad6d14..4578accc7 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DefaultParticipantStatusListener.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DefaultParticipantStatusListener.java
@@ -17,6 +17,10 @@
package org.jivesoftware.smackx.muc;
+import org.jxmpp.jid.FullJid;
+import org.jxmpp.jid.Jid;
+import org.jxmpp.jid.parts.Resourcepart;
+
/**
* Default implementation of the ParticipantStatusListener interface.
*
@@ -28,49 +32,49 @@ package org.jivesoftware.smackx.muc;
*/
public class DefaultParticipantStatusListener implements ParticipantStatusListener {
- public void joined(String participant) {
+ public void joined(FullJid participant) {
}
- public void left(String participant) {
+ public void left(FullJid participant) {
}
- public void kicked(String participant, String actor, String reason) {
+ public void kicked(FullJid participant, Jid actor, String reason) {
}
- public void voiceGranted(String participant) {
+ public void voiceGranted(FullJid participant) {
}
- public void voiceRevoked(String participant) {
+ public void voiceRevoked(FullJid participant) {
}
- public void banned(String participant, String actor, String reason) {
+ public void banned(FullJid participant, Jid actor, String reason) {
}
- public void membershipGranted(String participant) {
+ public void membershipGranted(FullJid participant) {
}
- public void membershipRevoked(String participant) {
+ public void membershipRevoked(FullJid participant) {
}
- public void moderatorGranted(String participant) {
+ public void moderatorGranted(FullJid participant) {
}
- public void moderatorRevoked(String participant) {
+ public void moderatorRevoked(FullJid participant) {
}
- public void ownershipGranted(String participant) {
+ public void ownershipGranted(FullJid participant) {
}
- public void ownershipRevoked(String participant) {
+ public void ownershipRevoked(FullJid participant) {
}
- public void adminGranted(String participant) {
+ public void adminGranted(FullJid participant) {
}
- public void adminRevoked(String participant) {
+ public void adminRevoked(FullJid participant) {
}
- public void nicknameChanged(String participant, String newNickname) {
+ public void nicknameChanged(FullJid participant, Resourcepart newNickname) {
}
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DefaultUserStatusListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DefaultUserStatusListener.java
index f83b88419..9d9757465 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DefaultUserStatusListener.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DefaultUserStatusListener.java
@@ -17,6 +17,8 @@
package org.jivesoftware.smackx.muc;
+import org.jxmpp.jid.Jid;
+
/**
* Default implementation of the UserStatusListener interface.
*
@@ -28,7 +30,7 @@ package org.jivesoftware.smackx.muc;
*/
public class DefaultUserStatusListener implements UserStatusListener {
- public void kicked(String actor, String reason) {
+ public void kicked(Jid actor, String reason) {
}
public void voiceGranted() {
@@ -37,7 +39,7 @@ public class DefaultUserStatusListener implements UserStatusListener {
public void voiceRevoked() {
}
- public void banned(String actor, String reason) {
+ public void banned(Jid actor, String reason) {
}
public void membershipGranted() {
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/HostedRoom.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/HostedRoom.java
index 0c15b352d..5d4defa1e 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/HostedRoom.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/HostedRoom.java
@@ -17,21 +17,22 @@
package org.jivesoftware.smackx.muc;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
+import org.jxmpp.jid.Jid;
/**
* Hosted rooms by a chat service may be discovered if they are configured to appear in the room
* directory . The information that may be discovered is the XMPP address of the room and the room
* name. The address of the room may be used for obtaining more detailed information
- * {@link org.jivesoftware.smackx.muc.MultiUserChatManager#getRoomInfo(String)}
+ * {@link org.jivesoftware.smackx.muc.MultiUserChatManager#getRoomInfo(org.jxmpp.jid.BareJid)}
* or could be used for joining the room
- * {@link org.jivesoftware.smackx.muc.MultiUserChatManager#getMultiUserChat(String)}
- * and {@link org.jivesoftware.smackx.muc.MultiUserChat#join(String)}.
+ * {@link org.jivesoftware.smackx.muc.MultiUserChatManager#getMultiUserChat(org.jxmpp.jid.BareJid)}
+ * and {@link org.jivesoftware.smackx.muc.MultiUserChat#join(org.jxmpp.jid.parts.Resourcepart)}.
*
* @author Gaston Dombiak
*/
public class HostedRoom {
- private final String jid;
+ private final Jid jid;
private final String name;
@@ -46,7 +47,7 @@ public class HostedRoom {
*
* @return the XMPP address of the hosted room by the chat service.
*/
- public String getJid() {
+ public Jid getJid() {
return jid;
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java
index 87d26566f..3a02dcb96 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java
@@ -19,9 +19,7 @@ package org.jivesoftware.smackx.muc;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
-import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@@ -69,9 +67,15 @@ import org.jivesoftware.smackx.muc.packet.MUCUser.Status;
import org.jivesoftware.smackx.xdata.Form;
import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.packet.DataForm;
+import org.jxmpp.jid.BareJid;
+import org.jxmpp.jid.FullJid;
+import org.jxmpp.jid.Jid;
+import org.jxmpp.jid.JidWithLocalpart;
+import org.jxmpp.jid.impl.JidCreate;
+import org.jxmpp.jid.parts.Resourcepart;
/**
- * A MultiUserChat room (XEP-45), created with {@link MultiUserChatManager#getMultiUserChat(String)}.
+ * A MultiUserChat room (XEP-45), created with {@link MultiUserChatManager#getMultiUserChat(BareJid)}.
*
* A MultiUserChat is a conversation that takes place among many users in a virtual
* room. A room could have many occupants with different affiliation and roles.
@@ -91,9 +95,9 @@ public class MultiUserChat {
private static final Logger LOGGER = Logger.getLogger(MultiUserChat.class.getName());
private final XMPPConnection connection;
- private final String room;
+ private final BareJid room;
private final MultiUserChatManager multiUserChatManager;
- private final Map occupantsMap = new ConcurrentHashMap();
+ private final Map occupantsMap = new ConcurrentHashMap<>();
private final Set invitationRejectionListeners = new CopyOnWriteArraySet();
private final Set subjectUpdatedListeners = new CopyOnWriteArraySet();
@@ -122,13 +126,13 @@ public class MultiUserChat {
private final PacketListener declinesListener;
private String subject;
- private String nickname = null;
+ private Resourcepart nickname;
private boolean joined = false;
private PacketCollector messageCollector;
- MultiUserChat(XMPPConnection connection, String room, MultiUserChatManager multiUserChatManager) {
+ MultiUserChat(XMPPConnection connection, BareJid room, MultiUserChatManager multiUserChatManager) {
this.connection = connection;
- this.room = room.toLowerCase(Locale.US);
+ this.room = room;
this.multiUserChatManager = multiUserChatManager;
fromRoomFilter = FromMatchesFilter.create(room);
@@ -148,11 +152,16 @@ public class MultiUserChat {
subjectListener = new PacketListener() {
public void processPacket(Stanza packet) {
Message msg = (Message) packet;
+ FullJid from = msg.getFrom().asFullJidIfPossible();
+ if (from == null) {
+ LOGGER.warning("Message subject not changed by a full JID: " + msg.getFrom());
+ return;
+ }
// Update the room subject
subject = msg.getSubject();
// Fire event for subject updated listeners
for (SubjectUpdatedListener listener : subjectUpdatedListeners) {
- listener.subjectUpdated(subject, msg.getFrom());
+ listener.subjectUpdated(subject, from);
}
}
};
@@ -161,7 +170,11 @@ public class MultiUserChat {
presenceListener = new PacketListener() {
public void processPacket(Stanza packet) {
Presence presence = (Presence) packet;
- String from = presence.getFrom();
+ final FullJid from = presence.getFrom().asFullJidIfPossible();
+ if (from == null) {
+ LOGGER.warning("Presence not from a full JID: " + presence.getFrom());
+ return;
+ }
String myRoomJID = MultiUserChat.this.room + "/" + nickname;
boolean isUserStatusModification = presence.getFrom().equals(myRoomJID);
switch (presence.getType()) {
@@ -254,7 +267,7 @@ public class MultiUserChat {
*
* @return the multi user chat room name.
*/
- public String getRoom() {
+ public BareJid getRoom() {
return room;
}
@@ -272,14 +285,15 @@ public class MultiUserChat {
* @throws InterruptedException
* @see XEP-45 7.2 Entering a Room
*/
- private Presence enter(String nickname, String password, DiscussionHistory history,
+ private Presence enter(Resourcepart nickname, String password, DiscussionHistory history,
long timeout) throws NotConnectedException, NoResponseException,
XMPPErrorException, InterruptedException {
StringUtils.requireNotNullOrEmpty(nickname, "Nickname must not be null or blank.");
// We enter a room by sending a presence packet where the "to"
// field is in the form "roomName@service/nickname"
Presence joinPresence = new Presence(Presence.Type.available);
- joinPresence.setTo(room + "/" + nickname);
+ final FullJid jid = JidCreate.fullFrom(room, nickname);
+ joinPresence.setTo(jid);
// Indicate the the client supports MUC
MUCInitialPresence mucInitialPresence = new MUCInitialPresence();
@@ -292,8 +306,7 @@ public class MultiUserChat {
joinPresence.addExtension(mucInitialPresence);
// Wait for a presence packet back from the server.
- PacketFilter responseFilter = new AndFilter(FromMatchesFilter.createFull(room + "/"
- + nickname), new PacketTypeFilter(Presence.class));
+ PacketFilter responseFilter = new AndFilter(FromMatchesFilter.createFull(jid), new PacketTypeFilter(Presence.class));
// Setup the messageListeners and presenceListeners *before* the join presence is send.
connection.addSyncPacketListener(messageListener, fromRoomGroupchatFilter);
@@ -348,7 +361,7 @@ public class MultiUserChat {
* server, e.g. because the room already existed.
* @throws InterruptedException
*/
- public synchronized void create(String nickname) throws NoResponseException, XMPPErrorException, SmackException, InterruptedException {
+ public synchronized void create(Resourcepart nickname) throws NoResponseException, XMPPErrorException, SmackException, InterruptedException {
if (joined) {
throw new IllegalStateException("Creation failed - User already joined the room.");
}
@@ -363,7 +376,7 @@ public class MultiUserChat {
}
/**
- * Same as {@link #createOrJoin(String, String, DiscussionHistory, long)}, but without a password, specifying a
+ * Same as {@link #createOrJoin(Resourcepart, String, DiscussionHistory, long)}, but without a password, specifying a
* discussion history and using the connections default reply timeout.
*
* @param nickname
@@ -372,15 +385,15 @@ public class MultiUserChat {
* @throws XMPPErrorException
* @throws SmackException
* @throws InterruptedException
- * @see #createOrJoin(String, String, DiscussionHistory, long)
+ * @see #createOrJoin(Resourcepart, String, DiscussionHistory, long)
*/
- public synchronized boolean createOrJoin(String nickname) throws NoResponseException, XMPPErrorException,
+ public synchronized boolean createOrJoin(Resourcepart nickname) throws NoResponseException, XMPPErrorException,
SmackException, InterruptedException {
return createOrJoin(nickname, null, null, connection.getPacketReplyTimeout());
}
/**
- * Like {@link #create(String)}, but will return true if the room creation was acknowledged by
+ * Like {@link #create(Resourcepart)}, but will return true if the room creation was acknowledged by
* the service (with an 201 status code). It's up to the caller to decide, based on the return
* value, if he needs to continue sending the room configuration. If false is returned, the room
* already existed and the user is able to join right away, without sending a form.
@@ -395,7 +408,7 @@ public class MultiUserChat {
* @throws NoResponseException if there was no response from the server.
* @throws InterruptedException
*/
- public synchronized boolean createOrJoin(String nickname, String password, DiscussionHistory history, long timeout)
+ public synchronized boolean createOrJoin(Resourcepart nickname, String password, DiscussionHistory history, long timeout)
throws NoResponseException, XMPPErrorException, SmackException, InterruptedException {
if (joined) {
throw new IllegalStateException("Creation failed - User already joined the room.");
@@ -431,7 +444,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void join(String nickname) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public void join(Resourcepart nickname) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
join(nickname, null, null, connection.getPacketReplyTimeout());
}
@@ -456,7 +469,7 @@ public class MultiUserChat {
* @throws SmackException if there was no response from the server.
* @throws InterruptedException
*/
- public void join(String nickname, String password) throws XMPPErrorException, SmackException, InterruptedException {
+ public void join(Resourcepart nickname, String password) throws XMPPErrorException, SmackException, InterruptedException {
join(nickname, password, null, connection.getPacketReplyTimeout());
}
@@ -489,7 +502,7 @@ public class MultiUserChat {
* @throws InterruptedException
*/
public synchronized void join(
- String nickname,
+ Resourcepart nickname,
String password,
DiscussionHistory history,
long timeout)
@@ -504,7 +517,7 @@ public class MultiUserChat {
/**
* Returns true if currently in the multi user chat (after calling the {@link
- * #join(String)} method).
+ * #join(Resourcepart)} method).
*
* @return true if currently in the multi user chat room.
*/
@@ -525,7 +538,7 @@ public class MultiUserChat {
// We leave a room by sending a presence packet where the "to"
// field is in the form "roomName@service/nickname"
Presence leavePresence = new Presence(Presence.Type.unavailable);
- leavePresence.setTo(room + "/" + nickname);
+ leavePresence.setTo(JidCreate.fullFrom(room, nickname));
connection.sendPacket(leavePresence);
// Reset occupant information.
occupantsMap.clear();
@@ -841,7 +854,7 @@ public class MultiUserChat {
*
* @return the nickname currently being used.
*/
- public String getNickname() {
+ public Resourcepart getNickname() {
return nickname;
}
@@ -858,23 +871,24 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void changeNickname(String nickname) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public void changeNickname(Resourcepart nickname) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
StringUtils.requireNotNullOrEmpty(nickname, "Nickname must not be null or blank.");
// Check that we already have joined the room before attempting to change the
// nickname.
if (!joined) {
throw new IllegalStateException("Must be logged into the room to change nickname.");
}
+ final FullJid jid = JidCreate.fullFrom(room, nickname);
// We change the nickname by sending a presence packet where the "to"
// field is in the form "roomName@service/nickname"
// We don't have to signal the MUC support again
Presence joinPresence = new Presence(Presence.Type.available);
- joinPresence.setTo(room + "/" + nickname);
+ joinPresence.setTo(jid);
// Wait for a presence packet back from the server.
PacketFilter responseFilter =
new AndFilter(
- FromMatchesFilter.createFull(room + "/" + nickname),
+ FromMatchesFilter.createFull(jid),
new PacketTypeFilter(Presence.class));
PacketCollector response = connection.createPacketCollectorAndSend(responseFilter, joinPresence);
// Wait up to a certain number of seconds for a reply. If there is a negative reply, an
@@ -907,7 +921,7 @@ public class MultiUserChat {
Presence joinPresence = new Presence(Presence.Type.available);
joinPresence.setStatus(status);
joinPresence.setMode(mode);
- joinPresence.setTo(room + "/" + nickname);
+ joinPresence.setTo(JidCreate.fullFrom(room, nickname));
// Send join packet.
connection.sendPacket(joinPresence);
@@ -934,7 +948,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void kickParticipant(String nickname, String reason) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void kickParticipant(Resourcepart nickname, String reason) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeRole(nickname, MUCRole.none, reason);
}
@@ -976,7 +990,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void grantVoice(Collection nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void grantVoice(Collection nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeRole(nicknames, MUCRole.participant);
}
@@ -994,7 +1008,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void grantVoice(String nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void grantVoice(Resourcepart nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeRole(nickname, MUCRole.participant, null);
}
@@ -1012,7 +1026,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void revokeVoice(Collection nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void revokeVoice(Collection nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeRole(nicknames, MUCRole.visitor);
}
@@ -1030,7 +1044,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void revokeVoice(String nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void revokeVoice(Resourcepart nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeRole(nickname, MUCRole.visitor, null);
}
@@ -1049,7 +1063,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void banUsers(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void banUsers(Collection extends Jid> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeAffiliationByAdmin(jids, MUCAffiliation.outcast);
}
@@ -1069,7 +1083,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void banUser(String jid, String reason) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void banUser(Jid jid, String reason) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeAffiliationByAdmin(jid, MUCAffiliation.outcast, reason);
}
@@ -1084,7 +1098,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void grantMembership(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void grantMembership(Collection extends Jid> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeAffiliationByAdmin(jids, MUCAffiliation.member);
}
@@ -1099,7 +1113,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void grantMembership(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void grantMembership(Jid jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeAffiliationByAdmin(jid, MUCAffiliation.member, null);
}
@@ -1115,7 +1129,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void revokeMembership(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void revokeMembership(Collection extends Jid> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeAffiliationByAdmin(jids, MUCAffiliation.none);
}
@@ -1131,7 +1145,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void revokeMembership(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void revokeMembership(Jid jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeAffiliationByAdmin(jid, MUCAffiliation.none, null);
}
@@ -1146,7 +1160,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void grantModerator(Collection nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void grantModerator(Collection nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeRole(nicknames, MUCRole.moderator);
}
@@ -1161,7 +1175,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void grantModerator(String nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void grantModerator(Resourcepart nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeRole(nickname, MUCRole.moderator, null);
}
@@ -1177,7 +1191,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void revokeModerator(Collection nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void revokeModerator(Collection nicknames) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeRole(nicknames, MUCRole.participant);
}
@@ -1193,7 +1207,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void revokeModerator(String nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void revokeModerator(Resourcepart nickname) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeRole(nickname, MUCRole.participant, null);
}
@@ -1209,7 +1223,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void grantOwnership(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void grantOwnership(Collection extends Jid> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeAffiliationByAdmin(jids, MUCAffiliation.owner);
}
@@ -1225,7 +1239,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void grantOwnership(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void grantOwnership(Jid jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeAffiliationByAdmin(jid, MUCAffiliation.owner, null);
}
@@ -1240,7 +1254,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void revokeOwnership(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void revokeOwnership(Collection extends Jid> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeAffiliationByAdmin(jids, MUCAffiliation.admin);
}
@@ -1255,7 +1269,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void revokeOwnership(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void revokeOwnership(Jid jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeAffiliationByAdmin(jid, MUCAffiliation.admin, null);
}
@@ -1270,7 +1284,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void grantAdmin(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void grantAdmin(Collection extends Jid> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeAffiliationByAdmin(jids, MUCAffiliation.admin);
}
@@ -1286,7 +1300,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void grantAdmin(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void grantAdmin(Jid jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeAffiliationByAdmin(jid, MUCAffiliation.admin);
}
@@ -1301,7 +1315,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void revokeAdmin(Collection jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void revokeAdmin(Collection extends Jid> jids) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeAffiliationByAdmin(jids, MUCAffiliation.admin);
}
@@ -1317,7 +1331,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void revokeAdmin(String jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
+ public void revokeAdmin(JidWithLocalpart jid) throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException {
changeAffiliationByAdmin(jid, MUCAffiliation.member);
}
@@ -1331,7 +1345,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- private void changeAffiliationByAdmin(String jid, MUCAffiliation affiliation)
+ private void changeAffiliationByAdmin(Jid jid, MUCAffiliation affiliation)
throws NoResponseException, XMPPErrorException,
NotConnectedException, InterruptedException {
changeAffiliationByAdmin(jid, affiliation, null);
@@ -1348,7 +1362,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
- private void changeAffiliationByAdmin(String jid, MUCAffiliation affiliation, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
+ private void changeAffiliationByAdmin(Jid jid, MUCAffiliation affiliation, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
MUCAdmin iq = new MUCAdmin();
iq.setTo(room);
@@ -1360,12 +1374,12 @@ public class MultiUserChat {
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
}
- private void changeAffiliationByAdmin(Collection jids, MUCAffiliation affiliation)
+ private void changeAffiliationByAdmin(Collection extends Jid> jids, MUCAffiliation affiliation)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCAdmin iq = new MUCAdmin();
iq.setTo(room);
iq.setType(IQ.Type.set);
- for (String jid : jids) {
+ for (Jid jid : jids) {
// Set the new affiliation.
MUCItem item = new MUCItem(affiliation, jid);
iq.addItem(item);
@@ -1374,7 +1388,7 @@ public class MultiUserChat {
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
}
- private void changeRole(String nickname, MUCRole role, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ private void changeRole(Resourcepart nickname, MUCRole role, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCAdmin iq = new MUCAdmin();
iq.setTo(room);
iq.setType(IQ.Type.set);
@@ -1385,11 +1399,11 @@ public class MultiUserChat {
connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
}
- private void changeRole(Collection nicknames, MUCRole role) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ private void changeRole(Collection nicknames, MUCRole role) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCAdmin iq = new MUCAdmin();
iq.setTo(room);
iq.setType(IQ.Type.set);
- for (String nickname : nicknames) {
+ for (Resourcepart nickname : nicknames) {
// Set the new role.
MUCItem item = new MUCItem(role, nickname);
iq.addItem(item);
@@ -1413,7 +1427,7 @@ public class MultiUserChat {
}
/**
- * Returns an Iterator (of Strings) for the list of fully qualified occupants
+ * Returns an List for the list of fully qualified occupants
* in the group chat. For example, "conference@chat.jivesoftware.com/SomeUser".
* Typically, a client would only display the nickname of the occupant. To
* get the nickname from the fully qualified name, use the
@@ -1423,8 +1437,8 @@ public class MultiUserChat {
*
* @return a List of the occupants in the group chat.
*/
- public List getOccupants() {
- return Collections.unmodifiableList(new ArrayList(occupantsMap.keySet()));
+ public List getOccupants() {
+ return new ArrayList<>(occupantsMap.keySet());
}
/**
@@ -1642,7 +1656,7 @@ public class MultiUserChat {
* created chat.
* @return new Chat for sending private messages to a given room occupant.
*/
- public Chat createPrivateChat(String occupant, ChatMessageListener listener) {
+ public Chat createPrivateChat(FullJid occupant, ChatMessageListener listener) {
return ChatManager.getInstanceFor(connection).createChat(occupant, listener);
}
@@ -1884,7 +1898,7 @@ public class MultiUserChat {
MUCRole oldRole,
MUCRole newRole,
boolean isUserModification,
- String from) {
+ FullJid from) {
// Voice was granted to a visitor
if (("visitor".equals(oldRole) || "none".equals(oldRole))
&& "participant".equals(newRole)) {
@@ -2010,7 +2024,7 @@ public class MultiUserChat {
MUCAffiliation oldAffiliation,
MUCAffiliation newAffiliation,
boolean isUserModification,
- String from) {
+ FullJid from) {
// First check for revoked affiliation and then for granted affiliations. The idea is to
// first fire the "revoke" events and then fire the "grant" events.
@@ -2107,7 +2121,7 @@ public class MultiUserChat {
Set statusCodes,
boolean isUserModification,
MUCUser mucUser,
- String from) {
+ FullJid from) {
// Check if an occupant was kicked from the room
if (statusCodes.contains(Status.KICKED_307)) {
// Check if this occupant was kicked
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java
index f55ba50b8..5724dbb01 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java
@@ -26,6 +26,7 @@ import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.logging.Logger;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.Manager;
@@ -49,10 +50,16 @@ import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
import org.jivesoftware.smackx.muc.packet.MUCInitialPresence;
import org.jivesoftware.smackx.muc.packet.MUCUser;
+import org.jxmpp.jid.BareJid;
+import org.jxmpp.jid.DomainBareJid;
+import org.jxmpp.jid.Jid;
+import org.jxmpp.jid.JidWithLocalpart;
public class MultiUserChatManager extends Manager {
private final static String DISCO_NODE = MUCInitialPresence.NAMESPACE + "#rooms";
+ private static final Logger LOGGER = Logger.getLogger(MultiUserChatManager.class.getName());
+
static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(final XMPPConnection connection) {
@@ -71,9 +78,9 @@ public class MultiUserChatManager extends Manager {
XMPPConnection connection = weakRefConnection.get();
if (connection == null)
return Collections.emptyList();
- Set joinedRooms = MultiUserChatManager.getInstanceFor(connection).getJoinedRooms();
+ Set joinedRooms = MultiUserChatManager.getInstanceFor(connection).getJoinedRooms();
List answer = new ArrayList();
- for (String room : joinedRooms) {
+ for (BareJid room : joinedRooms) {
answer.add(new DiscoverItems.Item(room));
}
return answer;
@@ -104,14 +111,14 @@ public class MultiUserChatManager extends Manager {
new NotFilter(MessageTypeFilter.ERROR));
private final Set invitationsListeners = new CopyOnWriteArraySet();
- private final Set joinedRooms = new HashSet();
+ private final Set joinedRooms = new HashSet<>();
/**
* A Map of MUC JIDs to {@link MultiUserChat} instances. We use weak references for the values in order to allow
* those instances to get garbage collected. Note that MultiUserChat instances can not get garbage collected while
* the user is joined, because then the MUC will have PacketListeners added to the XMPPConnection.
*/
- private final Map> multiUserChats = new HashMap>();
+ private final Map> multiUserChats = new HashMap<>();
private MultiUserChatManager(XMPPConnection connection) {
super(connection);
@@ -124,8 +131,13 @@ public class MultiUserChatManager extends Manager {
final MUCUser mucUser = MUCUser.from(message);
// Check if the MUCUser extension includes an invitation
if (mucUser.getInvite() != null) {
+ BareJid mucJid = message.getFrom().asBareJidIfPossible();
+ if (mucJid == null) {
+ LOGGER.warning("Invite to non bare JID: '" + message.toXML() + "'");
+ return;
+ }
// Fire event for invitation listeners
- final MultiUserChat muc = getMultiUserChat(packet.getFrom());
+ final MultiUserChat muc = getMultiUserChat(mucJid);
for (final InvitationListener listener : invitationsListeners) {
listener.invitationReceived(connection(), muc, mucUser.getInvite().getFrom(),
mucUser.getInvite().getReason(), mucUser.getPassword(), message);
@@ -138,7 +150,7 @@ public class MultiUserChatManager extends Manager {
/**
* Creates a multi user chat. Note: no information is sent to or received from the server until you attempt to
- * {@link MultiUserChat#join(String) join} the chat room. On some server implementations, the room will not be
+ * {@link MultiUserChat#join(org.jxmpp.jid.parts.Resourcepart) join} the chat room. On some server implementations, the room will not be
* created until the first person joins it.
*
* Most XMPP servers use a sub-domain for the chat service (eg chat.example.com for the XMPP server example.com).
@@ -148,7 +160,7 @@ public class MultiUserChatManager extends Manager {
* @param jid the name of the room in the form "roomName@service", where "service" is the hostname at which the
* multi-user chat service is running. Make sure to provide a valid JID.
*/
- public synchronized MultiUserChat getMultiUserChat(String jid) {
+ public synchronized MultiUserChat getMultiUserChat(BareJid jid) {
WeakReference weakRefMultiUserChat = multiUserChats.get(jid);
if (weakRefMultiUserChat == null) {
return createNewMucAndAddToMap(jid);
@@ -160,7 +172,7 @@ public class MultiUserChatManager extends Manager {
return multiUserChat;
}
- private MultiUserChat createNewMucAndAddToMap(String jid) {
+ private MultiUserChat createNewMucAndAddToMap(BareJid jid) {
MultiUserChat multiUserChat = new MultiUserChat(connection(), jid, this);
multiUserChats.put(jid, new WeakReference(multiUserChat));
return multiUserChat;
@@ -176,7 +188,7 @@ public class MultiUserChatManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public boolean isServiceEnabled(String user) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public boolean isServiceEnabled(Jid user) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(user, MUCInitialPresence.NAMESPACE);
}
@@ -186,7 +198,7 @@ public class MultiUserChatManager extends Manager {
*
* @return a List of the rooms where the user has joined using a given connection.
*/
- public Set getJoinedRooms() {
+ public Set getJoinedRooms() {
return Collections.unmodifiableSet(joinedRooms);
}
@@ -201,15 +213,20 @@ public class MultiUserChatManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public List getJoinedRooms(String user) throws NoResponseException, XMPPErrorException,
+ public List getJoinedRooms(JidWithLocalpart user) throws NoResponseException, XMPPErrorException,
NotConnectedException, InterruptedException {
// Send the disco packet to the user
DiscoverItems result = ServiceDiscoveryManager.getInstanceFor(connection()).discoverItems(user, DISCO_NODE);
List items = result.getItems();
- List answer = new ArrayList(items.size());
+ List answer = new ArrayList<>(items.size());
// Collect the entityID for each returned item
for (DiscoverItems.Item item : items) {
- answer.add(item.getEntityID());
+ BareJid muc = item.getEntityID().asBareJidIfPossible();
+ if (muc == null) {
+ LOGGER.warning("Not a bare JID: " + item.getEntityID());
+ continue;
+ }
+ answer.add(muc);
}
return answer;
}
@@ -225,7 +242,7 @@ public class MultiUserChatManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public RoomInfo getRoomInfo(String room) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public RoomInfo getRoomInfo(BareJid room) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
DiscoverInfo info = ServiceDiscoveryManager.getInstanceFor(connection()).discoverInfo(room);
return new RoomInfo(info);
}
@@ -239,7 +256,7 @@ public class MultiUserChatManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public List getServiceNames() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public List getServiceNames() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection());
return sdm.findServices(MUCInitialPresence.NAMESPACE, false, false);
}
@@ -256,7 +273,7 @@ public class MultiUserChatManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public List getHostedRooms(String serviceName) throws NoResponseException, XMPPErrorException,
+ public List getHostedRooms(DomainBareJid serviceName) throws NoResponseException, XMPPErrorException,
NotConnectedException, InterruptedException {
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection());
DiscoverItems discoverItems = discoManager.discoverItems(serviceName);
@@ -278,7 +295,7 @@ public class MultiUserChatManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void decline(String room, String inviter, String reason) throws NotConnectedException, InterruptedException {
+ public void decline(BareJid room, String inviter, String reason) throws NotConnectedException, InterruptedException {
Message message = new Message(room);
// Create the MUCUser packet that will include the rejection
@@ -311,11 +328,11 @@ public class MultiUserChatManager extends Manager {
invitationsListeners.remove(listener);
}
- void addJoinedRoom(String room) {
+ void addJoinedRoom(BareJid room) {
joinedRooms.add(room);
}
- void removeJoinedRoom(String room) {
+ void removeJoinedRoom(BareJid room) {
joinedRooms.remove(room);
}
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/Occupant.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/Occupant.java
index caa629d3d..0e6f93301 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/Occupant.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/Occupant.java
@@ -17,10 +17,14 @@
package org.jivesoftware.smackx.muc;
+import java.util.logging.Logger;
+
import org.jivesoftware.smackx.muc.packet.MUCItem;
import org.jivesoftware.smackx.muc.packet.MUCUser;
import org.jivesoftware.smack.packet.Presence;
-import org.jxmpp.util.XmppStringUtils;
+import org.jxmpp.jid.FullJid;
+import org.jxmpp.jid.Jid;
+import org.jxmpp.jid.parts.Resourcepart;
/**
* Represents the information about an occupant in a given room. The information will always have
@@ -29,12 +33,15 @@ import org.jxmpp.util.XmppStringUtils;
* @author Gaston Dombiak
*/
public class Occupant {
+
+ private static final Logger LOGGER = Logger.getLogger(Occupant.class.getName());
+
// Fields that must have a value
private final MUCAffiliation affiliation;
private final MUCRole role;
// Fields that may have a value
- private final String jid;
- private final String nick;
+ private final Jid jid;
+ private final Resourcepart nick;
Occupant(MUCItem item) {
this.jid = item.getJid();
@@ -51,7 +58,13 @@ public class Occupant {
this.affiliation = item.getAffiliation();
this.role = item.getRole();
// Get the nickname from the FROM attribute of the presence
- this.nick = XmppStringUtils.parseResource(presence.getFrom());
+ FullJid from = presence.getFrom().asFullJidIfPossible();
+ if (from == null) {
+ LOGGER.warning("Occupant presence without resource: " + presence.getFrom());
+ this.nick = null;
+ } else {
+ this.nick = from.getResourcepart();
+ }
}
/**
@@ -62,7 +75,7 @@ public class Occupant {
*
* @return the full JID of the occupant.
*/
- public String getJid() {
+ public Jid getJid() {
return jid;
}
@@ -93,7 +106,7 @@ public class Occupant {
* @return the current nickname of the occupant in the room or null if this information was
* obtained from a presence.
*/
- public String getNick() {
+ public Resourcepart getNick() {
return nick;
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/ParticipantStatusListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/ParticipantStatusListener.java
index 83c13ce24..2464540d8 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/ParticipantStatusListener.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/ParticipantStatusListener.java
@@ -17,6 +17,10 @@
package org.jivesoftware.smackx.muc;
+import org.jxmpp.jid.FullJid;
+import org.jxmpp.jid.Jid;
+import org.jxmpp.jid.parts.Resourcepart;
+
/**
* A listener that is fired anytime a participant's status in a room is changed, such as the
* user being kicked, banned, or granted admin permissions.
@@ -33,7 +37,7 @@ public interface ParticipantStatusListener {
* @param participant the participant that has just joined the room
* (e.g. room@conference.jabber.org/nick).
*/
- public abstract void joined(String participant);
+ public abstract void joined(FullJid participant);
/**
* Called when a room occupant has left the room on its own. This means that the occupant was
@@ -42,7 +46,7 @@ public interface ParticipantStatusListener {
* @param participant the participant that has left the room on its own.
* (e.g. room@conference.jabber.org/nick).
*/
- public abstract void left(String participant);
+ public abstract void left(FullJid participant);
/**
* Called when a room participant has been kicked from the room. This means that the kicked
@@ -53,7 +57,7 @@ public interface ParticipantStatusListener {
* @param actor the moderator that kicked the occupant from the room (e.g. user@host.org).
* @param reason the reason provided by the actor to kick the occupant from the room.
*/
- public abstract void kicked(String participant, String actor, String reason);
+ public abstract void kicked(FullJid participant, Jid actor, String reason);
/**
* Called when a moderator grants voice to a visitor. This means that the visitor
@@ -62,7 +66,7 @@ public interface ParticipantStatusListener {
* @param participant the participant that was granted voice in the room
* (e.g. room@conference.jabber.org/nick).
*/
- public abstract void voiceGranted(String participant);
+ public abstract void voiceGranted(FullJid participant);
/**
* Called when a moderator revokes voice from a participant. This means that the participant
@@ -72,7 +76,7 @@ public interface ParticipantStatusListener {
* @param participant the participant that was revoked voice from the room
* (e.g. room@conference.jabber.org/nick).
*/
- public abstract void voiceRevoked(String participant);
+ public abstract void voiceRevoked(FullJid participant);
/**
* Called when an administrator or owner banned a participant from the room. This means that
@@ -83,7 +87,7 @@ public interface ParticipantStatusListener {
* @param actor the administrator that banned the occupant (e.g. user@host.org).
* @param reason the reason provided by the administrator to ban the occupant.
*/
- public abstract void banned(String participant, String actor, String reason);
+ public abstract void banned(FullJid participant, Jid actor, String reason);
/**
* Called when an administrator grants a user membership to the room. This means that the user
@@ -92,7 +96,7 @@ public interface ParticipantStatusListener {
* @param participant the participant that was granted membership in the room
* (e.g. room@conference.jabber.org/nick).
*/
- public abstract void membershipGranted(String participant);
+ public abstract void membershipGranted(FullJid participant);
/**
* Called when an administrator revokes a user membership to the room. This means that the
@@ -101,7 +105,7 @@ public interface ParticipantStatusListener {
* @param participant the participant that was revoked membership from the room
* (e.g. room@conference.jabber.org/nick).
*/
- public abstract void membershipRevoked(String participant);
+ public abstract void membershipRevoked(FullJid participant);
/**
* Called when an administrator grants moderator privileges to a user. This means that the user
@@ -111,7 +115,7 @@ public interface ParticipantStatusListener {
* @param participant the participant that was granted moderator privileges in the room
* (e.g. room@conference.jabber.org/nick).
*/
- public abstract void moderatorGranted(String participant);
+ public abstract void moderatorGranted(FullJid participant);
/**
* Called when an administrator revokes moderator privileges from a user. This means that the
@@ -121,7 +125,7 @@ public interface ParticipantStatusListener {
* @param participant the participant that was revoked moderator privileges in the room
* (e.g. room@conference.jabber.org/nick).
*/
- public abstract void moderatorRevoked(String participant);
+ public abstract void moderatorRevoked(FullJid participant);
/**
* Called when an owner grants a user ownership on the room. This means that the user
@@ -131,7 +135,7 @@ public interface ParticipantStatusListener {
* @param participant the participant that was granted ownership on the room
* (e.g. room@conference.jabber.org/nick).
*/
- public abstract void ownershipGranted(String participant);
+ public abstract void ownershipGranted(FullJid participant);
/**
* Called when an owner revokes a user ownership on the room. This means that the user
@@ -141,7 +145,7 @@ public interface ParticipantStatusListener {
* @param participant the participant that was revoked ownership on the room
* (e.g. room@conference.jabber.org/nick).
*/
- public abstract void ownershipRevoked(String participant);
+ public abstract void ownershipRevoked(FullJid participant);
/**
* Called when an owner grants administrator privileges to a user. This means that the user
@@ -151,7 +155,7 @@ public interface ParticipantStatusListener {
* @param participant the participant that was granted administrator privileges
* (e.g. room@conference.jabber.org/nick).
*/
- public abstract void adminGranted(String participant);
+ public abstract void adminGranted(FullJid participant);
/**
* Called when an owner revokes administrator privileges from a user. This means that the user
@@ -161,7 +165,7 @@ public interface ParticipantStatusListener {
* @param participant the participant that was revoked administrator privileges
* (e.g. room@conference.jabber.org/nick).
*/
- public abstract void adminRevoked(String participant);
+ public abstract void adminRevoked(FullJid participant);
/**
* Called when a participant changed his/her nickname in the room. The new participant's
@@ -171,6 +175,6 @@ public interface ParticipantStatusListener {
* (e.g. room@conference.jabber.org/nick).
* @param newNickname the new nickname that the participant decided to use.
*/
- public abstract void nicknameChanged(String participant, String newNickname);
+ public abstract void nicknameChanged(FullJid participant, Resourcepart newNickname);
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/RoomInfo.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/RoomInfo.java
index 28c8ec872..4c38321d8 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/RoomInfo.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/RoomInfo.java
@@ -26,6 +26,8 @@ import java.util.logging.Logger;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.jivesoftware.smackx.xdata.Form;
import org.jivesoftware.smackx.xdata.FormField;
+import org.jxmpp.jid.BareJid;
+import org.jxmpp.jid.Jid;
/**
* Represents the room information that was discovered using Service Discovery. It's possible to
@@ -39,9 +41,9 @@ public class RoomInfo {
private static final Logger LOGGER = Logger.getLogger(RoomInfo.class.getName());
/**
- * JID of the room. The node of the JID is commonly used as the ID of the room or name.
+ * JID of the room. The localpart of the JID is commonly used as the ID of the room or name.
*/
- private final String room;
+ private final BareJid room;
/**
* Description of the room.
*/
@@ -128,7 +130,12 @@ public class RoomInfo {
private final Form form;
RoomInfo(DiscoverInfo info) {
- this.room = info.getFrom();
+ final Jid from = info.getFrom();
+ if (from != null) {
+ this.room = info.getFrom().asBareJidIfPossible();
+ } else {
+ this.room = null;
+ }
// Get the information based on the discovered features
this.membersOnly = info.containsFeature("muc_membersonly");
this.moderated = info.containsFeature("muc_moderated");
@@ -233,7 +240,7 @@ public class RoomInfo {
*
* @return the JID of the room whose information was discovered.
*/
- public String getRoom() {
+ public BareJid getRoom() {
return room;
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/SubjectUpdatedListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/SubjectUpdatedListener.java
index ac254a033..8c55a5695 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/SubjectUpdatedListener.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/SubjectUpdatedListener.java
@@ -17,6 +17,8 @@
package org.jivesoftware.smackx.muc;
+import org.jxmpp.jid.FullJid;
+
/**
* A listener that is fired anytime a MUC room changes its subject.
*
@@ -30,6 +32,6 @@ public interface SubjectUpdatedListener {
* @param subject the new room's subject.
* @param from the user that changed the room's subject (e.g. room@conference.jabber.org/nick).
*/
- public abstract void subjectUpdated(String subject, String from);
+ public abstract void subjectUpdated(String subject, FullJid from);
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/UserStatusListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/UserStatusListener.java
index 872bc10a9..4fe0329e8 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/UserStatusListener.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/UserStatusListener.java
@@ -17,6 +17,8 @@
package org.jivesoftware.smackx.muc;
+import org.jxmpp.jid.Jid;
+
/**
* A listener that is fired anytime your participant's status in a room is changed, such as the
* user being kicked, banned, or granted admin permissions.
@@ -32,7 +34,7 @@ public interface UserStatusListener {
* @param actor the moderator that kicked your user from the room (e.g. user@host.org).
* @param reason the reason provided by the actor to kick you from the room.
*/
- public abstract void kicked(String actor, String reason);
+ public abstract void kicked(Jid actor, String reason);
/**
* Called when a moderator grants voice to your user. This means that you were a visitor in
@@ -57,7 +59,7 @@ public interface UserStatusListener {
* @param actor the administrator that banned your user (e.g. user@host.org).
* @param reason the reason provided by the administrator to banned you.
*/
- public abstract void banned(String actor, String reason);
+ public abstract void banned(Jid actor, String reason);
/**
* Called when an administrator grants your user membership to the room. This means that you
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCItem.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCItem.java
index 7f1630390..9fb2216ac 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCItem.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCItem.java
@@ -21,6 +21,8 @@ import org.jivesoftware.smack.packet.NamedElement;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smackx.muc.MUCAffiliation;
import org.jivesoftware.smackx.muc.MUCRole;
+import org.jxmpp.jid.Jid;
+import org.jxmpp.jid.parts.Resourcepart;
/**
* Item child that holds information about roles, affiliation, jids and nicks.
@@ -32,10 +34,10 @@ public class MUCItem implements NamedElement {
private final MUCAffiliation affiliation;
private final MUCRole role;
- private final String actor;
+ private final Jid actor;
private final String reason;
- private final String jid;
- private final String nick;
+ private final Jid jid;
+ private final Resourcepart nick;
public MUCItem(MUCAffiliation affiliation) {
this(affiliation, null, null, null, null, null);
@@ -45,19 +47,19 @@ public class MUCItem implements NamedElement {
this(null, role, null, null, null, null);
}
- public MUCItem(MUCRole role, String nick) {
+ public MUCItem(MUCRole role, Resourcepart nick) {
this(null, role, null, null, null, nick);
}
- public MUCItem(MUCAffiliation affiliation, String jid, String reason) {
+ public MUCItem(MUCAffiliation affiliation, Jid jid, String reason) {
this(affiliation, null, null, reason, jid, null);
}
- public MUCItem(MUCAffiliation affiliation, String jid) {
+ public MUCItem(MUCAffiliation affiliation, Jid jid) {
this(affiliation, null, null, null, jid, null);
}
- public MUCItem(MUCRole role, String nick, String reason) {
+ public MUCItem(MUCRole role, Resourcepart nick, String reason) {
this(null, role, null, reason, null, nick);
}
@@ -71,8 +73,8 @@ public class MUCItem implements NamedElement {
* @param jid
* @param nick
*/
- public MUCItem(MUCAffiliation affiliation, MUCRole role, String actor,
- String reason, String jid, String nick) {
+ public MUCItem(MUCAffiliation affiliation, MUCRole role, Jid actor,
+ String reason, Jid jid, Resourcepart nick) {
this.affiliation = affiliation;
this.role = role;
this.actor = actor;
@@ -86,7 +88,7 @@ public class MUCItem implements NamedElement {
*
* @return the JID of an occupant in the room that was kicked or banned.
*/
- public String getActor() {
+ public Jid getActor() {
return actor;
}
@@ -118,7 +120,7 @@ public class MUCItem implements NamedElement {
*
* @return the room JID by which an occupant is identified within the room.
*/
- public String getJid() {
+ public Jid getJid() {
return jid;
}
@@ -128,7 +130,7 @@ public class MUCItem implements NamedElement {
*
* @return the new nickname of an occupant that is changing his/her nickname.
*/
- public String getNick() {
+ public Resourcepart getNick() {
return nick;
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/MUCParserUtils.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/MUCParserUtils.java
index c3f3f85fa..a143d7418 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/MUCParserUtils.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/MUCParserUtils.java
@@ -18,10 +18,13 @@ package org.jivesoftware.smackx.muc.provider;
import java.io.IOException;
+import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smackx.muc.MUCAffiliation;
import org.jivesoftware.smackx.muc.MUCRole;
import org.jivesoftware.smackx.muc.packet.Destroy;
import org.jivesoftware.smackx.muc.packet.MUCItem;
+import org.jxmpp.jid.Jid;
+import org.jxmpp.jid.parts.Resourcepart;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -29,10 +32,10 @@ public class MUCParserUtils {
public static MUCItem parseItem(XmlPullParser parser) throws XmlPullParserException, IOException {
int initialDepth = parser.getDepth();
MUCAffiliation affiliation = MUCAffiliation.fromString(parser.getAttributeValue("", "affiliation"));
- String nick = parser.getAttributeValue("", "nick");
+ Resourcepart nick = ParserUtils.getResourcepartAttribute(parser, "nick");
MUCRole role = MUCRole.fromString(parser.getAttributeValue("", "role"));
- String jid = parser.getAttributeValue("", "jid");
- String actor = null;
+ Jid jid = ParserUtils.getJidAttribute(parser);
+ Jid actor = null;
String reason = null;
outerloop: while (true) {
int eventType = parser.next();
@@ -41,7 +44,7 @@ public class MUCParserUtils {
String name = parser.getName();
switch (name) {
case "actor":
- actor = parser.getAttributeValue("", "jid");
+ actor = ParserUtils.getJidAttribute(parser);
break;
case "reason":
reason = parser.nextText();
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageHeader.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageHeader.java
index a43ecf1f4..e604e376d 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageHeader.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageHeader.java
@@ -18,6 +18,7 @@
package org.jivesoftware.smackx.offline;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
+import org.jxmpp.jid.Jid;
/**
* The OfflineMessageHeader holds header information of an offline message. The header
@@ -32,7 +33,7 @@ public class OfflineMessageHeader {
/**
* Bare JID of the user that was offline when the message was sent.
*/
- private String user;
+ private Jid user;
/**
* Full JID of the user that sent the message.
*/
@@ -56,7 +57,7 @@ public class OfflineMessageHeader {
*
* @return the bare JID of the user that was offline when the message was sent.
*/
- public String getUser() {
+ public Jid getUser() {
return user;
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PEPListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PEPListener.java
index 794321edc..b53811847 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PEPListener.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PEPListener.java
@@ -18,6 +18,7 @@
package org.jivesoftware.smackx.pep;
import org.jivesoftware.smackx.pep.packet.PEPEvent;
+import org.jxmpp.jid.Jid;
/**
@@ -34,6 +35,6 @@ public interface PEPListener {
* @param from the user that sent the entries.
* @param event the event contained in the message.
*/
- public void eventReceived(String from, PEPEvent event);
+ public void eventReceived(Jid from, PEPEvent event);
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PEPManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PEPManager.java
index 0be4e1b51..c6b1b9d71 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PEPManager.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pep/PEPManager.java
@@ -31,6 +31,7 @@ import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smackx.pep.packet.PEPEvent;
import org.jivesoftware.smackx.pep.packet.PEPItem;
import org.jivesoftware.smackx.pep.packet.PEPPubSub;
+import org.jxmpp.jid.Jid;
/**
*
@@ -122,7 +123,7 @@ public class PEPManager {
/**
* Fires roster exchange listeners.
*/
- private void firePEPListeners(String from, PEPEvent event) {
+ private void firePEPListeners(Jid from, PEPEvent event) {
PEPListener[] listeners = null;
synchronized (pepListeners) {
listeners = new PEPListener[pepListeners.size()];
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java
index a8c572827..608ab4775 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java
@@ -45,6 +45,7 @@ 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;
+import org.jxmpp.jid.Jid;
/**
* Implements the XMPP Ping as defined by XEP-0199. The XMPP Ping protocol allows one entity to
@@ -147,7 +148,7 @@ public class PingManager extends Manager {
* to this, is a server ping, which will always return true if the server is reachable,
* event if there is an error on the ping itself (i.e. ping not supported).
*
- * Use {@link #isPingSupported(String)} to determine if XMPP Ping is supported
+ * Use {@link #isPingSupported(Jid)} to determine if XMPP Ping is supported
* by the entity.
*
* @param jid The id of the entity the ping is being sent to
@@ -157,7 +158,7 @@ public class PingManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public boolean ping(String jid, long pingTimeout) throws NotConnectedException, NoResponseException, InterruptedException {
+ public boolean ping(Jid jid, long pingTimeout) throws NotConnectedException, NoResponseException, InterruptedException {
final XMPPConnection connection = connection();
// Packet collector for IQs needs an connection that was at least authenticated once,
// otherwise the client JID will be null causing an NPE
@@ -175,7 +176,7 @@ public class PingManager extends Manager {
}
/**
- * Same as calling {@link #ping(String, long)} with the defaultpacket reply
+ * Same as calling {@link #ping(Jid, long)} with the defaultpacket reply
* timeout.
*
* @param jid The id of the entity the ping is being sent to
@@ -184,7 +185,7 @@ public class PingManager extends Manager {
* @throws NoResponseException if there was no response from the jid.
* @throws InterruptedException
*/
- public boolean ping(String jid) throws NotConnectedException, NoResponseException, InterruptedException {
+ public boolean ping(Jid jid) throws NotConnectedException, NoResponseException, InterruptedException {
return ping(jid, connection().getPacketReplyTimeout());
}
@@ -198,7 +199,7 @@ public class PingManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public boolean isPingSupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public boolean isPingSupported(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, Ping.NAMESPACE);
}
@@ -206,8 +207,8 @@ public class PingManager extends Manager {
* Pings the server. This method will return true if the server is reachable. It
* is the equivalent of calling ping
with the XMPP domain.
*
- * Unlike the {@link #ping(String)} case, this method will return true even if
- * {@link #isPingSupported(String)} is false.
+ * Unlike the {@link #ping(Jid)} case, this method will return true even if
+ * {@link #isPingSupported(Jid)} is false.
*
* @return true if a reply was received from the server, false otherwise.
* @throws NotConnectedException
@@ -221,8 +222,8 @@ public class PingManager extends Manager {
* Pings the server. This method will return true if the server is reachable. It
* is the equivalent of calling ping
with the XMPP domain.
*
- * Unlike the {@link #ping(String)} case, this method will return true even if
- * {@link #isPingSupported(String)} is false.
+ * Unlike the {@link #ping(Jid)} case, this method will return true even if
+ * {@link #isPingSupported(Jid)} is false.
*
* @param notifyListeners Notify the PingFailedListener in case of error if true
* @return true if the user's server could be pinged.
@@ -237,8 +238,8 @@ public class PingManager extends Manager {
* Pings the server. This method will return true if the server is reachable. It
* is the equivalent of calling ping
with the XMPP domain.
*
- * Unlike the {@link #ping(String)} case, this method will return true even if
- * {@link #isPingSupported(String)} is false.
+ * Unlike the {@link #ping(Jid)} case, this method will return true even if
+ * {@link #isPingSupported(Jid)} is false.
*
* @param notifyListeners Notify the PingFailedListener in case of error if true
* @param pingTimeout The time to wait for a reply in milliseconds
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/packet/Ping.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/packet/Ping.java
index e36137f70..7025bbc85 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/packet/Ping.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/packet/Ping.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright 2012 Florian Schmaus
+ * Copyright 2012-2015 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package org.jivesoftware.smackx.ping.packet;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.SimpleIQ;
+import org.jxmpp.jid.Jid;
public class Ping extends SimpleIQ {
@@ -28,7 +29,7 @@ public class Ping extends SimpleIQ {
super(ELEMENT, NAMESPACE);
}
- public Ping(String to) {
+ public Ping(Jid to) {
this();
setTo(to);
setType(IQ.Type.get);
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/packet/PrivacyItem.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/packet/PrivacyItem.java
index 02d138f93..93a38dee8 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/packet/PrivacyItem.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/packet/PrivacyItem.java
@@ -106,6 +106,24 @@ public class PrivacyItem {
this.order = order;
}
+ /**
+ * Creates a new privacy item.
+ *
+ * If the type is "jid", then the 'value' attribute MUST contain a valid Jabber ID.
+ * If the type is "group", then the 'value' attribute SHOULD contain the name of a group
+ * in the user's roster.
+ * If the type is "subscription", then the 'value' attribute MUST be one of "both", "to",
+ * "from", or "none".
+ *
+ * @param type the type.
+ * @param value the value of the privacy item
+ * @param allow true if this is an allow item
+ * @param order the order of this privacy item
+ */
+ public PrivacyItem(Type type, CharSequence value, boolean allow, long order) {
+ this(type, value != null ? value.toString() : null, allow, order);
+ }
+
/**
* Returns the action associated with the item, it MUST be filled and will allow or deny
* the communication.
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java
index 239fb84f6..ee393efd7 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java
@@ -43,12 +43,13 @@ import org.jivesoftware.smackx.pubsub.util.NodeUtils;
import org.jivesoftware.smackx.shim.packet.Header;
import org.jivesoftware.smackx.shim.packet.HeadersExtension;
import org.jivesoftware.smackx.xdata.Form;
+import org.jxmpp.jid.Jid;
abstract public class Node
{
protected XMPPConnection con;
protected String id;
- protected String to;
+ protected Jid to;
protected ConcurrentHashMap, PacketListener> itemEventToListenerMap = new ConcurrentHashMap, PacketListener>();
protected ConcurrentHashMap itemDeleteToListenerMap = new ConcurrentHashMap();
@@ -73,7 +74,7 @@ abstract public class Node
*
* For example, OpenFire requires the server to be prefixed by pubsub
*/
- void setTo(String toAddress)
+ void setTo(Jid toAddress)
{
to = toAddress;
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java
index 9ba220a69..0f5064c2c 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java
@@ -38,6 +38,10 @@ import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
import org.jivesoftware.smackx.pubsub.util.NodeUtils;
import org.jivesoftware.smackx.xdata.Form;
import org.jivesoftware.smackx.xdata.FormField;
+import org.jxmpp.jid.DomainBareJid;
+import org.jxmpp.jid.Jid;
+import org.jxmpp.jid.impl.JidCreate;
+import org.jxmpp.stringprep.XmppStringprepException;
/**
* This is the starting point for access to the pubsub service. It
@@ -51,7 +55,7 @@ import org.jivesoftware.smackx.xdata.FormField;
final public class PubSubManager
{
private XMPPConnection con;
- private String to;
+ private DomainBareJid to;
private Map nodeMap = new ConcurrentHashMap();
/**
@@ -59,11 +63,12 @@ final public class PubSubManager
* name to pubsub
*
* @param connection The XMPP connection
+ * @throws XmppStringprepException
*/
- public PubSubManager(XMPPConnection connection)
+ public PubSubManager(XMPPConnection connection) throws XmppStringprepException
{
con = connection;
- to = "pubsub." + connection.getServiceName();
+ to = JidCreate.domainBareFrom("pubsub." + connection.getServiceName());
}
/**
@@ -73,7 +78,7 @@ final public class PubSubManager
* @param connection The XMPP connection
* @param toAddress The pubsub specific to address (required for some servers)
*/
- public PubSubManager(XMPPConnection connection, String toAddress)
+ public PubSubManager(XMPPConnection connection, DomainBareJid toAddress)
{
con = connection;
to = toAddress;
@@ -314,7 +319,7 @@ final public class PubSubManager
return sendPubsubPacket(con, to, type, Collections.singletonList(ext), ns);
}
- static PubSub sendPubsubPacket(XMPPConnection con, String to, Type type, List extList, PubSubNamespace ns) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
+ static PubSub sendPubsubPacket(XMPPConnection con, Jid to, Type type, List extList, PubSubNamespace ns) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub pubSub = new PubSub(to, type, ns);
for (PacketExtension pe : extList) {
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSub.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSub.java
index ed979cc82..0636abc95 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSub.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSub.java
@@ -19,6 +19,7 @@ package org.jivesoftware.smackx.pubsub.packet;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.pubsub.PubSubElementType;
+import org.jxmpp.jid.Jid;
/**
* The standard PubSub extension of an {@link IQ} packet. This is the topmost
@@ -40,7 +41,7 @@ public class PubSub extends IQ
super(ELEMENT, ns.getXmlns());
}
- public PubSub(String to, Type type, PubSubNamespace ns) {
+ public PubSub(Jid to, Type type, PubSubNamespace ns) {
super(ELEMENT, (ns == null ? PubSubNamespace.BASIC : ns).getXmlns());
setTo(to);
setType(type);
@@ -86,7 +87,7 @@ public class PubSub extends IQ
return xml;
}
- public static PubSub createPubsubPacket(String to, Type type, PacketExtension extension, PubSubNamespace ns) {
+ public static PubSub createPubsubPacket(Jid to, Type type, PacketExtension extension, PubSubNamespace ns) {
PubSub pubSub = new PubSub(to, type, ns);
pubSub.addExtension(extension);
return pubSub;
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java
index bed43508c..9f51ae2a6 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java
@@ -38,6 +38,7 @@ import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.roster.Roster;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
+import org.jxmpp.jid.Jid;
/**
* Manager for XEP-0184: Message Delivery Receipts. This class implements
@@ -142,7 +143,7 @@ public class DeliveryReceiptManager extends Manager {
connection.addAsyncPacketListener(new PacketListener() {
@Override
public void processPacket(Stanza packet) throws NotConnectedException, InterruptedException {
- final String from = packet.getFrom();
+ final Jid from = packet.getFrom();
final XMPPConnection connection = connection();
switch (autoReceiptMode) {
case disabled:
@@ -190,7 +191,7 @@ public class DeliveryReceiptManager extends Manager {
* @throws XMPPException
* @throws InterruptedException
*/
- public boolean isSupported(String jid) throws SmackException, XMPPException, InterruptedException {
+ public boolean isSupported(Jid jid) throws SmackException, XMPPException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid,
DeliveryReceipt.NAMESPACE);
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/ReceiptReceivedListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/ReceiptReceivedListener.java
index 774820ea7..5f6c849cb 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/ReceiptReceivedListener.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/ReceiptReceivedListener.java
@@ -17,6 +17,7 @@
package org.jivesoftware.smackx.receipts;
import org.jivesoftware.smack.packet.Stanza;
+import org.jxmpp.jid.Jid;
/**
* Interface for received receipt notifications.
@@ -36,5 +37,5 @@ public interface ReceiptReceivedListener {
* @param receiptId the message ID of the packet which has been received and this receipt is for
* @param receipt the receipt
*/
- void onReceiptReceived(String fromJid, String toJid, String receiptId, Stanza receipt);
+ void onReceiptReceived(Jid fromJid, Jid toJid, String receiptId, Stanza receipt);
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java
index f0aa55664..936c10590 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearch.java
@@ -30,6 +30,7 @@ import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.xdata.Form;
import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.packet.DataForm;
+import org.jxmpp.jid.DomainBareJid;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -66,7 +67,7 @@ public class UserSearch extends SimpleIQ {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public Form getSearchForm(XMPPConnection con, String searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public Form getSearchForm(XMPPConnection con, DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
UserSearch search = new UserSearch();
search.setType(IQ.Type.get);
search.setTo(searchService);
@@ -87,7 +88,7 @@ public class UserSearch extends SimpleIQ {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public ReportedData sendSearchForm(XMPPConnection con, Form searchForm, String searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public ReportedData sendSearchForm(XMPPConnection con, Form searchForm, DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
UserSearch search = new UserSearch();
search.setType(IQ.Type.set);
search.setTo(searchService);
@@ -109,7 +110,7 @@ public class UserSearch extends SimpleIQ {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public ReportedData sendSimpleSearchForm(XMPPConnection con, Form searchForm, String searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public ReportedData sendSimpleSearchForm(XMPPConnection con, Form searchForm, DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
SimpleUserSearch search = new SimpleUserSearch();
search.setForm(searchForm);
search.setType(IQ.Type.set);
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearchManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearchManager.java
index 3d2944fb8..b9b2bff8d 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearchManager.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/search/UserSearchManager.java
@@ -22,6 +22,7 @@ import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.xdata.Form;
+import org.jxmpp.jid.DomainBareJid;
import java.util.List;
@@ -68,7 +69,7 @@ public class UserSearchManager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public Form getSearchForm(String searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public Form getSearchForm(DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return userSearch.getSearchForm(con, searchService);
}
@@ -84,7 +85,7 @@ public class UserSearchManager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public ReportedData getSearchResults(Form searchForm, String searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public ReportedData getSearchResults(Form searchForm, DomainBareJid searchService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return userSearch.sendSearchForm(con, searchForm, searchService);
}
@@ -98,7 +99,7 @@ public class UserSearchManager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public List getSearchServices() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public List getSearchServices() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(con);
return discoManager.findServices(UserSearch.NAMESPACE, false, false);
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/time/EntityTimeManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/time/EntityTimeManager.java
index 03ee6e078..ad96e2742 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/time/EntityTimeManager.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/time/EntityTimeManager.java
@@ -34,6 +34,7 @@ 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;
+import org.jxmpp.jid.Jid;
public class EntityTimeManager extends Manager {
@@ -99,11 +100,11 @@ public class EntityTimeManager extends Manager {
enabled = false;
}
- public boolean isTimeSupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public boolean isTimeSupported(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, Time.NAMESPACE);
}
- public Time getTime(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public Time getTime(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
if (!isTimeSupported(jid))
return null;
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/VCardManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/VCardManager.java
index 23f99e33e..34c5ecbd6 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/VCardManager.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/VCardManager.java
@@ -29,6 +29,8 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.vcardtemp.packet.VCard;
+import org.jxmpp.jid.BareJid;
+import org.jxmpp.jid.Jid;
public class VCardManager extends Manager {
public static final String NAMESPACE = VCard.NAMESPACE;
@@ -71,10 +73,10 @@ public class VCardManager extends Manager {
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
- * @deprecated use {@link #isSupported(String)} instead.
+ * @deprecated use {@link #isSupported(Jid)} instead.
*/
@Deprecated
- public static boolean isSupported(String jid, XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public static boolean isSupported(Jid jid, XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return VCardManager.getInstanceFor(connection).isSupported(jid);
}
@@ -117,7 +119,7 @@ public class VCardManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public VCard loadVCard(String bareJid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public VCard loadVCard(BareJid bareJid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
VCard vcardRequest = new VCard();
vcardRequest.setTo(bareJid);
VCard result = connection().createPacketCollectorAndSend(vcardRequest).nextResultOrThrow();
@@ -134,7 +136,7 @@ public class VCardManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public boolean isSupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public boolean isSupported(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, NAMESPACE);
}
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java
index 08db8e932..1bc712450 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java
@@ -40,6 +40,7 @@ import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.stringencoder.Base64;
import org.jivesoftware.smackx.vcardtemp.VCardManager;
+import org.jxmpp.jid.BareJid;
/**
* A VCard class for use with the
@@ -551,10 +552,10 @@ public class VCard extends IQ {
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
- * @deprecated use {@link VCardManager#loadVCard(String)} instead.
+ * @deprecated use {@link VCardManager#loadVCard(BareJid)} instead.
*/
@Deprecated
- public void load(XMPPConnection connection, String user) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public void load(XMPPConnection connection, BareJid user) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
VCard result = VCardManager.getInstanceFor(connection).loadVCard(user);
copyFieldsFrom(result);
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/XDataManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/XDataManager.java
index 194b12a2d..ebd948d99 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/XDataManager.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/XDataManager.java
@@ -28,6 +28,7 @@ import org.jivesoftware.smack.XMPPConnectionRegistry;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.xdata.packet.DataForm;
+import org.jxmpp.jid.Jid;
public class XDataManager extends Manager {
@@ -80,7 +81,7 @@ public class XDataManager extends Manager {
* @see XEP-0004: Data Forms § 6. Service Discovery
* @since 4.1
*/
- public boolean isSupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public boolean isSupported(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, NAMESPACE);
}
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/XHTMLManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/XHTMLManager.java
index f0ac83b0c..10c96c936 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/XHTMLManager.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/XHTMLManager.java
@@ -26,6 +26,7 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.xhtmlim.packet.XHTMLExtension;
+import org.jxmpp.jid.Jid;
import java.util.List;
@@ -130,7 +131,7 @@ public class XHTMLManager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public static boolean isServiceEnabled(XMPPConnection connection, String userID)
+ public static boolean isServiceEnabled(XMPPConnection connection, Jid userID)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(connection).supportsFeature(userID, XHTMLExtension.NAMESPACE);
}
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/CloseListenerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/CloseListenerTest.java
index 0430124bf..22c2d5a00 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/CloseListenerTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/CloseListenerTest.java
@@ -25,6 +25,8 @@ import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Close;
import org.junit.Test;
+import org.jxmpp.jid.Jid;
+import org.jxmpp.jid.JidTestUtil;
import org.mockito.ArgumentCaptor;
import org.powermock.reflect.Whitebox;
@@ -35,8 +37,8 @@ import org.powermock.reflect.Whitebox;
*/
public class CloseListenerTest {
- String initiatorJID = "initiator@xmpp-server/Smack";
- String targetJID = "target@xmpp-server/Smack";
+ static final Jid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
+ static final Jid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
/**
* If a close request to an unknown session is received it should be replied
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/DataListenerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/DataListenerTest.java
index 29da9edd2..79f8fa6a7 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/DataListenerTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/DataListenerTest.java
@@ -26,6 +26,8 @@ import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Data;
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension;
import org.junit.Test;
+import org.jxmpp.jid.Jid;
+import org.jxmpp.jid.JidTestUtil;
import org.mockito.ArgumentCaptor;
import org.powermock.reflect.Whitebox;
@@ -36,8 +38,8 @@ import org.powermock.reflect.Whitebox;
*/
public class DataListenerTest {
- String initiatorJID = "initiator@xmpp-server/Smack";
- String targetJID = "target@xmpp-server/Smack";
+ static final Jid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
+ static final Jid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
/**
* If a data packet of an unknown session is received it should be replied
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/IBBPacketUtils.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/IBBPacketUtils.java
index 92dadc2d8..0618cdde1 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/IBBPacketUtils.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/IBBPacketUtils.java
@@ -20,6 +20,7 @@ import org.jivesoftware.smack.packet.EmptyResultIQ;
import org.jivesoftware.smack.packet.ErrorIQ;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.XMPPError;
+import org.jxmpp.jid.Jid;
/**
* Utility methods to create packets.
@@ -36,7 +37,7 @@ public class IBBPacketUtils {
* @param xmppError the XMPP error
* @return an error IQ
*/
- public static IQ createErrorIQ(String from, String to, XMPPError xmppError) {
+ public static IQ createErrorIQ(Jid from, Jid to, XMPPError xmppError) {
IQ errorIQ = new ErrorIQ(xmppError);
errorIQ.setType(IQ.Type.error);
errorIQ.setFrom(from);
@@ -51,7 +52,7 @@ public class IBBPacketUtils {
* @param to the recipients JID
* @return a result IQ
*/
- public static IQ createResultIQ(String from, String to) {
+ public static IQ createResultIQ(Jid from, Jid to) {
IQ result = new EmptyResultIQ();
result.setType(IQ.Type.result);
result.setFrom(from);
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManagerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManagerTest.java
index 902e82b19..f37cd3304 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManagerTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManagerTest.java
@@ -35,6 +35,9 @@ import org.jivesoftware.util.Protocol;
import org.jivesoftware.util.Verification;
import org.junit.Before;
import org.junit.Test;
+import org.jxmpp.jid.DomainBareJid;
+import org.jxmpp.jid.FullJid;
+import org.jxmpp.jid.JidTestUtil;
/**
* Test for InBandBytestreamManager.
@@ -44,9 +47,9 @@ import org.junit.Test;
public class InBandBytestreamManagerTest {
// settings
- String initiatorJID = "initiator@xmpp-server/Smack";
- String targetJID = "target@xmpp-server/Smack";
- String xmppServer = "xmpp-server";
+ static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
+ static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
+ static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
String sessionID = "session_id";
// protocol verifier
@@ -99,7 +102,7 @@ public class InBandBytestreamManagerTest {
}
/**
- * Invoking {@link InBandBytestreamManager#establishSession(String)} should
+ * Invoking {@link InBandBytestreamManager#establishSession(org.jxmpp.jid.Jid)} should
* throw an exception if the given target does not support in-band
* bytestream.
* @throws SmackException
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamRequestTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamRequestTest.java
index b04ed0cf3..dae6c52cd 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamRequestTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamRequestTest.java
@@ -28,6 +28,8 @@ import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
import org.junit.Before;
import org.junit.Test;
+import org.jxmpp.jid.Jid;
+import org.jxmpp.jid.JidTestUtil;
import org.mockito.ArgumentCaptor;
/**
@@ -37,8 +39,8 @@ import org.mockito.ArgumentCaptor;
*/
public class InBandBytestreamRequestTest {
- String initiatorJID = "initiator@xmpp-server/Smack";
- String targetJID = "target@xmpp-server/Smack";
+ static final Jid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
+ static final Jid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
String sessionID = "session_id";
XMPPConnection connection;
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java
index 347a5087a..5179fece0 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java
@@ -40,6 +40,9 @@ import org.jivesoftware.util.Protocol;
import org.jivesoftware.util.Verification;
import org.junit.Before;
import org.junit.Test;
+import org.jxmpp.jid.DomainBareJid;
+import org.jxmpp.jid.FullJid;
+import org.jxmpp.jid.JidTestUtil;
import org.powermock.reflect.Whitebox;
/**
@@ -52,9 +55,9 @@ import org.powermock.reflect.Whitebox;
public class InBandBytestreamSessionMessageTest {
// settings
- String initiatorJID = "initiator@xmpp-server/Smack";
- String targetJID = "target@xmpp-server/Smack";
- String xmppServer = "xmpp-server";
+ static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
+ static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
+ static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
String sessionID = "session_id";
int blockSize = 10;
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java
index 2b066b3f4..f1aa83966 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java
@@ -40,6 +40,9 @@ import org.jivesoftware.util.Protocol;
import org.jivesoftware.util.Verification;
import org.junit.Before;
import org.junit.Test;
+import org.jxmpp.jid.DomainBareJid;
+import org.jxmpp.jid.FullJid;
+import org.jxmpp.jid.JidTestUtil;
import org.powermock.reflect.Whitebox;
/**
@@ -53,9 +56,9 @@ import org.powermock.reflect.Whitebox;
public class InBandBytestreamSessionTest {
// settings
- String initiatorJID = "initiator@xmpp-server/Smack";
- String targetJID = "target@xmpp-server/Smack";
- String xmppServer = "xmpp-server";
+ static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
+ static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
+ static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
String sessionID = "session_id";
int blockSize = 10;
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InitiationListenerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InitiationListenerTest.java
index 5f57d089b..f6290689e 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InitiationListenerTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/InitiationListenerTest.java
@@ -28,6 +28,9 @@ import org.jivesoftware.smackx.bytestreams.BytestreamRequest;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
import org.junit.Before;
import org.junit.Test;
+import org.jxmpp.jid.FullJid;
+import org.jxmpp.jid.JidTestUtil;
+import org.jxmpp.jid.impl.JidCreate;
import org.mockito.ArgumentCaptor;
import org.powermock.reflect.Whitebox;
@@ -38,8 +41,8 @@ import org.powermock.reflect.Whitebox;
*/
public class InitiationListenerTest {
- String initiatorJID = "initiator@xmpp-server/Smack";
- String targetJID = "target@xmpp-server/Smack";
+ static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
+ static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
String sessionID = "session_id";
XMPPConnection connection;
@@ -190,7 +193,7 @@ public class InitiationListenerTest {
// add listener for request of user "other_initiator"
InBandBytestreamListener listener = mock(InBandBytestreamListener.class);
- byteStreamManager.addIncomingBytestreamListener(listener, "other_" + initiatorJID);
+ byteStreamManager.addIncomingBytestreamListener(listener, JidCreate.from("other_" + initiatorJID));
// run the listener with the initiation packet
initiationListener.handleIQRequest(initBytestream);
@@ -261,8 +264,8 @@ public class InitiationListenerTest {
// add listener for request of user "other_initiator"
InBandBytestreamListener userRequestsListener = mock(InBandBytestreamListener.class);
- byteStreamManager.addIncomingBytestreamListener(userRequestsListener, "other_"
- + initiatorJID);
+ byteStreamManager.addIncomingBytestreamListener(userRequestsListener, JidCreate.from("other_"
+ + initiatorJID));
// run the listener with the initiation packet
initiationListener.handleIQRequest(initBytestream);
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/CloseTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/CloseTest.java
index 2e02b216c..0103d250f 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/CloseTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/CloseTest.java
@@ -17,13 +17,13 @@
package org.jivesoftware.smackx.bytestreams.ibb.packet;
import static org.junit.Assert.assertEquals;
-
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import java.util.Properties;
import org.jivesoftware.smack.packet.IQ;
import org.junit.Test;
+import org.jxmpp.jid.impl.JidCreate;
import com.jamesmurty.utils.XMLBuilder;
@@ -74,8 +74,8 @@ public class CloseTest {
.asString(outputProperties);
Close close = new Close("i781hf64");
- close.setFrom("romeo@montague.lit/orchard");
- close.setTo("juliet@capulet.lit/balcony");
+ close.setFrom(JidCreate.from("romeo@montague.lit/orchard"));
+ close.setTo(JidCreate.from("juliet@capulet.lit/balcony"));
close.setStanzaId("us71g45j");
assertXMLEqual(control, close.toXML().toString());
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/DataTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/DataTest.java
index 96b7d9452..c8c2a9371 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/DataTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/DataTest.java
@@ -25,6 +25,7 @@ import java.util.Properties;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.stringencoder.Base64;
import org.junit.Test;
+import org.jxmpp.jid.impl.JidCreate;
import com.jamesmurty.utils.XMLBuilder;
@@ -70,8 +71,8 @@ public class DataTest {
DataPacketExtension dpe = new DataPacketExtension("i781hf64", 0, encodedData);
Data data = new Data(dpe);
- data.setFrom("romeo@montague.lit/orchard");
- data.setTo("juliet@capulet.lit/balcony");
+ data.setFrom(JidCreate.from("romeo@montague.lit/orchard"));
+ data.setTo(JidCreate.from("juliet@capulet.lit/balcony"));
data.setStanzaId("kr91n475");
assertXMLEqual(control, data.toXML().toString());
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/OpenTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/OpenTest.java
index 469d7a732..459e1fd2a 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/OpenTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/ibb/packet/OpenTest.java
@@ -24,6 +24,7 @@ import java.util.Properties;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaType;
import org.junit.Test;
+import org.jxmpp.jid.impl.JidCreate;
import com.jamesmurty.utils.XMLBuilder;
@@ -95,8 +96,8 @@ public class OpenTest {
.asString(outputProperties);
Open open = new Open("i781hf64", 4096, StanzaType.IQ);
- open.setFrom("romeo@montague.lit/orchard");
- open.setTo("juliet@capulet.lit/balcony");
+ open.setFrom(JidCreate.from("romeo@montague.lit/orchard"));
+ open.setTo(JidCreate.from("juliet@capulet.lit/balcony"));
open.setStanzaId("jn3h8g65");
assertXMLEqual(control, open.toXML().toString());
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/InitiationListenerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/InitiationListenerTest.java
index 9475fe287..f6172f6b2 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/InitiationListenerTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/InitiationListenerTest.java
@@ -29,6 +29,10 @@ import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.junit.Before;
import org.junit.Test;
+import org.jxmpp.jid.DomainBareJid;
+import org.jxmpp.jid.FullJid;
+import org.jxmpp.jid.JidTestUtil;
+import org.jxmpp.jid.impl.JidCreate;
import org.mockito.ArgumentCaptor;
import org.powermock.reflect.Whitebox;
@@ -39,10 +43,10 @@ import org.powermock.reflect.Whitebox;
*/
public class InitiationListenerTest {
- String initiatorJID = "initiator@xmpp-server/Smack";
- String targetJID = "target@xmpp-server/Smack";
- String xmppServer = "xmpp-server";
- String proxyJID = "proxy.xmpp-server";
+ static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
+ static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
+ static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
+ static final DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG;
String proxyAddress = "127.0.0.1";
String sessionID = "session_id";
@@ -169,7 +173,7 @@ public class InitiationListenerTest {
// add listener for request of user "other_initiator"
Socks5BytestreamListener listener = mock(Socks5BytestreamListener.class);
- byteStreamManager.addIncomingBytestreamListener(listener, "other_" + initiatorJID);
+ byteStreamManager.addIncomingBytestreamListener(listener, JidCreate.from("other_" + initiatorJID));
// run the listener with the initiation packet
initiationListener.handleIQRequest(initBytestream);
@@ -240,8 +244,8 @@ public class InitiationListenerTest {
// add listener for request of user "other_initiator"
Socks5BytestreamListener userRequestsListener = mock(Socks5BytestreamListener.class);
- byteStreamManager.addIncomingBytestreamListener(userRequestsListener, "other_"
- + initiatorJID);
+ byteStreamManager.addIncomingBytestreamListener(userRequestsListener, JidCreate.from("other_"
+ + initiatorJID));
// run the listener with the initiation packet
initiationListener.handleIQRequest(initBytestream);
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java
index dc32b8587..ecad7c6b6 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java
@@ -50,6 +50,11 @@ import org.jivesoftware.util.Verification;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.jxmpp.jid.DomainBareJid;
+import org.jxmpp.jid.FullJid;
+import org.jxmpp.jid.JidTestUtil;
+import org.jxmpp.jid.impl.JidCreate;
+import org.jxmpp.stringprep.XmppStringprepException;
/**
* Test for Socks5BytestreamManager.
@@ -59,10 +64,10 @@ import org.junit.Test;
public class Socks5ByteStreamManagerTest {
// settings
- String initiatorJID = "initiator@xmpp-server/Smack";
- String targetJID = "target@xmpp-server/Smack";
- String xmppServer = "xmpp-server";
- String proxyJID = "proxy.xmpp-server";
+ static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
+ static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
+ static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
+ static final DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG;
String proxyAddress = "127.0.0.1";
String sessionID = "session_id";
@@ -137,7 +142,7 @@ public class Socks5ByteStreamManagerTest {
}
/**
- * Invoking {@link Socks5BytestreamManager#establishSession(String)} should throw an exception
+ * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid)} should throw an exception
* if the given target does not support SOCKS5 Bytestream.
* @throws XMPPException
*/
@@ -165,7 +170,7 @@ public class Socks5ByteStreamManagerTest {
}
/**
- * Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if XMPP
+ * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if XMPP
* server doesn't return any proxies.
*/
@Test
@@ -216,7 +221,7 @@ public class Socks5ByteStreamManagerTest {
}
/**
- * Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if no
+ * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if no
* proxy is a SOCKS5 proxy.
*/
@Test
@@ -254,7 +259,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info for proxy containing information about NOT being a Socks5
// proxy
DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
- Identity identity = new Identity("noproxy", proxyJID, "bytestreams");
+ Identity identity = new Identity("noproxy", proxyJID.toString(), "bytestreams");
proxyInfo.addIdentity(identity);
// return the proxy identity if proxy is queried
@@ -279,7 +284,7 @@ public class Socks5ByteStreamManagerTest {
}
/**
- * Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if no
+ * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if no
* SOCKS5 proxy can be found. If it turns out that a proxy is not a SOCKS5 proxy it should not
* be queried again.
*/
@@ -318,7 +323,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info for proxy containing information about NOT being a Socks5
// proxy
DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
- Identity identity = new Identity("noproxy", proxyJID, "bytestreams");
+ Identity identity = new Identity("noproxy", proxyJID.toString(), "bytestreams");
proxyInfo.addIdentity(identity);
// return the proxy identity if proxy is queried
@@ -370,7 +375,7 @@ public class Socks5ByteStreamManagerTest {
}
/**
- * Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if the
+ * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if the
* target does not accept a SOCKS5 Bytestream. See XEP-0065 Section 5.2 A2
*/
@@ -408,7 +413,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info for proxy containing information about being a SOCKS5 proxy
DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
- Identity identity = new Identity("proxy", proxyJID, "bytestreams");
+ Identity identity = new Identity("proxy", proxyJID.toString(), "bytestreams");
proxyInfo.addIdentity(identity);
// return the socks5 bytestream proxy identity if proxy is queried
@@ -454,11 +459,12 @@ public class Socks5ByteStreamManagerTest {
}
/**
- * Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if the
+ * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if the
* proxy used by target is invalid.
+ * @throws XmppStringprepException
*/
@Test
- public void shouldFailIfTargetUsesInvalidSocks5Proxy() {
+ public void shouldFailIfTargetUsesInvalidSocks5Proxy() throws XmppStringprepException {
// disable clients local SOCKS5 proxy
Socks5Proxy.setLocalSocks5ProxyEnabled(false);
@@ -491,7 +497,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info for proxy containing information about being a SOCKS5 proxy
DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
- Identity identity = new Identity("proxy", proxyJID, "bytestreams");
+ Identity identity = new Identity("proxy", proxyJID.toString(), "bytestreams");
proxyInfo.addIdentity(identity);
// return the socks5 bytestream proxy identity if proxy is queried
@@ -512,7 +518,7 @@ public class Socks5ByteStreamManagerTest {
Bytestream streamHostUsedPacket = Socks5PacketUtils.createBytestreamResponse(targetJID,
initiatorJID);
streamHostUsedPacket.setSessionID(sessionID);
- streamHostUsedPacket.setUsedHost("invalid.proxy");
+ streamHostUsedPacket.setUsedHost(JidCreate.from("invalid.proxy"));
// return used stream host info as response to the bytestream initiation
protocol.addResponse(streamHostUsedPacket, Verification.correspondingSenderReceiver,
@@ -536,7 +542,7 @@ public class Socks5ByteStreamManagerTest {
}
/**
- * Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should fail if
+ * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if
* initiator can not connect to the SOCKS5 proxy used by target.
*/
@Test
@@ -573,7 +579,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info for proxy containing information about being a SOCKS5 proxy
DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
- Identity identity = new Identity("proxy", proxyJID, "bytestreams");
+ Identity identity = new Identity("proxy", proxyJID.toString(), "bytestreams");
proxyInfo.addIdentity(identity);
// return the socks5 bytestream proxy identity if proxy is queried
@@ -628,7 +634,7 @@ public class Socks5ByteStreamManagerTest {
}
/**
- * Invoking {@link Socks5BytestreamManager#establishSession(String, String)} should successfully
+ * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should successfully
* negotiate and return a SOCKS5 Bytestream connection.
*
* @throws Exception should not happen
@@ -667,7 +673,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info for proxy containing information about being a SOCKS5 proxy
DiscoverInfo proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
- Identity identity = new Identity("proxy", proxyJID, "bytestreams");
+ Identity identity = new Identity("proxy", proxyJID.toString(), "bytestreams");
proxyInfo.addIdentity(identity);
// return the socks5 bytestream proxy identity if proxy is queried
@@ -838,7 +844,7 @@ public class Socks5ByteStreamManagerTest {
}
/**
- * Invoking {@link Socks5BytestreamManager#establishSession(String, String)} the first time
+ * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} the first time
* should successfully negotiate a SOCKS5 Bytestream via the second SOCKS5 proxy and should
* prioritize this proxy for a second SOCKS5 Bytestream negotiation.
*
@@ -921,7 +927,7 @@ public class Socks5ByteStreamManagerTest {
}
/**
- * Invoking {@link Socks5BytestreamManager#establishSession(String, String)} the first time
+ * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} the first time
* should successfully negotiate a SOCKS5 Bytestream via the second SOCKS5 proxy. The second
* negotiation should run in the same manner if prioritization is disabled.
*
@@ -995,7 +1001,7 @@ public class Socks5ByteStreamManagerTest {
}
- private void createResponses(Verification streamHostUsedVerification) {
+ private void createResponses(Verification streamHostUsedVerification) throws XmppStringprepException {
// build discover info that supports the SOCKS5 feature
DiscoverInfo discoverInfo = Socks5PacketUtils.createDiscoverInfo(targetJID, initiatorJID);
discoverInfo.addFeature(Bytestream.NAMESPACE);
@@ -1007,7 +1013,7 @@ public class Socks5ByteStreamManagerTest {
// build discover items containing a proxy item
DiscoverItems discoverItems = Socks5PacketUtils.createDiscoverItems(xmppServer,
initiatorJID);
- discoverItems.addItem(new Item("proxy2.xmpp-server"));
+ discoverItems.addItem(new Item(JidCreate.from("proxy2.xmpp-server")));
discoverItems.addItem(new Item(proxyJID));
// return the proxy item if XMPP server is queried
@@ -1018,7 +1024,7 @@ public class Socks5ByteStreamManagerTest {
* build discover info for proxy "proxy2.xmpp-server" containing information about being a
* SOCKS5 proxy
*/
- DiscoverInfo proxyInfo1 = Socks5PacketUtils.createDiscoverInfo("proxy2.xmpp-server",
+ DiscoverInfo proxyInfo1 = Socks5PacketUtils.createDiscoverInfo(JidCreate.from("proxy2.xmpp-server"),
initiatorJID);
Identity identity1 = new Identity("proxy", "proxy2.xmpp-server", "bytestreams");
proxyInfo1.addIdentity(identity1);
@@ -1029,7 +1035,7 @@ public class Socks5ByteStreamManagerTest {
// build discover info for proxy containing information about being a SOCKS5 proxy
DiscoverInfo proxyInfo2 = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
- Identity identity2 = new Identity("proxy", proxyJID, "bytestreams");
+ Identity identity2 = new Identity("proxy", proxyJID.toString(), "bytestreams");
proxyInfo2.addIdentity(identity2);
// return the SOCKS5 bytestream proxy identity if proxy is queried
@@ -1041,8 +1047,8 @@ public class Socks5ByteStreamManagerTest {
* port of the proxy
*/
Bytestream streamHostInfo1 = Socks5PacketUtils.createBytestreamResponse(
- "proxy2.xmpp-server", initiatorJID);
- streamHostInfo1.addStreamHost("proxy2.xmpp-server", proxyAddress, 7778);
+ JidCreate.from("proxy2.xmpp-server"), initiatorJID);
+ streamHostInfo1.addStreamHost(JidCreate.from("proxy2.xmpp-server"), proxyAddress, 7778);
// return stream host info if it is queried
protocol.addResponse(streamHostInfo1, Verification.correspondingSenderReceiver,
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamRequestTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamRequestTest.java
index 266f229f3..16dcb57fd 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamRequestTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamRequestTest.java
@@ -40,6 +40,10 @@ import org.jivesoftware.util.Protocol;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.jxmpp.jid.DomainBareJid;
+import org.jxmpp.jid.FullJid;
+import org.jxmpp.jid.JidTestUtil;
+import org.jxmpp.jid.impl.JidCreate;
/**
* Tests for the Socks5BytestreamRequest class.
@@ -49,10 +53,10 @@ import org.junit.Test;
public class Socks5ByteStreamRequestTest {
// settings
- String initiatorJID = "initiator@xmpp-server/Smack";
- String targetJID = "target@xmpp-server/Smack";
- String xmppServer = "xmpp-server";
- String proxyJID = "proxy.xmpp-server";
+ static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
+ static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
+ static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
+ static final DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG;
String proxyAddress = "127.0.0.1";
String sessionID = "session_id";
@@ -174,7 +178,7 @@ public class Socks5ByteStreamRequestTest {
// build SOCKS5 Bytestream initialization request
Bytestream bytestreamInitialization = Socks5PacketUtils.createBytestreamInitiation(
initiatorJID, targetJID, sessionID);
- bytestreamInitialization.addStreamHost("invalid." + proxyJID, "127.0.0.2", 7778);
+ bytestreamInitialization.addStreamHost(JidCreate.from("invalid." + proxyJID), "127.0.0.2", 7778);
// get SOCKS5 Bytestream manager for connection
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
@@ -266,7 +270,7 @@ public class Socks5ByteStreamRequestTest {
// build SOCKS5 Bytestream initialization request
Bytestream bytestreamInitialization = Socks5PacketUtils.createBytestreamInitiation(
initiatorJID, targetJID, sessionID);
- bytestreamInitialization.addStreamHost("invalid." + proxyJID, "127.0.0.2", 7778);
+ bytestreamInitialization.addStreamHost(JidCreate.from("invalid." + proxyJID), "127.0.0.2", 7778);
// get SOCKS5 Bytestream manager for connection
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiatorTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiatorTest.java
index 1a19e6d18..79ec5976b 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiatorTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiatorTest.java
@@ -42,6 +42,9 @@ import org.jivesoftware.util.Verification;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.jxmpp.jid.DomainBareJid;
+import org.jxmpp.jid.FullJid;
+import org.jxmpp.jid.JidTestUtil;
/**
* Test for Socks5ClientForInitiator class.
@@ -51,10 +54,10 @@ import org.junit.Test;
public class Socks5ClientForInitiatorTest {
// settings
- String initiatorJID = "initiator@xmpp-server/Smack";
- String targetJID = "target@xmpp-server/Smack";
- String xmppServer = "xmpp-server";
- String proxyJID = "proxy.xmpp-server";
+ static final FullJid initiatorJID = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
+ static final FullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
+ static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
+ static final DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG;
String proxyAddress = "127.0.0.1";
int proxyPort = 7890;
String sessionID = "session_id";
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientTest.java
index 34800a10c..8e74614be 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientTest.java
@@ -32,6 +32,8 @@ import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.jxmpp.jid.DomainBareJid;
+import org.jxmpp.jid.JidTestUtil;
/**
* Test for Socks5Client class.
@@ -43,7 +45,7 @@ public class Socks5ClientTest {
// settings
private String serverAddress = "127.0.0.1";
private int serverPort = 7890;
- private String proxyJID = "proxy.xmpp-server";
+ private DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG;
private String digest = "digest";
private ServerSocket serverSocket;
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5PacketUtils.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5PacketUtils.java
index fac8cab5d..b16c6cf20 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5PacketUtils.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5PacketUtils.java
@@ -21,6 +21,7 @@ import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
+import org.jxmpp.jid.Jid;
/**
* A collection of utility methods to create XMPP packets.
@@ -38,7 +39,7 @@ public class Socks5PacketUtils {
* @param sessionID the session ID
* @return SOCKS5 Bytestream initialization request packet
*/
- public static Bytestream createBytestreamInitiation(String from, String to, String sessionID) {
+ public static Bytestream createBytestreamInitiation(Jid from, Jid to, String sessionID) {
Bytestream bytestream = new Bytestream();
bytestream.setFrom(from);
bytestream.setTo(to);
@@ -55,7 +56,7 @@ public class Socks5PacketUtils {
* @param to the initiator
* @return response to a SOCKS5 Bytestream initialization request
*/
- public static Bytestream createBytestreamResponse(String from, String to) {
+ public static Bytestream createBytestreamResponse(Jid from, Jid to) {
Bytestream streamHostInfo = new Bytestream();
streamHostInfo.setFrom(from);
streamHostInfo.setTo(to);
@@ -70,7 +71,7 @@ public class Socks5PacketUtils {
* @param to the XMPP client
* @return response to an item discovery request
*/
- public static DiscoverItems createDiscoverItems(String from, String to) {
+ public static DiscoverItems createDiscoverItems(Jid from, Jid to) {
DiscoverItems discoverItems = new DiscoverItems();
discoverItems.setFrom(from);
discoverItems.setTo(to);
@@ -85,7 +86,7 @@ public class Socks5PacketUtils {
* @param to the initiator
* @return response to an info discovery request
*/
- public static DiscoverInfo createDiscoverInfo(String from, String to) {
+ public static DiscoverInfo createDiscoverInfo(Jid from, Jid to) {
DiscoverInfo discoverInfo = new DiscoverInfo();
discoverInfo.setFrom(from);
discoverInfo.setTo(to);
@@ -100,7 +101,7 @@ public class Socks5PacketUtils {
* @param to JID of the client who wants to activate the SOCKS5 Bytestream
* @return response IQ for a activation request to the proxy
*/
- public static IQ createActivationConfirmation(String from, String to) {
+ public static IQ createActivationConfirmation(Jid from, Jid to) {
IQ response = new EmptyResultIQ();
response.setFrom(from);
response.setTo(to);
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/caps/EntityCapsManagerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/caps/EntityCapsManagerTest.java
index 0ce256dc1..b60956da6 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/caps/EntityCapsManagerTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/caps/EntityCapsManagerTest.java
@@ -38,6 +38,8 @@ import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.junit.Before;
import org.junit.Test;
+import org.jxmpp.jid.impl.JidCreate;
+import org.jxmpp.stringprep.XmppStringprepException;
public class EntityCapsManagerTest extends InitExtensions {
@@ -50,9 +52,10 @@ public class EntityCapsManagerTest extends InitExtensions {
/**
* XEP-
* 0115 Complex Generation Example
+ * @throws XmppStringprepException
*/
@Test
- public void testComplexGenerationExample() {
+ public void testComplexGenerationExample() throws XmppStringprepException {
DiscoverInfo di = createComplexSamplePacket();
CapsVersionAndHash versionAndHash = EntityCapsManager.generateVerificationString(di, StringUtils.SHA1);
@@ -66,13 +69,13 @@ public class EntityCapsManagerTest extends InitExtensions {
}
@Test
- public void testVerificationDuplicateFeatures() {
+ public void testVerificationDuplicateFeatures() throws XmppStringprepException {
DiscoverInfo di = createMalformedDiscoverInfo();
assertTrue(di.containsDuplicateFeatures());
}
@Test
- public void testVerificationDuplicateIdentities() {
+ public void testVerificationDuplicateIdentities() throws XmppStringprepException {
DiscoverInfo di = createMalformedDiscoverInfo();
assertTrue(di.containsDuplicateIdentities());
}
@@ -97,11 +100,11 @@ public class EntityCapsManagerTest extends InitExtensions {
assertEquals(di.toXML().toString(), restored_di.toXML().toString());
}
- private static DiscoverInfo createComplexSamplePacket() {
+ private static DiscoverInfo createComplexSamplePacket() throws XmppStringprepException {
DiscoverInfo di = new DiscoverInfo();
- di.setFrom("benvolio@capulet.lit/230193");
+ di.setFrom(JidCreate.from("benvolio@capulet.lit/230193"));
di.setStanzaId("disco1");
- di.setTo("juliet@capulet.lit/chamber");
+ di.setTo(JidCreate.from("juliet@capulet.lit/chamber"));
di.setType(IQ.Type.result);
Collection identities = new LinkedList();
@@ -148,11 +151,11 @@ public class EntityCapsManagerTest extends InitExtensions {
return di;
}
- private static DiscoverInfo createMalformedDiscoverInfo() {
+ private static DiscoverInfo createMalformedDiscoverInfo() throws XmppStringprepException {
DiscoverInfo di = new DiscoverInfo();
- di.setFrom("benvolio@capulet.lit/230193");
+ di.setFrom(JidCreate.from("benvolio@capulet.lit/230193"));
di.setStanzaId("disco1");
- di.setTo(")juliet@capulet.lit/chamber");
+ di.setTo(JidCreate.from(")juliet@capulet.lit/chamber"));
di.setType(IQ.Type.result);
Collection identities = new LinkedList();
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiatorTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiatorTest.java
index e7d9f46c0..d8a49487f 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiatorTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiatorTest.java
@@ -25,6 +25,7 @@ import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.jxmpp.jid.JidTestUtil;
public class FileTransferNegotiatorTest {
private DummyConnection connection;
@@ -50,7 +51,7 @@ public class FileTransferNegotiatorTest {
public void verifyForm() throws Exception {
FileTransferNegotiator fileNeg = FileTransferNegotiator.getInstanceFor(connection);
try {
- fileNeg.negotiateOutgoingTransfer("me", "streamid", "file", 1024, null, 10);
+ fileNeg.negotiateOutgoingTransfer(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, "streamid", "file", 1024, null, 10);
} catch (NoResponseException e) {
// Ignore
}
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/forward/ForwardedTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/forward/ForwardedTest.java
index 30ea25fa3..70e05054d 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/forward/ForwardedTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/forward/ForwardedTest.java
@@ -16,8 +16,10 @@
*/
package org.jivesoftware.smackx.forward;
+import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
import java.util.Properties;
@@ -56,7 +58,7 @@ public class ForwardedTest {
assertEquals(null, fwd.getDelayInformation());
// check message
- assertEquals("romeo@montague.com", fwd.getForwardedPacket().getFrom());
+ assertThat("romeo@montague.com", equalsCharSequence(fwd.getForwardedPacket().getFrom()));
// check end of tag
assertEquals(XmlPullParser.END_TAG, parser.getEventType());
@@ -84,7 +86,7 @@ public class ForwardedTest {
assertNotNull(delay);
// check message
- assertEquals("romeo@montague.com", fwd.getForwardedPacket().getFrom());
+ assertThat("romeo@montague.com", equalsCharSequence(fwd.getForwardedPacket().getFrom()));
// check end of tag
assertEquals(XmlPullParser.END_TAG, parser.getEventType());
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/iqversion/VersionTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/iqversion/VersionTest.java
index d8bb596e4..2855994ee 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/iqversion/VersionTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/iqversion/VersionTest.java
@@ -16,7 +16,9 @@
*/
package org.jivesoftware.smackx.iqversion;
+import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import org.jivesoftware.smack.DummyConnection;
@@ -52,7 +54,7 @@ public class VersionTest {
Version reply = (Version) replyPacket;
//getFrom check is pending for SMACK-547
//assertEquals("juliet@capulet.lit/balcony", reply.getFrom());
- assertEquals("capulet.lit", reply.getTo());
+ assertThat("capulet.lit", equalsCharSequence(reply.getTo()));
assertEquals("s2c1", reply.getStanzaId());
assertEquals(IQ.Type.result, reply.getType());
assertEquals("Test", reply.getName());
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java
index 3ebab7b09..887d3fa85 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java
@@ -16,10 +16,13 @@
*/
package org.jivesoftware.smackx.ping;
+import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.jxmpp.jid.JidTestUtil.DUMMY_AT_EXAMPLE_ORG;
import java.io.IOException;
@@ -66,7 +69,7 @@ public class PingTest extends InitExtensions {
assertTrue(pongPacket instanceof IQ);
IQ pong = (IQ) pongPacket;
- assertEquals("capulet.lit", pong.getTo());
+ assertThat("capulet.lit", equalsCharSequence(pong.getTo()));
assertEquals("s2c1", pong.getStanzaId());
assertEquals(IQ.Type.result, pong.getType());
}
@@ -76,7 +79,7 @@ public class PingTest extends InitExtensions {
DummyConnection dummyCon = getAuthentiactedDummyConnection();
PingManager pinger = PingManager.getInstanceFor(dummyCon);
try {
- pinger.ping("test@myserver.com");
+ pinger.ping(DUMMY_AT_EXAMPLE_ORG);
}
catch (SmackException e) {
// Ignore the fact the server won't answer for this unit test.
@@ -92,7 +95,7 @@ public class PingTest extends InitExtensions {
PingManager pinger = PingManager.getInstanceFor(threadedCon);
- boolean pingSuccess = pinger.ping("test@myserver.com");
+ boolean pingSuccess = pinger.ping(DUMMY_AT_EXAMPLE_ORG);
assertTrue(pingSuccess);
@@ -111,7 +114,7 @@ public class PingTest extends InitExtensions {
PingManager pinger = PingManager.getInstanceFor(dummyCon);
try {
- pinger.ping("test@myserver.com");
+ pinger.ping(DUMMY_AT_EXAMPLE_ORG);
}
catch (NoResponseException e) {
return;
@@ -140,7 +143,7 @@ public class PingTest extends InitExtensions {
PingManager pinger = PingManager.getInstanceFor(threadedCon);
- boolean pingSuccess = pinger.ping("test@myserver.com");
+ boolean pingSuccess = pinger.ping(DUMMY_AT_EXAMPLE_ORG);
assertFalse(pingSuccess);
}
@@ -207,7 +210,7 @@ public class PingTest extends InitExtensions {
con.addIQReply(discoReply);
PingManager pinger = PingManager.getInstanceFor(con);
- boolean pingSupported = pinger.isPingSupported("test@myserver.com");
+ boolean pingSupported = pinger.isPingSupported(DUMMY_AT_EXAMPLE_ORG);
assertTrue(pingSupported);
}
@@ -229,7 +232,7 @@ public class PingTest extends InitExtensions {
con.addIQReply(discoReply);
PingManager pinger = PingManager.getInstanceFor(con);
- boolean pingSupported = pinger.isPingSupported("test@myserver.com");
+ boolean pingSupported = pinger.isPingSupported(DUMMY_AT_EXAMPLE_ORG);
assertFalse(pingSupported);
}
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java
index 48b382c8a..0bf1158fa 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java
@@ -33,6 +33,7 @@ import org.jivesoftware.smackx.pubsub.packet.PubSub;
import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.junit.Assert;
import org.junit.Test;
+import org.jxmpp.stringprep.XmppStringprepException;
/**
*
@@ -77,7 +78,7 @@ public class ConfigureFormTest
}
@Test (expected=SmackException.class)
- public void getConfigFormWithTimeout() throws XMPPException, SmackException, InterruptedException
+ public void getConfigFormWithTimeout() throws XMPPException, SmackException, InterruptedException, XmppStringprepException
{
ThreadedDummyConnection con = new ThreadedDummyConnection();
PubSubManager mgr = new PubSubManager(con);
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java
index 7f30b9d5d..7a6ef7a06 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java
@@ -19,7 +19,9 @@ package org.jivesoftware.smackx.receipts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
+import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence;
import java.util.Properties;
@@ -31,6 +33,8 @@ import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smackx.InitExtensions;
import org.jivesoftware.smackx.receipts.DeliveryReceiptManager.AutoReceiptMode;
import org.junit.Test;
+import org.jxmpp.jid.Jid;
+import org.jxmpp.jid.impl.JidCreate;
import org.xmlpull.v1.XmlPullParser;
import com.jamesmurty.utils.XMLBuilder;
@@ -62,7 +66,7 @@ public class DeliveryReceiptTest extends InitExtensions {
assertTrue(DeliveryReceiptManager.hasDeliveryReceiptRequest(p));
- Message m = new Message("romeo@montague.com", Message.Type.normal);
+ Message m = new Message(JidCreate.from("romeo@montague.com"), Message.Type.normal);
assertFalse(DeliveryReceiptManager.hasDeliveryReceiptRequest(m));
DeliveryReceiptRequest.addTo(m);
assertTrue(DeliveryReceiptManager.hasDeliveryReceiptRequest(m));
@@ -77,8 +81,8 @@ public class DeliveryReceiptTest extends InitExtensions {
TestReceiptReceivedListener rrl = new TestReceiptReceivedListener();
drm.addReceiptReceivedListener(rrl);
- Message m = new Message("romeo@montague.com", Message.Type.normal);
- m.setFrom("julia@capulet.com");
+ Message m = new Message(JidCreate.from("romeo@montague.com"), Message.Type.normal);
+ m.setFrom(JidCreate.from("julia@capulet.com"));
m.setStanzaId("reply-id");
m.addExtension(new DeliveryReceipt("original-test-id"));
c.processPacket(m);
@@ -88,9 +92,9 @@ public class DeliveryReceiptTest extends InitExtensions {
private static class TestReceiptReceivedListener extends WaitForPacketListener implements ReceiptReceivedListener {
@Override
- public void onReceiptReceived(String fromJid, String toJid, String receiptId, Stanza receipt) {
- assertEquals("julia@capulet.com", fromJid);
- assertEquals("romeo@montague.com", toJid);
+ public void onReceiptReceived(Jid fromJid, Jid toJid, String receiptId, Stanza receipt) {
+ assertThat("julia@capulet.com", equalsCharSequence(fromJid));
+ assertThat("romeo@montague.com", equalsCharSequence(toJid));
assertEquals("original-test-id", receiptId);
reportInvoked();
}
@@ -106,8 +110,8 @@ public class DeliveryReceiptTest extends InitExtensions {
assertEquals(AutoReceiptMode.always, drm.getAutoReceiptMode());
// test auto-receipts
- Message m = new Message("julia@capulet.com", Message.Type.normal);
- m.setFrom("romeo@montague.com");
+ Message m = new Message(JidCreate.from("julia@capulet.com"), Message.Type.normal);
+ m.setFrom(JidCreate.from("romeo@montague.com"));
m.setStanzaId("test-receipt-request");
DeliveryReceiptRequest.addTo(m);
@@ -116,7 +120,7 @@ public class DeliveryReceiptTest extends InitExtensions {
Stanza reply = c.getSentPacket();
DeliveryReceipt r = DeliveryReceipt.from(reply);
- assertEquals("romeo@montague.com", reply.getTo());
+ assertThat("romeo@montague.com", equalsCharSequence(reply.getTo()));
assertEquals("test-receipt-request", r.getId());
}
}
diff --git a/smack-extensions/src/test/java/org/jivesoftware/util/ConnectionUtils.java b/smack-extensions/src/test/java/org/jivesoftware/util/ConnectionUtils.java
index e6a6e4869..a43ed7c8b 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/util/ConnectionUtils.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/util/ConnectionUtils.java
@@ -32,6 +32,8 @@ import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
+import org.jxmpp.jid.DomainBareJid;
+import org.jxmpp.jid.FullJid;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -67,7 +69,7 @@ public class ConnectionUtils {
* @throws InterruptedException
*/
public static XMPPConnection createMockedConnection(final Protocol protocol,
- String initiatorJID, String xmppServer) throws SmackException, XMPPErrorException, InterruptedException {
+ FullJid initiatorJID, DomainBareJid xmppServer) throws SmackException, XMPPErrorException, InterruptedException {
// mock XMPP connection
XMPPConnection connection = mock(XMPPConnection.class);
diff --git a/smack-im/src/main/java/org/jivesoftware/smack/chat/Chat.java b/smack-im/src/main/java/org/jivesoftware/smack/chat/Chat.java
index 64a9b875c..db80a2dc4 100644
--- a/smack-im/src/main/java/org/jivesoftware/smack/chat/Chat.java
+++ b/smack-im/src/main/java/org/jivesoftware/smack/chat/Chat.java
@@ -21,6 +21,7 @@ import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.util.StringUtils;
+import org.jxmpp.jid.JidWithLocalpart;
import java.util.Set;
import java.util.Collections;
@@ -40,7 +41,7 @@ public class Chat {
private ChatManager chatManager;
private String threadID;
- private String participant;
+ private JidWithLocalpart participant;
private final Set listeners = new CopyOnWriteArraySet();
/**
@@ -50,7 +51,7 @@ public class Chat {
* @param participant the user to chat with.
* @param threadID the thread ID to use.
*/
- Chat(ChatManager chatManager, String participant, String threadID) {
+ Chat(ChatManager chatManager, JidWithLocalpart participant, String threadID) {
if (StringUtils.isEmpty(threadID)) {
throw new IllegalArgumentException("Thread ID must not be null");
}
@@ -75,7 +76,7 @@ public class Chat {
*
* @return the name of the user the chat is occuring with.
*/
- public String getParticipant() {
+ public JidWithLocalpart getParticipant() {
return participant;
}
diff --git a/smack-im/src/main/java/org/jivesoftware/smack/chat/ChatManager.java b/smack-im/src/main/java/org/jivesoftware/smack/chat/ChatManager.java
index 0685f5669..6e2daead8 100644
--- a/smack-im/src/main/java/org/jivesoftware/smack/chat/ChatManager.java
+++ b/smack-im/src/main/java/org/jivesoftware/smack/chat/ChatManager.java
@@ -24,6 +24,7 @@ import java.util.UUID;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.logging.Logger;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.MessageListener;
@@ -41,7 +42,9 @@ import org.jivesoftware.smack.filter.ThreadFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Message.Type;
import org.jivesoftware.smack.packet.Stanza;
-import org.jxmpp.util.XmppStringUtils;
+import org.jxmpp.jid.BareJid;
+import org.jxmpp.jid.Jid;
+import org.jxmpp.jid.JidWithLocalpart;
/**
* The chat manager keeps track of references to all current chats. It will not hold any references
@@ -51,6 +54,9 @@ import org.jxmpp.util.XmppStringUtils;
* @author Alexander Wenckus
*/
public class ChatManager extends Manager{
+
+ private static final Logger LOGGER = Logger.getLogger(ChatManager.class.getName());
+
private static final Map INSTANCES = new WeakHashMap();
/**
@@ -124,12 +130,12 @@ public class ChatManager extends Manager{
/**
* Maps jids to chats
*/
- private Map jidChats = new ConcurrentHashMap<>();
+ private Map jidChats = new ConcurrentHashMap<>();
/**
* Maps base jids to chats
*/
- private Map baseJidChats = new ConcurrentHashMap<>();
+ private Map baseJidChats = new ConcurrentHashMap<>();
private Set chatManagerListeners
= new CopyOnWriteArraySet();
@@ -209,7 +215,7 @@ public class ChatManager extends Manager{
* @param userJID the user this chat is with.
* @return the created chat.
*/
- public Chat createChat(String userJID) {
+ public Chat createChat(JidWithLocalpart userJID) {
return createChat(userJID, null);
}
@@ -220,7 +226,7 @@ public class ChatManager extends Manager{
* @param listener the optional listener which will listen for new messages from this chat.
* @return the created chat.
*/
- public Chat createChat(String userJID, ChatMessageListener listener) {
+ public Chat createChat(JidWithLocalpart userJID, ChatMessageListener listener) {
return createChat(userJID, null, listener);
}
@@ -232,7 +238,7 @@ public class ChatManager extends Manager{
* @param listener the optional listener to add to the chat
* @return the created chat.
*/
- public Chat createChat(String userJID, String thread, ChatMessageListener listener) {
+ public Chat createChat(JidWithLocalpart userJID, String thread, ChatMessageListener listener) {
if (thread == null) {
thread = nextID();
}
@@ -245,11 +251,11 @@ public class ChatManager extends Manager{
return chat;
}
- private Chat createChat(String userJID, String threadID, boolean createdLocally) {
+ private Chat createChat(JidWithLocalpart userJID, String threadID, boolean createdLocally) {
Chat chat = new Chat(this, userJID, threadID);
threadChats.put(threadID, chat);
jidChats.put(userJID, chat);
- baseJidChats.put(XmppStringUtils.parseBareJid(userJID), chat);
+ baseJidChats.put(userJID.asBareJid(), chat);
for(ChatManagerListener listener : chatManagerListeners) {
listener.chatCreated(chat, createdLocally);
@@ -260,9 +266,9 @@ public class ChatManager extends Manager{
void closeChat(Chat chat) {
threadChats.remove(chat.getThreadID());
- String userJID = chat.getParticipant();
+ JidWithLocalpart userJID = chat.getParticipant();
jidChats.remove(userJID);
- baseJidChats.remove(XmppStringUtils.parseBareJid(userJID));
+ baseJidChats.remove(userJID.withoutResource());
}
/**
@@ -273,10 +279,16 @@ public class ChatManager extends Manager{
* @return a Chat or null if none can be created
*/
private Chat createChat(Message message) {
- String userJID = message.getFrom();
+ Jid from = message.getFrom();
// According to RFC6120 8.1.2.1 4. messages without a 'from' attribute are valid, but they
// are of no use in this case for ChatManager
+ if (from == null) {
+ return null;
+ }
+
+ JidWithLocalpart userJID = from.asJidWithLocalpartIfPossible();
if (userJID == null) {
+ LOGGER.warning("Message from JID without localpart: '" +message.toXML() + "'");
return null;
}
String threadID = message.getThread();
@@ -296,7 +308,7 @@ public class ChatManager extends Manager{
* @param userJID jid in the from field of message.
* @return Matching chat, or null if no match found.
*/
- private Chat getUserChat(String userJID) {
+ private Chat getUserChat(Jid userJID) {
if (matchMode == MatchMode.NONE) {
return null;
}
@@ -308,7 +320,7 @@ public class ChatManager extends Manager{
Chat match = jidChats.get(userJID);
if (match == null && (matchMode == MatchMode.BARE_JID)) {
- match = baseJidChats.get(XmppStringUtils.parseBareJid(userJID));
+ match = baseJidChats.get(userJID.asBareJidIfPossible());
}
return match;
}
diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java
index 56e3ea400..13e767f05 100644
--- a/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java
+++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java
@@ -24,7 +24,6 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
-import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
@@ -60,7 +59,11 @@ import org.jivesoftware.smack.roster.packet.RosterVer;
import org.jivesoftware.smack.roster.packet.RosterPacket.Item;
import org.jivesoftware.smack.roster.rosterstore.RosterStore;
import org.jivesoftware.smack.util.Objects;
-import org.jxmpp.util.XmppStringUtils;
+import org.jxmpp.jid.BareJid;
+import org.jxmpp.jid.Jid;
+import org.jxmpp.jid.JidWithResource;
+import org.jxmpp.jid.impl.JidCreate;
+import org.jxmpp.jid.parts.Resourcepart;
/**
* Represents a user's roster, which is the collection of users a person receives
@@ -96,7 +99,7 @@ public class Roster extends Manager {
*
* This method will never return null
, instead if the user has not yet logged into
* the server or is logged in anonymously all modifying methods of the returned roster object
- * like {@link Roster#createEntry(String, String, String[])},
+ * like {@link Roster#createEntry(Jid, String, String[])},
* {@link Roster#removeEntry(RosterEntry)} , etc. except adding or removing
* {@link RosterListener}s will throw an IllegalStateException.
*
@@ -128,11 +131,16 @@ public class Roster extends Manager {
/**
* Concurrent hash map from JID to its roster entry.
*/
- private final Map entries = new ConcurrentHashMap();
+ private final Map entries = new ConcurrentHashMap<>();
private final Set unfiledEntries = new CopyOnWriteArraySet<>();
private final Set rosterListeners = new LinkedHashSet<>();
- private final Map> presenceMap = new ConcurrentHashMap>();
+
+ /**
+ * A map of JIDs to another Map of Resourceparts to Presences. The 'inner' map may contain
+ * {@link Resourcepart#EMPTY} if there are no other Presences available.
+ */
+ private final Map> presenceMap = new ConcurrentHashMap<>();
/**
* Mutually exclude roster listener invocation and changing the {@link entries} map. Also used
@@ -421,7 +429,7 @@ public class Roster extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
- public void createEntry(String user, String name, String[] groups) throws NotLoggedInException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
+ public void createEntry(Jid user, String name, String[] groups) throws NotLoggedInException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
final XMPPConnection connection = connection();
if (!connection.isAuthenticated()) {
throw new NotLoggedInException();
@@ -568,11 +576,11 @@ public class Roster extends Manager {
* in any valid format (e.g. "domain/resource", "user@domain" or "user@domain/resource").
* @return the roster entry or null if it does not exist.
*/
- public RosterEntry getEntry(String user) {
+ public RosterEntry getEntry(Jid user) {
if (user == null) {
return null;
}
- String key = getMapKey(user);
+ Jid key = getMapKey(user);
return entries.get(key);
}
@@ -584,7 +592,7 @@ public class Roster extends Manager {
* "user@domain" or "user@domain/resource").
* @return true if the XMPP address is an entry in the roster.
*/
- public boolean contains(String user) {
+ public boolean contains(Jid user) {
return getEntry(user) != null;
}
@@ -645,9 +653,9 @@ public class Roster extends Manager {
* @return the user's current presence, or unavailable presence if the user is offline
* or if no presence information is available..
*/
- public Presence getPresence(String user) {
- String key = getMapKey(XmppStringUtils.parseBareJid(user));
- Map userPresences = presenceMap.get(key);
+ public Presence getPresence(Jid user) {
+ Jid key = getMapKey(user);
+ Map userPresences = presenceMap.get(key);
if (userPresences == null) {
Presence presence = new Presence(Presence.Type.unavailable);
presence.setFrom(user);
@@ -660,7 +668,7 @@ public class Roster extends Manager {
// This is used in case no available presence is found
Presence unavailable = null;
- for (String resource : userPresences.keySet()) {
+ for (Resourcepart resource : userPresences.keySet()) {
Presence p = userPresences.get(resource);
if (!p.isAvailable()) {
unavailable = p;
@@ -712,10 +720,10 @@ public class Roster extends Manager {
* @return the user's current presence, or unavailable presence if the user is offline
* or if no presence information is available.
*/
- public Presence getPresenceResource(String userWithResource) {
- String key = getMapKey(userWithResource);
- String resource = XmppStringUtils.parseResource(userWithResource);
- Map userPresences = presenceMap.get(key);
+ public Presence getPresenceResource(JidWithResource userWithResource) {
+ Jid key = getMapKey(userWithResource);
+ Resourcepart resource = userWithResource.getResourcepart();
+ Map userPresences = presenceMap.get(key);
if (userPresences == null) {
Presence presence = new Presence(Presence.Type.unavailable);
presence.setFrom(userWithResource);
@@ -742,8 +750,8 @@ public class Roster extends Manager {
* @return a List of Presence objects for all the user's current presences, or an unavailable presence if no
* presence information is available.
*/
- public List getAllPresences(String bareJid) {
- Map userPresences = presenceMap.get(getMapKey(bareJid));
+ public List getAllPresences(Jid bareJid) {
+ Map userPresences = presenceMap.get(getMapKey(bareJid));
List res;
if (userPresences == null) {
// Create an unavailable presence if none was found
@@ -763,7 +771,7 @@ public class Roster extends Manager {
* @param bareJid the bare JID from which the presences should be retrieved.
* @return available presences for the bare JID.
*/
- public List getAvailablePresences(String bareJid) {
+ public List getAvailablePresences(Jid bareJid) {
List allPresences = getAllPresences(bareJid);
List res = new ArrayList<>(allPresences.size());
for (Presence presence : allPresences) {
@@ -785,10 +793,10 @@ public class Roster extends Manager {
* or an unavailable presence if the user is offline or if no presence information
* is available.
*/
- public List getPresences(String user) {
+ public List getPresences(Jid user) {
List res;
- String key = getMapKey(user);
- Map userPresences = presenceMap.get(key);
+ Jid key = getMapKey(user);
+ Map userPresences = presenceMap.get(key);
if (userPresences == null) {
Presence presence = new Presence(Presence.Type.unavailable);
presence.setFrom(user);
@@ -835,7 +843,7 @@ public class Roster extends Manager {
* @return true if the given JID is allowed to see the users presence.
* @since 4.1
*/
- public boolean isSubscribedToMyPresence(String jid) {
+ public boolean isSubscribedToMyPresence(Jid jid) {
if (connection().getServiceName().equals(jid)) {
return true;
}
@@ -892,15 +900,19 @@ public class Roster extends Manager {
* jdoe@example.com/Work.
* @return the key to use in the presenceMap and entries Map for the fully qualified XMPP ID.
*/
- private String getMapKey(String user) {
+ private Jid getMapKey(Jid user) {
if (user == null) {
return null;
}
if (entries.containsKey(user)) {
return user;
}
- String key = XmppStringUtils.parseBareJid(user);
- return key.toLowerCase(Locale.US);
+ BareJid bareJid = user.asBareJidIfPossible();
+ if (bareJid != null) {
+ return bareJid;
+ }
+ // jid validate, log this case?
+ return user;
}
/**
@@ -911,12 +923,17 @@ public class Roster extends Manager {
*/
private void setOfflinePresencesAndResetLoaded() {
Presence packetUnavailable;
- outerloop: for (String user : presenceMap.keySet()) {
- Map resources = presenceMap.get(user);
+ outerloop: for (Jid user : presenceMap.keySet()) {
+ Map resources = presenceMap.get(user);
if (resources != null) {
- for (String resource : resources.keySet()) {
+ for (Resourcepart resource : resources.keySet()) {
packetUnavailable = new Presence(Presence.Type.unavailable);
- packetUnavailable.setFrom(user + "/" + resource);
+ BareJid bareUserJid = user.asBareJidIfPossible();
+ if (bareUserJid == null) {
+ LOGGER.warning("Can not transform user JID to bare JID: '" + user + "'");
+ continue;
+ }
+ packetUnavailable.setFrom(JidCreate.fullFrom(bareUserJid, resource));
try {
presencePacketListener.processPacket(packetUnavailable);
}
@@ -943,8 +960,8 @@ public class Roster extends Manager {
* @param updatedEntries the collection of address of the updated contacts.
* @param deletedEntries the collection of address of the deleted contacts.
*/
- private void fireRosterChangedEvent(final Collection addedEntries, final Collection updatedEntries,
- final Collection deletedEntries) {
+ private void fireRosterChangedEvent(final Collection addedEntries, final Collection updatedEntries,
+ final Collection deletedEntries) {
synchronized (rosterListenersAndEntriesLock) {
for (RosterListener listener : rosterListeners) {
if (!addedEntries.isEmpty()) {
@@ -973,8 +990,8 @@ public class Roster extends Manager {
}
}
- private void addUpdateEntry(Collection addedEntries, Collection updatedEntries,
- Collection unchangedEntries, RosterPacket.Item item, RosterEntry entry) {
+ private void addUpdateEntry(Collection addedEntries, Collection updatedEntries,
+ Collection unchangedEntries, RosterPacket.Item item, RosterEntry entry) {
RosterEntry oldEntry;
synchronized (rosterListenersAndEntriesLock) {
oldEntry = entries.put(item.getUser(), entry);
@@ -1032,11 +1049,11 @@ public class Roster extends Manager {
}
}
- private void deleteEntry(Collection deletedEntries, RosterEntry entry) {
- String user = entry.getUser();
+ private void deleteEntry(Collection deletedEntries, RosterEntry entry) {
+ Jid user = entry.getUser();
entries.remove(user);
unfiledEntries.remove(entry);
- presenceMap.remove(XmppStringUtils.parseBareJid(user));
+ presenceMap.remove(user);
deletedEntries.add(user);
for (Entry e: groups.entrySet()) {
@@ -1131,8 +1148,8 @@ public class Roster extends Manager {
* @param key the presence map key
* @return the user presences
*/
- private Map getUserPresences(String key) {
- Map userPresences = presenceMap.get(key);
+ private Map getUserPresences(Jid key) {
+ Map userPresences = presenceMap.get(key);
if (userPresences == null) {
userPresences = new ConcurrentHashMap<>();
presenceMap.put(key, userPresences);
@@ -1144,9 +1161,13 @@ public class Roster extends Manager {
public void processPacket(Stanza packet) throws NotConnectedException, InterruptedException {
final XMPPConnection connection = connection();
Presence presence = (Presence) packet;
- String from = presence.getFrom();
- String key = getMapKey(from);
- Map userPresences;
+ Jid from = presence.getFrom();
+ Resourcepart fromResource = from.getResourceOrNull();
+ if (fromResource == null) {
+ fromResource = Resourcepart.EMPTY;
+ }
+ Jid key = getMapKey(from);
+ Map userPresences;
Presence response = null;
// If an "available" presence, add it to the presence map. Each presence
@@ -1158,9 +1179,9 @@ public class Roster extends Manager {
userPresences = getUserPresences(key);
// See if an offline presence was being stored in the map. If so, remove
// it since we now have an online presence.
- userPresences.remove("");
+ userPresences.remove(Resourcepart.EMPTY);
// Add the new presence, using the resources as a key.
- userPresences.put(XmppStringUtils.parseResource(from), presence);
+ userPresences.put(fromResource, presence);
// If the user is in the roster, fire an event.
if (entries.containsKey(key)) {
fireRosterPresenceEvent(presence);
@@ -1170,17 +1191,17 @@ public class Roster extends Manager {
case unavailable:
// If no resource, this is likely an offline presence as part of
// a roster presence flood. In that case, we store it.
- if ("".equals(XmppStringUtils.parseResource(from))) {
+ if (from.hasNoResource()) {
// Get the user presence map
userPresences = getUserPresences(key);
- userPresences.put("", presence);
+ userPresences.put(Resourcepart.EMPTY, presence);
}
// Otherwise, this is a normal offline presence.
else if (presenceMap.get(key) != null) {
userPresences = presenceMap.get(key);
// Store the offline presence, as it may include extra information
// such as the user being on vacation.
- userPresences.put(XmppStringUtils.parseResource(from), presence);
+ userPresences.put(fromResource, presence);
}
// If the user is in the roster, fire an event.
if (entries.containsKey(key)) {
@@ -1221,7 +1242,7 @@ public class Roster extends Manager {
// Error presence packets from a bare JID mean we invalidate all existing
// presence info for the user.
case error:
- if (!"".equals(XmppStringUtils.parseResource(from))) {
+ if (!from.isBareJid()) {
break;
}
userPresences = getUserPresences(key);
@@ -1229,7 +1250,7 @@ public class Roster extends Manager {
userPresences.clear();
// Set the new presence using the empty resource as a key.
- userPresences.put("", presence);
+ userPresences.put(Resourcepart.EMPTY, presence);
// If the user is in the roster, fire an event.
if (entries.containsKey(key)) {
fireRosterPresenceEvent(presence);
@@ -1250,10 +1271,10 @@ public class Roster extends Manager {
public void processPacket(Stanza packet) {
final XMPPConnection connection = connection();
LOGGER.fine("RosterResultListener received stanza");
- Collection addedEntries = new ArrayList();
- Collection updatedEntries = new ArrayList();
- Collection deletedEntries = new ArrayList();
- Collection unchangedEntries = new ArrayList();
+ Collection addedEntries = new ArrayList<>();
+ Collection updatedEntries = new ArrayList<>();
+ Collection deletedEntries = new ArrayList<>();
+ Collection unchangedEntries = new ArrayList<>();
if (packet instanceof RosterPacket) {
// Non-empty roster result. This stanza contains all the roster elements.
@@ -1274,14 +1295,14 @@ public class Roster extends Manager {
}
// Delete all entries which where not added or updated
- Set toDelete = new HashSet();
+ Set toDelete = new HashSet<>();
for (RosterEntry entry : entries.values()) {
toDelete.add(entry.getUser());
}
toDelete.removeAll(addedEntries);
toDelete.removeAll(updatedEntries);
toDelete.removeAll(unchangedEntries);
- for (String user : toDelete) {
+ for (Jid user : toDelete) {
deleteEntry(deletedEntries, entries.get(user));
}
@@ -1329,8 +1350,8 @@ public class Roster extends Manager {
// Roster push (RFC 6121, 2.1.6)
// A roster push with a non-empty from not matching our address MUST be ignored
- String jid = XmppStringUtils.parseBareJid(connection.getUser());
- String from = rosterPacket.getFrom();
+ BareJid jid = connection.getUser().asBareJid();
+ Jid from = rosterPacket.getFrom();
if (from != null && !from.equals(jid)) {
LOGGER.warning("Ignoring roster push with a non matching 'from' ourJid='" + jid + "' from='" + from
+ "'");
@@ -1344,10 +1365,10 @@ public class Roster extends Manager {
return IQ.createErrorResponse(iqRequest, new XMPPError(Condition.bad_request));
}
- Collection addedEntries = new ArrayList();
- Collection updatedEntries = new ArrayList();
- Collection deletedEntries = new ArrayList();
- Collection unchangedEntries = new ArrayList();
+ Collection addedEntries = new ArrayList<>();
+ Collection updatedEntries = new ArrayList<>();
+ Collection deletedEntries = new ArrayList<>();
+ Collection unchangedEntries = new ArrayList<>();
// We assured above that the size of items is exaclty 1, therefore we are able to
// safely retrieve this single item here.
diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java
index f87ad50fa..22fafc822 100644
--- a/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java
+++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java
@@ -28,6 +28,7 @@ import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.roster.packet.RosterPacket;
+import org.jxmpp.jid.Jid;
/**
@@ -41,7 +42,7 @@ public class RosterEntry {
/**
* The JID of the entity/user.
*/
- private final String user;
+ private final Jid user;
private String name;
private RosterPacket.ItemType type;
@@ -58,7 +59,7 @@ public class RosterEntry {
* @param status the subscription status (related to subscriptions pending to be approbed).
* @param connection a connection to the XMPP server.
*/
- RosterEntry(String user, String name, RosterPacket.ItemType type,
+ RosterEntry(Jid user, String name, RosterPacket.ItemType type,
RosterPacket.ItemStatus status, Roster roster, XMPPConnection connection) {
this.user = user;
this.name = name;
@@ -73,7 +74,7 @@ public class RosterEntry {
*
* @return the user associated with this entry.
*/
- public String getUser() {
+ public Jid getUser() {
return user;
}
diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterListener.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterListener.java
index 2a00de66a..e3216d7ae 100644
--- a/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterListener.java
+++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterListener.java
@@ -18,6 +18,7 @@
package org.jivesoftware.smack.roster;
import org.jivesoftware.smack.packet.Presence;
+import org.jxmpp.jid.Jid;
import java.util.Collection;
@@ -35,21 +36,21 @@ public interface RosterListener {
*
* @param addresses the XMPP addresses of the contacts that have been added to the roster.
*/
- public void entriesAdded(Collection addresses);
+ public void entriesAdded(Collection addresses);
/**
* Called when a roster entries are updated.
*
* @param addresses the XMPP addresses of the contacts whose entries have been updated.
*/
- public void entriesUpdated(Collection addresses);
+ public void entriesUpdated(Collection addresses);
/**
* Called when a roster entries are removed.
*
* @param addresses the XMPP addresses of the contacts that have been removed from the roster.
*/
- public void entriesDeleted(Collection addresses);
+ public void entriesDeleted(Collection addresses);
/**
* Called when the presence of a roster entry is changed. Care should be taken
@@ -74,7 +75,7 @@ public interface RosterListener {
* presence packets will not cause this method to be called.
*
* @param presence the presence that changed.
- * @see Roster#getPresence(String)
+ * @see Roster#getPresence(Jid)
*/
public void presenceChanged(Presence presence);
}
diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/packet/RosterPacket.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/packet/RosterPacket.java
index 9997cbbed..74e5afa25 100644
--- a/smack-im/src/main/java/org/jivesoftware/smack/roster/packet/RosterPacket.java
+++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/packet/RosterPacket.java
@@ -20,11 +20,11 @@ package org.jivesoftware.smack.roster.packet;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.util.XmlStringBuilder;
+import org.jxmpp.jid.Jid;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.Locale;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
@@ -107,7 +107,7 @@ public class RosterPacket extends IQ {
public static final String GROUP = "group";
- private String user;
+ private final Jid user;
private String name;
private ItemType itemType;
private ItemStatus itemStatus;
@@ -119,8 +119,8 @@ public class RosterPacket extends IQ {
* @param user the user.
* @param name the user's name.
*/
- public Item(String user, String name) {
- this.user = user.toLowerCase(Locale.US);
+ public Item(Jid user, String name) {
+ this.user = user;
this.name = name;
itemType = null;
itemStatus = null;
@@ -132,7 +132,7 @@ public class RosterPacket extends IQ {
*
* @return the user.
*/
- public String getUser() {
+ public Jid getUser() {
return user;
}
diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/provider/RosterPacketProvider.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/provider/RosterPacketProvider.java
index eaddfb504..941817e34 100644
--- a/smack-im/src/main/java/org/jivesoftware/smack/roster/provider/RosterPacketProvider.java
+++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/provider/RosterPacketProvider.java
@@ -21,6 +21,8 @@ import java.io.IOException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.roster.packet.RosterPacket;
+import org.jxmpp.jid.Jid;
+import org.jxmpp.jid.impl.JidCreate;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -44,8 +46,9 @@ public class RosterPacketProvider extends IQProvider {
String startTag = parser.getName();
switch (startTag) {
case "item":
- String jid = parser.getAttributeValue("", "jid");
+ String jidString = parser.getAttributeValue("", "jid");
String name = parser.getAttributeValue("", "name");
+ Jid jid = JidCreate.from(jidString);
// Create packet.
item = new RosterPacket.Item(jid, name);
// Set status.
diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStore.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStore.java
index 5bdde3ea9..279e47b60 100644
--- a/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStore.java
+++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStore.java
@@ -31,6 +31,8 @@ import org.jivesoftware.smack.roster.packet.RosterPacket.Item;
import org.jivesoftware.smack.util.FileUtils;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smack.util.stringencoder.Base32;
+import org.jxmpp.jid.Jid;
+import org.jxmpp.jid.impl.JidCreate;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -131,7 +133,7 @@ public class DirectoryRosterStore implements RosterStore {
}
@Override
- public Item getEntry(String bareJid) {
+ public Item getEntry(Jid bareJid) {
return readEntry(getBareJidFile(bareJid));
}
@@ -158,7 +160,7 @@ public class DirectoryRosterStore implements RosterStore {
}
@Override
- public boolean removeEntry(String bareJid, String version) {
+ public boolean removeEntry(Jid bareJid, String version) {
return getBareJidFile(bareJid).delete() && setRosterVersion(version);
}
@@ -182,7 +184,7 @@ public class DirectoryRosterStore implements RosterStore {
}
String parserName;
- String user = null;
+ Jid user = null;
String name = null;
String type = null;
String status = null;
@@ -199,11 +201,12 @@ public class DirectoryRosterStore implements RosterStore {
parserName = parser.getName();
if (eventType == XmlPullParser.START_TAG) {
if (parserName.equals("item")) {
- user = name = type = status = null;
+ user = null;
+ name = type = status = null;
}
else if (parserName.equals("user")) {
parser.next();
- user = parser.getText();
+ user = JidCreate.from(parser.getText());
}
else if (parserName.equals("name")) {
parser.next();
@@ -297,8 +300,8 @@ public class DirectoryRosterStore implements RosterStore {
}
- private File getBareJidFile(String bareJid) {
- String encodedJid = Base32.encode(bareJid);
+ private File getBareJidFile(Jid bareJid) {
+ String encodedJid = Base32.encode(bareJid.toString());
return new File(fileDir, ENTRY_PREFIX + encodedJid);
}
diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/RosterStore.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/RosterStore.java
index b732da296..f99a7d0e3 100644
--- a/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/RosterStore.java
+++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/RosterStore.java
@@ -19,6 +19,7 @@ package org.jivesoftware.smack.roster.rosterstore;
import java.util.Collection;
import org.jivesoftware.smack.roster.packet.RosterPacket;
+import org.jxmpp.jid.Jid;
/**
* This is an interface for persistent roster store needed to implement
@@ -37,7 +38,7 @@ public interface RosterStore {
* @param bareJid The bare JID of the RosterEntry
* @return The {@link org.jivesoftware.smack.roster.RosterEntry} which belongs to that user
*/
- public RosterPacket.Item getEntry(String bareJid);
+ public RosterPacket.Item getEntry(Jid bareJid);
/**
* This method returns the version number as specified by the "ver" attribute
* of the local store. For a fresh store, this MUST be the empty string.
@@ -64,6 +65,6 @@ public interface RosterStore {
* @param version the new roster version
* @return True if successful
*/
- public boolean removeEntry(String bareJid, String version);
+ public boolean removeEntry(Jid bareJid, String version);
}
diff --git a/smack-im/src/test/java/org/jivesoftware/smack/chat/ChatConnectionTest.java b/smack-im/src/test/java/org/jivesoftware/smack/chat/ChatConnectionTest.java
index 10e139f17..48a5748fb 100644
--- a/smack-im/src/test/java/org/jivesoftware/smack/chat/ChatConnectionTest.java
+++ b/smack-im/src/test/java/org/jivesoftware/smack/chat/ChatConnectionTest.java
@@ -32,6 +32,8 @@ import org.jivesoftware.smack.test.util.WaitForPacketListener;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.jxmpp.jid.Jid;
+import org.jxmpp.jid.JidTestUtil;
public class ChatConnectionTest {
@@ -219,7 +221,7 @@ public class ChatConnectionTest {
*/
@Test
public void chatFoundWhenNoThreadFullJid() {
- Chat outgoing = cm.createChat("you@testserver", null);
+ Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null);
Stanza incomingChat = createChatPacket(null, true);
processServerMessage(incomingChat);
@@ -235,7 +237,7 @@ public class ChatConnectionTest {
*/
@Test
public void chatFoundWhenNoThreadBaseJid() {
- Chat outgoing = cm.createChat("you@testserver", null);
+ Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null);
Stanza incomingChat = createChatPacket(null, false);
processServerMessage(incomingChat);
@@ -251,7 +253,7 @@ public class ChatConnectionTest {
*/
@Test
public void chatFoundWithSameThreadFullJid() {
- Chat outgoing = cm.createChat("you@testserver", null);
+ Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null);
Stanza incomingChat = createChatPacket(outgoing.getThreadID(), true);
processServerMessage(incomingChat);
@@ -267,7 +269,7 @@ public class ChatConnectionTest {
*/
@Test
public void chatFoundWithSameThreadBaseJid() {
- Chat outgoing = cm.createChat("you@testserver", null);
+ Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null);
Stanza incomingChat = createChatPacket(outgoing.getThreadID(), false);
processServerMessage(incomingChat);
@@ -283,7 +285,7 @@ public class ChatConnectionTest {
*/
@Test
public void chatNotFoundWithDiffThreadBaseJid() {
- Chat outgoing = cm.createChat("you@testserver", null);
+ Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null);
Stanza incomingChat = createChatPacket(outgoing.getThreadID() + "ff", false);
processServerMessage(incomingChat);
@@ -299,7 +301,7 @@ public class ChatConnectionTest {
*/
@Test
public void chatNotFoundWithDiffThreadFullJid() {
- Chat outgoing = cm.createChat("you@testserver", null);
+ Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null);
Stanza incomingChat = createChatPacket(outgoing.getThreadID() + "ff", true);
processServerMessage(incomingChat);
@@ -321,9 +323,15 @@ public class ChatConnectionTest {
}
private Message createChatPacket(final String threadId, final boolean isFullJid) {
- Message chatMsg = new Message("me@testserver", Message.Type.chat);
+ Message chatMsg = new Message(JidTestUtil.BARE_JID_1, Message.Type.chat);
chatMsg.setBody("the body message - " + System.currentTimeMillis());
- chatMsg.setFrom("you@testserver" + (isFullJid ? "/resource" : ""));
+ Jid jid;
+ if (isFullJid) {
+ jid = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
+ } else {
+ jid = JidTestUtil.DUMMY_AT_EXAMPLE_ORG;
+ }
+ chatMsg.setFrom(jid);
chatMsg.setThread(threadId);
return chatMsg;
}
diff --git a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterOfflineTest.java b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterOfflineTest.java
index 005c3c837..930c6b919 100644
--- a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterOfflineTest.java
+++ b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterOfflineTest.java
@@ -45,11 +45,6 @@ public class RosterOfflineTest {
assertNotNull(roster);
}
- @Test(expected = SmackException.class)
- public void shouldThrowExceptionOnCreateEntry() throws Exception {
- roster.createEntry("test", "test", null);
- }
-
@Test(expected = SmackException.class)
public void shouldThrowExceptionOnReload() throws Exception {
roster.reload();
diff --git a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java
index cc37c7afe..05f1523ad 100644
--- a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java
+++ b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java
@@ -50,6 +50,9 @@ import org.jivesoftware.smack.util.PacketParserUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.jxmpp.jid.Jid;
+import org.jxmpp.jid.impl.JidCreate;
+import org.jxmpp.stringprep.XmppStringprepException;
import org.xmlpull.v1.XmlPullParser;
/**
@@ -104,18 +107,18 @@ public class RosterTest extends InitSmackIm {
// Verify roster
assertTrue("Roster can't be loaded!", roster.waitUntilLoaded());
- verifyRomeosEntry(roster.getEntry("romeo@example.net"));
- verifyMercutiosEntry(roster.getEntry("mercutio@example.com"));
- verifyBenvoliosEntry(roster.getEntry("benvolio@example.net"));
+ verifyRomeosEntry(roster.getEntry(JidCreate.from("romeo@example.net")));
+ verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com")));
+ verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net")));
assertSame("Wrong number of roster entries.", 3, roster.getEntries().size());
// Verify roster listener
assertTrue("The roster listener wasn't invoked for Romeo.",
- rosterListener.getAddedAddresses().contains("romeo@example.net"));
+ rosterListener.addedAddressesContains("romeo@example.net"));
assertTrue("The roster listener wasn't invoked for Mercutio.",
- rosterListener.getAddedAddresses().contains("mercutio@example.com"));
+ rosterListener.addedAddressesContains("mercutio@example.com"));
assertTrue("The roster listener wasn't invoked for Benvolio.",
- rosterListener.getAddedAddresses().contains("benvolio@example.net"));
+ rosterListener.addedAddressesContains("benvolio@example.net"));
assertSame("RosterListeners implies that a item was deleted!",
0,
rosterListener.getDeletedAddresses().size());
@@ -132,7 +135,7 @@ public class RosterTest extends InitSmackIm {
@Test
public void testAddRosterItem() throws Throwable {
// Constants for the new contact
- final String contactJID = "nurse@example.com";
+ final Jid contactJID = JidCreate.from("nurse@example.com");
final String contactName = "Nurse";
final String[] contactGroup = {"Servants"};
@@ -189,9 +192,9 @@ public class RosterTest extends InitSmackIm {
addedEntry.getGroups().iterator().next().getName());
// Verify the unchanged roster items
- verifyRomeosEntry(roster.getEntry("romeo@example.net"));
- verifyMercutiosEntry(roster.getEntry("mercutio@example.com"));
- verifyBenvoliosEntry(roster.getEntry("benvolio@example.net"));
+ verifyRomeosEntry(roster.getEntry(JidCreate.from("romeo@example.net")));
+ verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com")));
+ verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net")));
assertSame("Wrong number of roster entries.", 4, roster.getEntries().size());
}
@@ -203,7 +206,7 @@ public class RosterTest extends InitSmackIm {
@Test
public void testUpdateRosterItem() throws Throwable {
// Constants for the updated contact
- final String contactJID = "romeo@example.net";
+ final Jid contactJID = JidCreate.from("romeo@example.net");
final String contactName = "Romeo";
final String[] contactGroups = {"Friends", "Lovers"};
@@ -263,8 +266,8 @@ public class RosterTest extends InitSmackIm {
addedEntry.getGroups().size());
// Verify the unchanged roster items
- verifyMercutiosEntry(roster.getEntry("mercutio@example.com"));
- verifyBenvoliosEntry(roster.getEntry("benvolio@example.net"));
+ verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com")));
+ verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net")));
assertSame("Wrong number of roster entries (" + roster.getEntries() + ").",
3,
roster.getEntries().size());
@@ -278,7 +281,7 @@ public class RosterTest extends InitSmackIm {
@Test
public void testDeleteRosterItem() throws Throwable {
// The contact which should be deleted
- final String contactJID = "romeo@example.net";
+ final Jid contactJID = JidCreate.from("romeo@example.net");
// Setup
assertNotNull("Can't get the roster from the provided connection!", roster);
@@ -310,8 +313,8 @@ public class RosterTest extends InitSmackIm {
assertNull("The contact wasn't deleted from the roster!", deletedEntry);
assertTrue("The roster listener wasn't invoked for the deleted contact!",
rosterListener.getDeletedAddresses().contains(contactJID));
- verifyMercutiosEntry(roster.getEntry("mercutio@example.com"));
- verifyBenvoliosEntry(roster.getEntry("benvolio@example.net"));
+ verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com")));
+ verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net")));
assertSame("Wrong number of roster entries (" + roster.getEntries() + ").",
2,
roster.getEntries().size());
@@ -324,7 +327,7 @@ public class RosterTest extends InitSmackIm {
*/
@Test
public void testSimpleRosterPush() throws Throwable {
- final String contactJID = "nurse@example.com";
+ final Jid contactJID = JidCreate.from("nurse@example.com");
assertNotNull("Can't get the roster from the provided connection!", roster);
final StringBuilder sb = new StringBuilder();
sb.append("RFC 6121, Section 2.1.6
*/
@Test
- public void testIgnoreInvalidFrom() {
+ public void testIgnoreInvalidFrom() throws XmppStringprepException {
+ final Jid spammerJid = JidCreate.from("spam@example.com");
RosterPacket packet = new RosterPacket();
packet.setType(Type.set);
packet.setTo(connection.getUser());
- packet.setFrom("mallory@example.com");
- packet.addRosterItem(new Item("spam@example.com", "Cool products!"));
+ packet.setFrom(JidCreate.from("mallory@example.com"));
+ packet.addRosterItem(new Item(spammerJid, "Cool products!"));
final String requestId = packet.getStanzaId();
// Simulate receiving the roster push
@@ -383,7 +388,7 @@ public class RosterTest extends InitSmackIm {
assertEquals(requestId, errorIQ.getStanzaId());
assertEquals(Condition.service_unavailable, errorIQ.getError().getCondition());
- assertNull("Contact was added to roster", Roster.getInstanceFor(connection).getEntry("spam@example.com"));
+ assertNull("Contact was added to roster", Roster.getInstanceFor(connection).getEntry(spammerJid));
}
/**
@@ -395,7 +400,7 @@ public class RosterTest extends InitSmackIm {
@Test(timeout=5000)
public void testAddEmptyGroupEntry() throws Throwable {
// Constants for the new contact
- final String contactJID = "nurse@example.com";
+ final Jid contactJID = JidCreate.from("nurse@example.com");
final String contactName = "Nurse";
final String[] contactGroup = {""};
@@ -447,9 +452,9 @@ public class RosterTest extends InitSmackIm {
addedEntry.getGroups().size());
// Verify the unchanged roster items
- verifyRomeosEntry(roster.getEntry("romeo@example.net"));
- verifyMercutiosEntry(roster.getEntry("mercutio@example.com"));
- verifyBenvoliosEntry(roster.getEntry("benvolio@example.net"));
+ verifyRomeosEntry(roster.getEntry(JidCreate.from("romeo@example.net")));
+ verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com")));
+ verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net")));
assertSame("Wrong number of roster entries.", 4, roster.getEntries().size());
}
@@ -461,7 +466,7 @@ public class RosterTest extends InitSmackIm {
*/
@Test
public void testEmptyGroupRosterPush() throws Throwable {
- final String contactJID = "nurse@example.com";
+ final Jid contactJID = JidCreate.from("nurse@example.com");
assertNotNull("Can't get the roster from the provided connection!", roster);
final StringBuilder sb = new StringBuilder();
sb.append("