diff --git a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java
index 3477e62e5..336e193cc 100644
--- a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java
+++ b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java
@@ -95,11 +95,6 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
private PipedWriter readerPipe;
private Thread readerConsumer;
- /**
- * The BOSH equivalent of the stream ID which is used for DIGEST authentication.
- */
- protected String authID = null;
-
/**
* The session ID for the BOSH session with the connection manager.
*/
@@ -147,7 +142,6 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
client = null;
}
sessionID = null;
- authID = null;
// Initialize BOSH client
BOSHClientConfig.Builder cfgBuilder = BOSHClientConfig.Builder
@@ -206,16 +200,6 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
callConnectionConnectedListener();
}
- public String getConnectionID() {
- if (!connected) {
- return null;
- } else if (authID != null) {
- return authID;
- } else {
- return sessionID;
- }
- }
-
public boolean isSecureConnection() {
// TODO: Implement SSL usage
return false;
@@ -298,7 +282,6 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
@Override
protected void shutdown() {
setWasAuthenticated();
- authID = null;
sessionID = null;
done = true;
authenticated = false;
@@ -525,8 +508,8 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
if (sessionID == null) {
sessionID = body.getAttribute(BodyQName.create(XMPPBOSHConnection.BOSH_URI, "sid"));
}
- if (authID == null) {
- authID = body.getAttribute(BodyQName.create(XMPPBOSHConnection.BOSH_URI, "authid"));
+ if (streamId == null) {
+ streamId = body.getAttribute(BodyQName.create(XMPPBOSHConnection.BOSH_URI, "authid"));
}
final XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java
index f38eae26d..da9a3b4b8 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java
@@ -168,6 +168,11 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
protected boolean connected = false;
+ /**
+ * The stream ID, see RFC 6120 § 4.7.3
+ */
+ protected String streamId;
+
/**
*
*/
@@ -354,9 +359,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
return port;
}
- @Override
- public abstract String getConnectionID();
-
@Override
public abstract boolean isSecureConnection();
@@ -382,10 +384,16 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
* @return a reference to this object, to chain connect()
with login()
.
*/
public synchronized AbstractXMPPConnection connect() throws SmackException, IOException, XMPPException {
+ // Check if not already connected
throwAlreadyConnectedExceptionIfAppropriate();
+
+ // Reset the connection state
saslAuthentication.init();
saslFeatureReceived.init();
lastFeaturesReceived.init();
+ streamId = null;
+
+ // Perform the actual connection to the XMPP service
connectInternal();
return this;
}
@@ -501,6 +509,14 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
return user;
}
+ @Override
+ public String getStreamId() {
+ if (!isConnected()) {
+ return null;
+ }
+ return streamId;
+ }
+
// TODO remove this suppression once "disable legacy session" code has been removed from Smack
@SuppressWarnings("deprecation")
protected void bindResourceAndEstablishSession(String resource) throws XMPPErrorException,
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java
index 783b5a21a..9670cd768 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java
@@ -98,14 +98,14 @@ public interface XMPPConnection {
public String getUser();
/**
- * Returns the connection ID for this connection, which is the value set by the server
- * when opening a XMPP stream. If the server does not set a connection ID, this value
- * will be null. This value will be null if not connected to the server.
+ * Returns the stream ID for this connection, which is the value set by the server
+ * when opening a XMPP stream. This value will be null if not connected to the server.
*
* @return the ID of this connection returned from the XMPP server or null if
* not connected to the server.
+ * @see RFC 6120 § 4.7.3. id
*/
- public String getConnectionID();
+ public String getStreamId();
/**
* Returns true if currently connected to the XMPP server.
diff --git a/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java b/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java
index 78c6ad789..237c7fdef 100644
--- a/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java
+++ b/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java
@@ -48,8 +48,6 @@ public class DummyConnection extends AbstractXMPPConnection {
private boolean reconnect = false;
- private String connectionID;
-
private final BlockingQueue queue = new LinkedBlockingQueue();
public static ConnectionConfiguration.Builder,?> getDummyConfigurationBuilder() {
@@ -77,7 +75,7 @@ public class DummyConnection extends AbstractXMPPConnection {
@Override
protected void connectInternal() {
connected = true;
- connectionID = "dummy-" + new Random(new Date().getTime()).nextInt();
+ streamId = "dummy-" + new Random(new Date().getTime()).nextInt();
if (reconnect) {
notifyReconnection();
@@ -87,24 +85,12 @@ public class DummyConnection extends AbstractXMPPConnection {
@Override
protected void shutdown() {
user = null;
- connectionID = null;
authenticated = false;
callConnectionClosedListener();
reconnect = true;
}
- @Override
- public String getConnectionID() {
- if (!isConnected()) {
- return null;
- }
- if (connectionID == null) {
- connectionID = "dummy-" + new Random(new Date().getTime()).nextInt();
- }
- return connectionID;
- }
-
@Override
public boolean isSecureConnection() {
return false;
diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java
index 851814928..9fdbea101 100644
--- a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java
+++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java
@@ -144,8 +144,6 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
*/
private Socket socket;
- private String connectionID = null;
-
/**
*
*/
@@ -298,14 +296,6 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
serviceName).build());
}
- @Override
- public String getConnectionID() {
- if (!isConnected()) {
- return null;
- }
- return connectionID;
- }
-
@Override
protected void throwNotConnectedExceptionIfAppropriate() throws NotConnectedException {
if (packetWriter == null) {
@@ -893,7 +883,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
if (localpart != null) {
from = XmppStringUtils.completeJidFrom(localpart, to);
}
- String id = getConnectionID();
+ String id = getStreamId();
send(new StreamOpen(to, from, id));
try {
packetReader.parser = PacketParserUtils.newXmppParser(reader);
@@ -956,7 +946,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
case "stream":
// We found an opening stream.
if ("jabber:client".equals(parser.getNamespace(null))) {
- connectionID = parser.getAttributeValue("", "id");
+ streamId = parser.getAttributeValue("", "id");
String reportedServiceName = parser.getAttributeValue("", "from");
assert(reportedServiceName.equals(config.getServiceName()));
}