diff --git a/.travis.yml b/.travis.yml
index a371c394f..5b6c55b30 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,7 +4,6 @@ android:
- android-8
jdk:
- oraclejdk8
- - oraclejdk7
sudo: false
cache:
directories:
diff --git a/build.gradle b/build.gradle
index 5cfd4ad21..f4e013e2e 100644
--- a/build.gradle
+++ b/build.gradle
@@ -170,7 +170,7 @@ allprojects {
// version 52.0" error messages caused by the errorprone javac.
// See https://github.com/tbroyer/gradle-errorprone-plugin/issues/18 for more information.
configurations.errorprone {
- resolutionStrategy.force 'com.google.errorprone:error_prone_core:2.0.5'
+ resolutionStrategy.force 'com.google.errorprone:error_prone_core:2.0.15'
}
}
diff --git a/config/checkstyle.xml b/config/checkstyle.xml
index 08703c562..ce2345c20 100644
--- a/config/checkstyle.xml
+++ b/config/checkstyle.xml
@@ -35,10 +35,6 @@
-
-
-
-
@@ -89,6 +85,10 @@
+
+
+
+
diff --git a/smack-android-extensions/src/main/java/org/jivesoftware/smackx/ping/android/ServerPingWithAlarmManager.java b/smack-android-extensions/src/main/java/org/jivesoftware/smackx/ping/android/ServerPingWithAlarmManager.java
index 6d9fe943b..054bc0418 100644
--- a/smack-android-extensions/src/main/java/org/jivesoftware/smackx/ping/android/ServerPingWithAlarmManager.java
+++ b/smack-android-extensions/src/main/java/org/jivesoftware/smackx/ping/android/ServerPingWithAlarmManager.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright © 2014 Florian Schmaus
+ * Copyright © 2014-2017 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -63,116 +63,116 @@ import android.os.SystemClock;
*/
public final class ServerPingWithAlarmManager extends Manager {
- private static final Logger LOGGER = Logger.getLogger(ServerPingWithAlarmManager.class
- .getName());
+ private static final Logger LOGGER = Logger.getLogger(ServerPingWithAlarmManager.class
+ .getName());
- private static final String PING_ALARM_ACTION = "org.igniterealtime.smackx.ping.ACTION";
+ private static final String PING_ALARM_ACTION = "org.igniterealtime.smackx.ping.ACTION";
- private static final Map INSTANCES = new WeakHashMap();
+ private static final Map INSTANCES = new WeakHashMap();
- static {
- XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
- @Override
- public void connectionCreated(XMPPConnection connection) {
- getInstanceFor(connection);
- }
- });
- }
+ static {
+ XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
+ @Override
+ public void connectionCreated(XMPPConnection connection) {
+ getInstanceFor(connection);
+ }
+ });
+ }
- public static synchronized ServerPingWithAlarmManager getInstanceFor(XMPPConnection connection) {
- ServerPingWithAlarmManager serverPingWithAlarmManager = INSTANCES.get(connection);
- if (serverPingWithAlarmManager == null) {
- serverPingWithAlarmManager = new ServerPingWithAlarmManager(connection);
- INSTANCES.put(connection, serverPingWithAlarmManager);
- }
- return serverPingWithAlarmManager;
- }
+ public static synchronized ServerPingWithAlarmManager getInstanceFor(XMPPConnection connection) {
+ ServerPingWithAlarmManager serverPingWithAlarmManager = INSTANCES.get(connection);
+ if (serverPingWithAlarmManager == null) {
+ serverPingWithAlarmManager = new ServerPingWithAlarmManager(connection);
+ INSTANCES.put(connection, serverPingWithAlarmManager);
+ }
+ return serverPingWithAlarmManager;
+ }
- private boolean mEnabled = true;
+ private boolean mEnabled = true;
- private ServerPingWithAlarmManager(XMPPConnection connection) {
- super(connection);
- }
+ private ServerPingWithAlarmManager(XMPPConnection connection) {
+ super(connection);
+ }
/**
* If enabled, ServerPingWithAlarmManager will call {@link PingManager#pingServerIfNecessary()}
* for the connection of this instance every half hour.
- *
+ *
* @param enabled
*/
- public void setEnabled(boolean enabled) {
- mEnabled = enabled;
- }
+ public void setEnabled(boolean enabled) {
+ mEnabled = enabled;
+ }
- public boolean isEnabled() {
- return mEnabled;
- }
+ public boolean isEnabled() {
+ return mEnabled;
+ }
- private static final BroadcastReceiver ALARM_BROADCAST_RECEIVER = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- LOGGER.fine("Ping Alarm broadcast received");
- Set> managers;
- synchronized (ServerPingWithAlarmManager.class) {
- // Make a copy to avoid ConcurrentModificationException when
- // iterating directly over INSTANCES and the Set is modified
- // concurrently by creating a new ServerPingWithAlarmManager.
- managers = new HashSet<>(INSTANCES.entrySet());
- }
- for (Entry entry : managers) {
- XMPPConnection connection = entry.getKey();
- if (entry.getValue().isEnabled()) {
- LOGGER.fine("Calling pingServerIfNecessary for connection "
- + connection);
- final PingManager pingManager = PingManager.getInstanceFor(connection);
- // Android BroadcastReceivers have a timeout of 60 seconds.
- // The connections reply timeout may be higher, which causes
- // timeouts of the broadcast receiver and a subsequent ANR
- // of the App of the broadcast receiver. We therefore need
- // to call pingServerIfNecessary() in a new thread to avoid
- // this. It could happen that the device gets back to sleep
- // until the Thread runs, but that's a risk we are willing
- // to take into account as it's unlikely.
- Async.go(new Runnable() {
- @Override
- public void run() {
- pingManager.pingServerIfNecessary();
- }
- }, "PingServerIfNecessary (" + connection.getConnectionCounter() + ')');
- } else {
- LOGGER.fine("NOT calling pingServerIfNecessary (disabled) on connection "
- + connection.getConnectionCounter());
- }
- }
- }
- };
+ private static final BroadcastReceiver ALARM_BROADCAST_RECEIVER = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ LOGGER.fine("Ping Alarm broadcast received");
+ Set> managers;
+ synchronized (ServerPingWithAlarmManager.class) {
+ // Make a copy to avoid ConcurrentModificationException when
+ // iterating directly over INSTANCES and the Set is modified
+ // concurrently by creating a new ServerPingWithAlarmManager.
+ managers = new HashSet<>(INSTANCES.entrySet());
+ }
+ for (Entry entry : managers) {
+ XMPPConnection connection = entry.getKey();
+ if (entry.getValue().isEnabled()) {
+ LOGGER.fine("Calling pingServerIfNecessary for connection "
+ + connection);
+ final PingManager pingManager = PingManager.getInstanceFor(connection);
+ // Android BroadcastReceivers have a timeout of 60 seconds.
+ // The connections reply timeout may be higher, which causes
+ // timeouts of the broadcast receiver and a subsequent ANR
+ // of the App of the broadcast receiver. We therefore need
+ // to call pingServerIfNecessary() in a new thread to avoid
+ // this. It could happen that the device gets back to sleep
+ // until the Thread runs, but that's a risk we are willing
+ // to take into account as it's unlikely.
+ Async.go(new Runnable() {
+ @Override
+ public void run() {
+ pingManager.pingServerIfNecessary();
+ }
+ }, "PingServerIfNecessary (" + connection.getConnectionCounter() + ')');
+ } else {
+ LOGGER.fine("NOT calling pingServerIfNecessary (disabled) on connection "
+ + connection.getConnectionCounter());
+ }
+ }
+ }
+ };
- private static Context sContext;
- private static PendingIntent sPendingIntent;
- private static AlarmManager sAlarmManager;
+ private static Context sContext;
+ private static PendingIntent sPendingIntent;
+ private static AlarmManager sAlarmManager;
/**
* Register a pending intent with the AlarmManager to be broadcasted every half hour and
* register the alarm broadcast receiver to receive this intent. The receiver will check all
* known questions if a ping is Necessary when invoked by the alarm intent.
- *
+ *
* @param context
*/
- public static void onCreate(Context context) {
- sContext = context;
- context.registerReceiver(ALARM_BROADCAST_RECEIVER, new IntentFilter(PING_ALARM_ACTION));
- sAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
- sPendingIntent = PendingIntent.getBroadcast(context, 0, new Intent(PING_ALARM_ACTION), 0);
- sAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
- SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_HALF_HOUR,
- AlarmManager.INTERVAL_HALF_HOUR, sPendingIntent);
- }
+ public static void onCreate(Context context) {
+ sContext = context;
+ context.registerReceiver(ALARM_BROADCAST_RECEIVER, new IntentFilter(PING_ALARM_ACTION));
+ sAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+ sPendingIntent = PendingIntent.getBroadcast(context, 0, new Intent(PING_ALARM_ACTION), 0);
+ sAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
+ SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_HALF_HOUR,
+ AlarmManager.INTERVAL_HALF_HOUR, sPendingIntent);
+ }
/**
* Unregister the alarm broadcast receiver and cancel the alarm.
*/
- public static void onDestroy() {
- sContext.unregisterReceiver(ALARM_BROADCAST_RECEIVER);
- sAlarmManager.cancel(sPendingIntent);
- }
+ public static void onDestroy() {
+ sContext.unregisterReceiver(ALARM_BROADCAST_RECEIVER);
+ sAlarmManager.cancel(sPendingIntent);
+ }
}
diff --git a/smack-android/src/main/java/org/jivesoftware/smack/android/AndroidSmackInitializer.java b/smack-android/src/main/java/org/jivesoftware/smack/android/AndroidSmackInitializer.java
index bae2beb93..b58f8679c 100644
--- a/smack-android/src/main/java/org/jivesoftware/smack/android/AndroidSmackInitializer.java
+++ b/smack-android/src/main/java/org/jivesoftware/smack/android/AndroidSmackInitializer.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright © 2014 Florian Schmaus
+ * Copyright © 2014-2017 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,12 +28,12 @@ import org.jivesoftware.smack.util.stringencoder.android.AndroidBase64UrlSafeEnc
public class AndroidSmackInitializer implements SmackInitializer {
- @Override
- public List initialize() {
- SmackConfiguration.setDefaultHostnameVerifier(new StrictHostnameVerifier());
- Base64.setEncoder(AndroidBase64Encoder.getInstance());
- Base64UrlSafeEncoder.setEncoder(AndroidBase64UrlSafeEncoder.getInstance());
- return null;
- }
+ @Override
+ public List initialize() {
+ SmackConfiguration.setDefaultHostnameVerifier(new StrictHostnameVerifier());
+ Base64.setEncoder(AndroidBase64Encoder.getInstance());
+ Base64UrlSafeEncoder.setEncoder(AndroidBase64UrlSafeEncoder.getInstance());
+ return null;
+ }
}
diff --git a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/BOSHConfiguration.java b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/BOSHConfiguration.java
index 92615f32e..252a49a43 100644
--- a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/BOSHConfiguration.java
+++ b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/BOSHConfiguration.java
@@ -55,6 +55,7 @@ public final class BOSHConfiguration extends ConnectionConfiguration {
return proxy != null;
}
+ @Override
public ProxyInfo getProxyInfo() {
return proxy;
}
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 f88cc7c3e..abf9105f6 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
@@ -203,11 +203,13 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
saslFeatureReceived.reportSuccess();
}
+ @Override
public boolean isSecureConnection() {
// TODO: Implement SSL usage
return false;
}
+ @Override
public boolean isUsingCompression() {
// TODO: Implement compression
return false;
@@ -313,16 +315,25 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
/**
* Initialize the SmackDebugger which allows to log and debug XML traffic.
*/
+ @Override
protected void initDebugger() {
// TODO: Maybe we want to extend the SmackDebugger for simplification
// and a performance boost.
// Initialize a empty writer which discards all data.
writer = new Writer() {
- public void write(char[] cbuf, int off, int len) { /* ignore */}
- public void close() { /* ignore */ }
- public void flush() { /* ignore */ }
- };
+ @Override
+ public void write(char[] cbuf, int off, int len) {
+ /* ignore */}
+
+ @Override
+ public void close() {
+ /* ignore */ }
+
+ @Override
+ public void flush() {
+ /* ignore */ }
+ };
// Initialize a pipe for received raw data.
try {
@@ -338,6 +349,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
// Add listeners for the received and sent raw data.
client.addBOSHClientResponseListener(new BOSHClientResponseListener() {
+ @Override
public void responseReceived(BOSHMessageEvent event) {
if (event.getBody() != null) {
try {
@@ -350,6 +362,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
}
});
client.addBOSHClientRequestListener(new BOSHClientRequestListener() {
+ @Override
public void requestSent(BOSHMessageEvent event) {
if (event.getBody() != null) {
try {
@@ -366,6 +379,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
private Thread thread = this;
private int bufferLength = 1024;
+ @Override
public void run() {
try {
char[] cbuf = new char[bufferLength];
@@ -406,6 +420,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
* Process the connection listeners and try to login if the
* connection was formerly authenticated and is now reconnected.
*/
+ @Override
public void connectionEvent(BOSHClientConnEvent connEvent) {
try {
if (connEvent.isConnected()) {
@@ -463,6 +478,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
*
* @param event the BOSH client response which includes the received packet.
*/
+ @Override
public void responseReceived(BOSHMessageEvent event) {
AbstractBody body = event.getBody();
if (body != null) {
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 b75e937a5..eab2710c2 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java
@@ -1494,6 +1494,12 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
final StanzaListener packetListener = new StanzaListener() {
@Override
public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException {
+ boolean removed = removeAsyncStanzaListener(this);
+ if (!removed) {
+ // We lost a race against the "no response" handling runnable. Avoid calling the callback, as the
+ // exception callback will be invoked (if any).
+ return;
+ }
try {
XMPPErrorException.ifHasErrorThenThrow(packet);
callback.processStanza(packet);
@@ -1503,9 +1509,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
exceptionCallback.processException(e);
}
}
- finally {
- removeAsyncStanzaListener(this);
- }
}
};
removeCallbacksService.schedule(new Runnable() {
@@ -1613,6 +1616,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
private long lastStanzaReceived;
+ @Override
public long getLastStanzaReceived() {
return lastStanzaReceived;
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java b/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java
index 79ef71e67..a5b12da29 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java
@@ -576,14 +576,17 @@ public abstract class ConnectionConfiguration {
}
/**
- * Set the resource to use.
+ * Set the resource we are requesting from the server.
*
- * If resource
is null
, then the server will automatically create a resource for the
- * client. Default resource is "Smack".
+ * If resource
is null
, the default, then the server will automatically create a
+ * resource for the client. Note that XMPP clients only suggest this resource to the server. XMPP servers are
+ * allowed to ignore the client suggested resource and instead assign a completely different
+ * resource (see RFC 6120 § 7.7.1).
*
*
* @param resource the resource to use.
* @return a reference to this builder.
+ * @see RFC 6120 § 7.7.1
*/
public B setResource(Resourcepart resource) {
this.resource = resource;
@@ -591,7 +594,7 @@ public abstract class ConnectionConfiguration {
}
/**
- * Set the resource to use.
+ * Set the resource we are requesting from the server.
*
* @param resource the non-null CharSequence to use a resource.
* @return a reference ot this builder.
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/ReconnectionManager.java b/smack-core/src/main/java/org/jivesoftware/smack/ReconnectionManager.java
index 90a5f9a6a..4430b1f9e 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/ReconnectionManager.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/ReconnectionManager.java
@@ -70,6 +70,7 @@ public final class ReconnectionManager {
static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
+ @Override
public void connectionCreated(XMPPConnection connection) {
if (connection instanceof AbstractXMPPConnection) {
ReconnectionManager.getInstanceFor((AbstractXMPPConnection) connection);
@@ -204,6 +205,7 @@ public final class ReconnectionManager {
/**
* The process will try the reconnection until the connection succeed or the user cancel it
*/
+ @Override
public void run() {
final AbstractXMPPConnection connection = weakRefConnection.get();
if (connection == null) {
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java b/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java
index 74f8d49fb..7bdb8e18a 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java
@@ -37,6 +37,7 @@ import org.jivesoftware.smack.sasl.core.SASLXOauth2Mechanism;
import org.jivesoftware.smack.sasl.core.SCRAMSHA1Mechanism;
import org.jivesoftware.smack.sasl.core.ScramSha1PlusMechanism;
import org.jivesoftware.smack.util.FileUtils;
+import org.jivesoftware.smack.util.StringUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
@@ -60,7 +61,7 @@ public final class SmackInitialization {
static {
String smackVersion;
try {
- BufferedReader reader = new BufferedReader(new InputStreamReader(FileUtils.getStreamForUrl("classpath:org.jivesoftware.smack/version", null)));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(FileUtils.getStreamForUrl("classpath:org.jivesoftware.smack/version", null), StringUtils.UTF8));
smackVersion = reader.readLine();
try {
reader.close();
@@ -232,7 +233,7 @@ public final class SmackInitialization {
}
}
if (SmackInitializer.class.isAssignableFrom(initClass)) {
- SmackInitializer initializer = (SmackInitializer) initClass.newInstance();
+ SmackInitializer initializer = (SmackInitializer) initClass.getConstructor().newInstance();
List exceptions = initializer.initialize();
if (exceptions == null || exceptions.size() == 0) {
LOGGER.log(Level.FINE, "Loaded SmackInitializer " + className);
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/debugger/AbstractDebugger.java b/smack-core/src/main/java/org/jivesoftware/smack/debugger/AbstractDebugger.java
index a7940fe08..7a58e64cb 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/debugger/AbstractDebugger.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/debugger/AbstractDebugger.java
@@ -49,6 +49,7 @@ public abstract class AbstractDebugger implements SmackDebugger {
// Create a special Reader that wraps the main Reader and logs data to the GUI.
this.reader = new ObservableReader(reader);
readerListener = new ReaderListener() {
+ @Override
public void read(String str) {
log("RECV (" + connection.getConnectionCounter() + "): " + str);
}
@@ -58,6 +59,7 @@ public abstract class AbstractDebugger implements SmackDebugger {
// Create a special Writer that wraps the main Writer and logs data to the GUI.
this.writer = new ObservableWriter(writer);
writerListener = new WriterListener() {
+ @Override
public void write(String str) {
log("SENT (" + connection.getConnectionCounter() + "): " + str);
}
@@ -68,6 +70,7 @@ public abstract class AbstractDebugger implements SmackDebugger {
// the GUI. This is what we call "interpreted" packet data, since it's the packet
// data as Smack sees it and not as it's coming in as raw XML.
listener = new StanzaListener() {
+ @Override
public void processStanza(Stanza packet) {
if (printInterpreted) {
log("RCV PKT (" + connection.getConnectionCounter() + "): " + packet.toXML());
@@ -76,10 +79,12 @@ public abstract class AbstractDebugger implements SmackDebugger {
};
connListener = new ConnectionListener() {
+ @Override
public void connected(XMPPConnection connection) {
log("XMPPConnection connected ("
+ connection + ")");
}
+ @Override
public void authenticated(XMPPConnection connection, boolean resumed) {
String logString = "XMPPConnection authenticated (" + connection + ")";
if (resumed) {
@@ -87,6 +92,7 @@ public abstract class AbstractDebugger implements SmackDebugger {
}
log(logString);
}
+ @Override
public void connectionClosed() {
log(
"XMPPConnection closed (" +
@@ -94,24 +100,28 @@ public abstract class AbstractDebugger implements SmackDebugger {
")");
}
+ @Override
public void connectionClosedOnError(Exception e) {
log(
"XMPPConnection closed due to an exception (" +
connection +
")", e);
}
+ @Override
public void reconnectionFailed(Exception e) {
log(
"Reconnection failed due to an exception (" +
connection +
")", e);
}
+ @Override
public void reconnectionSuccessful() {
log(
"XMPPConnection reconnected (" +
connection +
")");
}
+ @Override
public void reconnectingIn(int seconds) {
log(
"XMPPConnection (" +
@@ -125,6 +135,7 @@ public abstract class AbstractDebugger implements SmackDebugger {
protected abstract void log(String logMessage, Throwable throwable);
+ @Override
public Reader newConnectionReader(Reader newReader) {
reader.removeReaderListener(readerListener);
ObservableReader debugReader = new ObservableReader(newReader);
@@ -133,6 +144,7 @@ public abstract class AbstractDebugger implements SmackDebugger {
return reader;
}
+ @Override
public Writer newConnectionWriter(Writer newWriter) {
writer.removeWriterListener(writerListener);
ObservableWriter debugWriter = new ObservableWriter(newWriter);
@@ -159,18 +171,22 @@ public abstract class AbstractDebugger implements SmackDebugger {
connection.addConnectionListener(connListener);
}
+ @Override
public Reader getReader() {
return reader;
}
+ @Override
public Writer getWriter() {
return writer;
}
+ @Override
public StanzaListener getReaderListener() {
return listener;
}
+ @Override
public StanzaListener getWriterListener() {
return null;
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/AbstractFromToMatchesFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/AbstractFromToMatchesFilter.java
new file mode 100644
index 000000000..d9b5605e0
--- /dev/null
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/AbstractFromToMatchesFilter.java
@@ -0,0 +1,72 @@
+/**
+ *
+ * Copyright 2017 Florian Schmaus.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jivesoftware.smack.filter;
+
+import org.jivesoftware.smack.packet.Stanza;
+import org.jxmpp.jid.Jid;
+
+public abstract class AbstractFromToMatchesFilter implements StanzaFilter {
+
+ private final Jid address;
+
+ /**
+ * Flag that indicates if the checking will be done against bare JID addresses or full JIDs.
+ */
+ private final boolean ignoreResourcepart;
+
+ /**
+ * Creates a filter matching on the address returned by {@link #getAddressToCompare(Stanza)}. The address must be
+ * the same as the filter address. The second parameter specifies whether the full or the bare addresses are
+ * compared.
+ *
+ * @param address The address to filter for. If null
is given, then
+ * {@link #getAddressToCompare(Stanza)} must also return null
to match.
+ * @param ignoreResourcepart
+ */
+ protected AbstractFromToMatchesFilter(Jid address, boolean ignoreResourcepart) {
+ if (address != null && ignoreResourcepart) {
+ this.address = address.asBareJid();
+ }
+ else {
+ this.address = address;
+ }
+ this.ignoreResourcepart = ignoreResourcepart;
+ }
+
+ @Override
+ public final boolean accept(final Stanza stanza) {
+ Jid stanzaAddress = getAddressToCompare(stanza);
+
+ if (stanzaAddress == null) {
+ return address == null;
+ }
+
+ if (ignoreResourcepart) {
+ stanzaAddress = stanzaAddress.asBareJid();
+ }
+
+ return stanzaAddress.equals(address);
+ }
+
+ protected abstract Jid getAddressToCompare(Stanza stanza);
+
+ @Override
+ public final String toString() {
+ String matchMode = ignoreResourcepart ? "ignoreResourcepart" : "full";
+ return getClass().getSimpleName() + " (" + matchMode + "): " + address;
+ }
+}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/AndFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/AndFilter.java
index a1a5749fc..216c3ddde 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/AndFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/AndFilter.java
@@ -44,6 +44,7 @@ public class AndFilter extends AbstractListFilter implements StanzaFilter {
super(filters);
}
+ @Override
public boolean accept(Stanza packet) {
for (StanzaFilter filter : filters) {
if (!filter.accept(packet)) {
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/FromMatchesFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/FromMatchesFilter.java
index 08b7f2c89..1e46de307 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/FromMatchesFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/FromMatchesFilter.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright 2003-2014 Jive Software.
+ * Copyright 2003-2014 Jive Software, 2017 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.jivesoftware.smack.filter;
import org.jivesoftware.smack.packet.Stanza;
@@ -28,14 +27,9 @@ import org.jxmpp.jid.Jid;
*
* @author Gaston Dombiak
*/
-public class FromMatchesFilter implements StanzaFilter {
+public final class FromMatchesFilter extends AbstractFromToMatchesFilter {
- private final Jid address;
-
- /**
- * Flag that indicates if the checking will be done against bare JID addresses or full JIDs.
- */
- private final boolean ignoreResourcepart;
+ public final static FromMatchesFilter MATCH_NO_FROM_SET = create(null);
/**
* Creates a filter matching on the "from" field. The from address must be the same as the
@@ -47,13 +41,7 @@ public class FromMatchesFilter implements StanzaFilter {
* @param ignoreResourcepart
*/
public FromMatchesFilter(Jid address, boolean ignoreResourcepart) {
- if (address != null && ignoreResourcepart) {
- this.address = address.asBareJid();
- }
- else {
- this.address = address;
- }
- this.ignoreResourcepart = ignoreResourcepart;
+ super(address, ignoreResourcepart);
}
/**
@@ -61,51 +49,38 @@ public class FromMatchesFilter implements StanzaFilter {
* the filter address with the bare from address. Otherwise, compares the filter address
* with the full from address.
*
- * @param address The address to filter for. If null
is given, the stanza(/packet) must not
+ * @param address The address to filter for. If null
is given, the stanza must not
* have a from address.
*/
public static FromMatchesFilter create(Jid address) {
- return new FromMatchesFilter(address, address.hasNoResource()) ;
+ return new FromMatchesFilter(address, address != null ? address.hasNoResource() : false) ;
}
/**
* Creates a filter matching on the "from" field. Compares the bare version of from and filter
* address.
*
- * @param address The address to filter for. If null
is given, the stanza(/packet) must not
+ * @param address The address to filter for. If null
is given, the stanza must not
* have a from address.
*/
public static FromMatchesFilter createBare(Jid address) {
- address = (address == null) ? null : address;
return new FromMatchesFilter(address, true);
}
-
/**
- * Creates a filter matching on the "from" field. Compares the full version of from and filter
+ * Creates a filter matching on the "from" field. Compares the full version, if available, of from and filter
* address.
*
- * @param address The address to filter for. If null
is given, the stanza(/packet) must not
+ * @param address The address to filter for. If null
is given, the stanza must not
* have a from address.
*/
public static FromMatchesFilter createFull(Jid address) {
return new FromMatchesFilter(address, false);
}
- public boolean accept(Stanza packet) {
- Jid from = packet.getFrom();
- if (from == null) {
- return address == null;
- }
-
- if (ignoreResourcepart) {
- from = from.asBareJid();
- }
- return from.equals(address);
+ @Override
+ protected Jid getAddressToCompare(Stanza stanza) {
+ return stanza.getFrom();
}
- public String toString() {
- String matchMode = ignoreResourcepart ? "ignoreResourcepart" : "full";
- return getClass().getSimpleName() + " (" + matchMode + "): " + address;
- }
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/IQTypeFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/IQTypeFilter.java
index f84bdadb2..fe50083df 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/IQTypeFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/IQTypeFilter.java
@@ -35,12 +35,12 @@ public final class IQTypeFilter extends FlexibleStanzaTypeFilter {
public static final StanzaFilter ERROR = new IQTypeFilter(Type.error);
public static final StanzaFilter GET_OR_SET = new OrFilter(GET, SET);
- private final IQ.Type type;
+ private final IQ.Type type;
- private IQTypeFilter(IQ.Type type) {
+ private IQTypeFilter(IQ.Type type) {
super(IQ.class);
- this.type = Objects.requireNonNull(type, "Type must not be null");
- }
+ this.type = Objects.requireNonNull(type, "Type must not be null");
+ }
@Override
protected boolean acceptSpecific(IQ iq) {
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/NotFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/NotFilter.java
index e657cf4eb..c836be1c1 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/NotFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/NotFilter.java
@@ -39,6 +39,7 @@ public class NotFilter implements StanzaFilter {
this.filter = Objects.requireNonNull(filter, "Parameter must not be null.");
}
+ @Override
public boolean accept(Stanza packet) {
return !filter.accept(packet);
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketExtensionFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketExtensionFilter.java
index f6458194f..82c1016c0 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketExtensionFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketExtensionFilter.java
@@ -67,6 +67,7 @@ public class PacketExtensionFilter implements StanzaFilter {
this(packetExtension.getElementName(), packetExtension.getNamespace());
}
+ @Override
public boolean accept(Stanza packet) {
return packet.hasExtension(elementName, namespace);
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketIDFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketIDFilter.java
index e4ea23248..d596f9ef9 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketIDFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketIDFilter.java
@@ -54,10 +54,12 @@ public class PacketIDFilter implements StanzaFilter {
this.packetID = packetID;
}
+ @Override
public boolean accept(Stanza packet) {
return packetID.equals(packet.getStanzaId());
}
+ @Override
public String toString() {
return getClass().getSimpleName() + ": id=" + packetID;
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketTypeFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketTypeFilter.java
index f20fdeac1..8b254f56e 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketTypeFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketTypeFilter.java
@@ -51,6 +51,7 @@ public class PacketTypeFilter implements StanzaFilter {
this.packetType = packetType;
}
+ @Override
public boolean accept(Stanza packet) {
return packetType.isInstance(packet);
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/StanzaExtensionFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/StanzaExtensionFilter.java
index e8fb46d46..f7f810e82 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/StanzaExtensionFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/StanzaExtensionFilter.java
@@ -65,6 +65,7 @@ public class StanzaExtensionFilter implements StanzaFilter {
this(packetExtension.getElementName(), packetExtension.getNamespace());
}
+ @Override
public boolean accept(Stanza packet) {
return packet.hasExtension(elementName, namespace);
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/StanzaIdFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/StanzaIdFilter.java
index 3cc9740a1..0e6b0f404 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/StanzaIdFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/StanzaIdFilter.java
@@ -47,10 +47,12 @@ public class StanzaIdFilter implements StanzaFilter {
this.stanzaId = StringUtils.requireNotNullOrEmpty(stanzaID, "Stanza ID must not be null or empty.");
}
+ @Override
public boolean accept(Stanza stanza) {
return stanzaId.equals(stanza.getStanzaId());
}
+ @Override
public String toString() {
return getClass().getSimpleName() + ": id=" + stanzaId;
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/StanzaTypeFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/StanzaTypeFilter.java
index 8b8971cda..156a7914e 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/StanzaTypeFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/StanzaTypeFilter.java
@@ -51,6 +51,7 @@ public final class StanzaTypeFilter implements StanzaFilter {
this.packetType = packetType;
}
+ @Override
public boolean accept(Stanza packet) {
return packetType.isInstance(packet);
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/ToFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/ToFilter.java
index 115c30f15..d8964b5f1 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/ToFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/ToFilter.java
@@ -19,6 +19,12 @@ package org.jivesoftware.smack.filter;
import org.jivesoftware.smack.packet.Stanza;
import org.jxmpp.jid.Jid;
+/**
+ * Match based on the 'to' attribute of a Stanza.
+ *
+ * @deprecated use {@link ToMatchesFilter} instead.
+ */
+@Deprecated
public class ToFilter implements StanzaFilter {
private final Jid to;
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/ToMatchesFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/ToMatchesFilter.java
new file mode 100644
index 000000000..99ca2a762
--- /dev/null
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/ToMatchesFilter.java
@@ -0,0 +1,69 @@
+/**
+ *
+ * Copyright 2017 Florian Schmaus.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jivesoftware.smack.filter;
+
+import org.jivesoftware.smack.packet.Stanza;
+import org.jxmpp.jid.Jid;
+
+public final class ToMatchesFilter extends AbstractFromToMatchesFilter {
+
+ public static final ToMatchesFilter MATCH_NO_TO_SET = create(null);
+
+ public ToMatchesFilter(Jid address, boolean ignoreResourcepart) {
+ super(address, ignoreResourcepart);
+ }
+
+ /**
+ * Creates a filter matching on the "to" field. If the filter address is bare, compares
+ * the filter address with the bare from address. Otherwise, compares the filter address
+ * with the full from address.
+ *
+ * @param address The address to filter for. If null
is given, the stanza must not
+ * have a from address.
+ */
+ public static ToMatchesFilter create(Jid address) {
+ return new ToMatchesFilter(address, address != null ? address.hasNoResource() : false) ;
+ }
+
+ /**
+ * Creates a filter matching on the "to" field. Compares the bare version of to and filter
+ * address.
+ *
+ * @param address The address to filter for. If null
is given, the stanza must not
+ * have a from address.
+ */
+ public static ToMatchesFilter createBare(Jid address) {
+ return new ToMatchesFilter(address, true);
+ }
+
+ /**
+ * Creates a filter matching on the "to" field. Compares the full version, if available, of to and filter
+ * address.
+ *
+ * @param address The address to filter for. If null
is given, the stanza must not
+ * have a from address.
+ */
+ public static ToMatchesFilter createFull(Jid address) {
+ return new ToMatchesFilter(address, false);
+ }
+
+ @Override
+ protected Jid getAddressToCompare(Stanza stanza) {
+ return stanza.getTo();
+ }
+
+}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/DefaultExtensionElement.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/DefaultExtensionElement.java
index 88166db43..e51b5b4ee 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/packet/DefaultExtensionElement.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/DefaultExtensionElement.java
@@ -70,6 +70,7 @@ public class DefaultExtensionElement implements ExtensionElement {
*
* @return the XML element name of the stanza(/packet) extension.
*/
+ @Override
public String getElementName() {
return elementName;
}
@@ -79,6 +80,7 @@ public class DefaultExtensionElement implements ExtensionElement {
*
* @return the XML namespace of the stanza(/packet) extension.
*/
+ @Override
public String getNamespace() {
return namespace;
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java
index e0ec0ce82..ebf18faef 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java
@@ -570,6 +570,7 @@ public final class Message extends Stanza implements TypedCloneable {
}
+ @Override
public int hashCode() {
final int prime = 31;
int result = 1;
@@ -578,6 +579,7 @@ public final class Message extends Stanza implements TypedCloneable {
return result;
}
+ @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
@@ -632,6 +634,7 @@ public final class Message extends Stanza implements TypedCloneable {
return message;
}
+ @Override
public int hashCode() {
final int prime = 31;
int result = 1;
@@ -640,6 +643,7 @@ public final class Message extends Stanza implements TypedCloneable {
return result;
}
+ @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/provider/IntrospectionProvider.java b/smack-core/src/main/java/org/jivesoftware/smack/provider/IntrospectionProvider.java
index 88549db4f..e51033f43 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/provider/IntrospectionProvider.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/provider/IntrospectionProvider.java
@@ -78,7 +78,7 @@ public class IntrospectionProvider{
IOException, IllegalArgumentException, InvocationTargetException,
ClassNotFoundException {
ParserUtils.assertAtStartTag(parser);
- Object object = objectClass.newInstance();
+ Object object = objectClass.getConstructor().newInstance();
outerloop: while (true) {
int eventType = parser.next();
switch (eventType) {
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/provider/ProviderFileLoader.java b/smack-core/src/main/java/org/jivesoftware/smack/provider/ProviderFileLoader.java
index 2090401cc..bee798fb0 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/provider/ProviderFileLoader.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/provider/ProviderFileLoader.java
@@ -83,7 +83,8 @@ public class ProviderFileLoader implements ProviderLoader {
// reflection later to create instances of the class.
// Add the provider to the map.
if (IQProvider.class.isAssignableFrom(provider)) {
- iqProviders.add(new IQProviderInfo(elementName, namespace, (IQProvider) provider.newInstance()));
+ IQProvider iqProvider = (IQProvider) provider.getConstructor().newInstance();
+ iqProviders.add(new IQProviderInfo(elementName, namespace, iqProvider));
}
else {
exceptions.add(new IllegalArgumentException(className + " is not a IQProvider"));
@@ -96,7 +97,9 @@ public class ProviderFileLoader implements ProviderLoader {
// then we'll use reflection later to create instances
// of the class.
if (ExtensionElementProvider.class.isAssignableFrom(provider)) {
- extProviders.add(new ExtensionProviderInfo(elementName, namespace, (ExtensionElementProvider) provider.newInstance()));
+ ExtensionElementProvider extensionElementProvider = (ExtensionElementProvider) provider.getConstructor().newInstance();
+ extProviders.add(new ExtensionProviderInfo(elementName, namespace,
+ extensionElementProvider));
}
else {
exceptions.add(new IllegalArgumentException(className
@@ -104,9 +107,10 @@ public class ProviderFileLoader implements ProviderLoader {
}
break;
case "streamFeatureProvider":
+ ExtensionElementProvider streamFeatureProvider = (ExtensionElementProvider) provider.getConstructor().newInstance();
sfProviders.add(new StreamFeatureProviderInfo(elementName,
namespace,
- (ExtensionElementProvider) provider.newInstance()));
+ streamFeatureProvider));
break;
default:
LOGGER.warning("Unknown provider type: " + typeName);
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks4ProxySocketConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks4ProxySocketConnection.java
index 40ef48215..65a54059a 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks4ProxySocketConnection.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks4ProxySocketConnection.java
@@ -23,6 +23,8 @@ import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
+import org.jivesoftware.smack.util.StringUtils;
+
/**
* Socket factory for socks4 proxy.
*
@@ -89,7 +91,8 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection {
if(user!=null)
{
- System.arraycopy(user.getBytes(), 0, buf, index, user.length());
+ byte[] userBytes = user.getBytes(StringUtils.UTF8);
+ System.arraycopy(userBytes, 0, buf, index, user.length());
index+=user.length();
}
buf[index++]=0;
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks5ProxySocketConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks5ProxySocketConnection.java
index d7b71802e..3e54f877c 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks5ProxySocketConnection.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/proxy/Socks5ProxySocketConnection.java
@@ -22,6 +22,8 @@ import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
+import org.jivesoftware.smack.util.StringUtils;
+
/**
* Socket factory for Socks5 proxy.
*
@@ -132,11 +134,13 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
index=0;
buf[index++]=1;
buf[index++]=(byte)(user.length());
- System.arraycopy(user.getBytes(), 0, buf, index,
+ byte[] userBytes = user.getBytes(StringUtils.UTF8);
+ System.arraycopy(userBytes, 0, buf, index,
user.length());
index+=user.length();
- buf[index++]=(byte)(passwd.length());
- System.arraycopy(passwd.getBytes(), 0, buf, index,
+ byte[] passwordBytes = user.getBytes(StringUtils.UTF8);
+ buf[index++]=(byte)(passwordBytes.length);
+ System.arraycopy(passwordBytes, 0, buf, index,
passwd.length());
index+=passwd.length();
@@ -210,7 +214,7 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
buf[index++]=1; // CONNECT
buf[index++]=0;
- byte[] hostb= host.getBytes();
+ byte[] hostb= host.getBytes(StringUtils.UTF8);
int len=hostb.length;
buf[index++]=3; // DOMAINNAME
buf[index++]=(byte)(len);
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/sasl/SASLMechanism.java b/smack-core/src/main/java/org/jivesoftware/smack/sasl/SASLMechanism.java
index dce630b8c..c2cc66e3a 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/sasl/SASLMechanism.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/sasl/SASLMechanism.java
@@ -265,8 +265,11 @@ public abstract class SASLMechanism implements Comparable {
return null;
}
+ @Override
public final int compareTo(SASLMechanism other) {
- return getPriority() - other.getPriority();
+ // Switch to Integer.compare(int, int) once Smack is on Android 19 or higher.
+ Integer ourPriority = getPriority();
+ return ourPriority.compareTo(other.getPriority());
}
/**
@@ -298,7 +301,7 @@ public abstract class SASLMechanism implements Comparable {
}
/**
- * SASLprep the given String.
+ * SASLprep the given String. The resulting String is in UTF-8.
*
* @param string the String to sasl prep.
* @return the given String SASL preped
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/sasl/core/SASLAnonymous.java b/smack-core/src/main/java/org/jivesoftware/smack/sasl/core/SASLAnonymous.java
index 7f99b5ef8..509104d2b 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/sasl/core/SASLAnonymous.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/sasl/core/SASLAnonymous.java
@@ -30,6 +30,7 @@ public class SASLAnonymous extends SASLMechanism {
public static final String NAME = "ANONYMOUS";
+ @Override
public String getName() {
return NAME;
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/sasl/core/ScramMechanism.java b/smack-core/src/main/java/org/jivesoftware/smack/sasl/core/ScramMechanism.java
index a59b40815..08a1f6aab 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/sasl/core/ScramMechanism.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/sasl/core/ScramMechanism.java
@@ -16,6 +16,7 @@
*/
package org.jivesoftware.smack.sasl.core;
+import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.SecureRandom;
import java.util.Collections;
@@ -105,7 +106,15 @@ public abstract class ScramMechanism extends SASLMechanism {
@Override
protected byte[] evaluateChallenge(byte[] challenge) throws SmackException {
- final String challengeString = new String(challenge);
+ String challengeString;
+ try {
+ // TODO: Where is it specified that this is an UTF-8 encoded string?
+ challengeString = new String(challenge, StringUtils.UTF8);
+ }
+ catch (UnsupportedEncodingException e) {
+ throw new AssertionError(e);
+ }
+
switch (state) {
case AUTH_TEXT_SENT:
final String serverFirstMessage = challengeString;
@@ -358,14 +367,21 @@ public abstract class ScramMechanism extends SASLMechanism {
* (PRF) and with dkLen == output length of HMAC() == output length of H().
*
*
- * @param str
+ * @param normalizedPassword the normalized password.
* @param salt
* @param iterations
* @return the result of the Hi function.
* @throws SmackException
*/
- private byte[] hi(String str, byte[] salt, int iterations) throws SmackException {
- byte[] key = str.getBytes();
+ private byte[] hi(String normalizedPassword, byte[] salt, int iterations) throws SmackException {
+ byte[] key;
+ try {
+ // According to RFC 5802 § 2.2, the resulting string of the normalization is also in UTF-8.
+ key = normalizedPassword.getBytes(StringUtils.UTF8);
+ }
+ catch (UnsupportedEncodingException e) {
+ throw new AssertionError();
+ }
// U1 := HMAC(str, salt + INT(1))
byte[] u = hmac(key, ByteUtils.concact(salt, ONE));
byte[] res = u.clone();
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/ArrayBlockingQueueWithShutdown.java b/smack-core/src/main/java/org/jivesoftware/smack/util/ArrayBlockingQueueWithShutdown.java
index a24c06d49..742b34cf1 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/ArrayBlockingQueueWithShutdown.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/ArrayBlockingQueueWithShutdown.java
@@ -240,6 +240,7 @@ public class ArrayBlockingQueueWithShutdown extends AbstractQueue implemen
* @param e the element to add.
* @throws InterruptedException if interrupted while waiting or if the queue was shut down.
*/
+ @Override
public void put(E e) throws InterruptedException {
checkNotNull(e);
lock.lockInterruptibly();
@@ -452,6 +453,7 @@ public class ArrayBlockingQueueWithShutdown extends AbstractQueue implemen
}
}
+ @Override
public boolean hasNext() {
return nextIndex >= 0;
}
@@ -469,6 +471,7 @@ public class ArrayBlockingQueueWithShutdown extends AbstractQueue implemen
}
}
+ @Override
public E next() {
lock.lock();
try {
@@ -486,6 +489,7 @@ public class ArrayBlockingQueueWithShutdown extends AbstractQueue implemen
}
}
+ @Override
public void remove() {
lock.lock();
try {
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/DNSUtil.java b/smack-core/src/main/java/org/jivesoftware/smack/util/DNSUtil.java
index ebe709a06..60cfd8af3 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/DNSUtil.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/DNSUtil.java
@@ -185,7 +185,7 @@ public class DNSUtil {
}
List srvRecords = dnsResolver.lookupSRVRecords(srvDomain, failedAddresses, dnssecMode);
- if (srvRecords != null) {
+ if (srvRecords != null && !srvRecords.isEmpty()) {
if (LOGGER.isLoggable(Level.FINE)) {
String logMessage = "Resolved SRV RR for " + srvDomain + ":";
for (SRVRecord r : srvRecords)
@@ -194,6 +194,8 @@ public class DNSUtil {
}
List sortedRecords = sortSRVRecords(srvRecords);
addresses.addAll(sortedRecords);
+ } else {
+ LOGGER.info("Could not resolve DNS SRV resource records for " + srvDomain + ". Consider adding those.");
}
int defaultPort = -1;
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/FileUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/FileUtils.java
index 395fdf846..8fa5bb557 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/FileUtils.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/FileUtils.java
@@ -87,7 +87,8 @@ public final class FileUtils {
public static boolean addLines(String url, Set set) throws MalformedURLException, IOException {
InputStream is = getStreamForUrl(url, null);
if (is == null) return false;
- BufferedReader br = new BufferedReader(new InputStreamReader(is));
+ InputStreamReader sr = new InputStreamReader(is, StringUtils.UTF8);
+ BufferedReader br = new BufferedReader(sr);
String line;
while ((line = br.readLine()) != null) {
set.add(line);
@@ -102,6 +103,7 @@ public final class FileUtils {
* @return the content of file or null in case of an error
* @throws IOException
*/
+ @SuppressWarnings("DefaultCharset")
public static String readFileOrThrow(File file) throws FileNotFoundException, IOException {
Reader reader = null;
try {
@@ -132,6 +134,7 @@ public final class FileUtils {
return null;
}
+ @SuppressWarnings("DefaultCharset")
public static void writeFileOrThrow(File file, CharSequence content) throws IOException {
FileWriter writer = new FileWriter(file, false);
try {
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/ObservableReader.java b/smack-core/src/main/java/org/jivesoftware/smack/util/ObservableReader.java
index 3cd27ff2f..43713261a 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/ObservableReader.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/ObservableReader.java
@@ -37,6 +37,7 @@ public class ObservableReader extends Reader {
this.wrappedReader = wrappedReader;
}
+ @Override
public int read(char[] cbuf, int off, int len) throws IOException {
int count = wrappedReader.read(cbuf, off, len);
if (count > 0) {
@@ -54,34 +55,42 @@ public class ObservableReader extends Reader {
return count;
}
+ @Override
public void close() throws IOException {
wrappedReader.close();
}
+ @Override
public int read() throws IOException {
return wrappedReader.read();
}
+ @Override
public int read(char[] cbuf) throws IOException {
return wrappedReader.read(cbuf);
}
+ @Override
public long skip(long n) throws IOException {
return wrappedReader.skip(n);
}
+ @Override
public boolean ready() throws IOException {
return wrappedReader.ready();
}
+ @Override
public boolean markSupported() {
return wrappedReader.markSupported();
}
+ @Override
public void mark(int readAheadLimit) throws IOException {
wrappedReader.mark(readAheadLimit);
}
+ @Override
public void reset() throws IOException {
wrappedReader.reset();
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/ObservableWriter.java b/smack-core/src/main/java/org/jivesoftware/smack/util/ObservableWriter.java
index 8a7a754de..a92d00c28 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/ObservableWriter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/ObservableWriter.java
@@ -38,36 +38,43 @@ public class ObservableWriter extends Writer {
this.wrappedWriter = wrappedWriter;
}
+ @Override
public void write(char[] cbuf, int off, int len) throws IOException {
wrappedWriter.write(cbuf, off, len);
String str = new String(cbuf, off, len);
maybeNotifyListeners(str);
}
+ @Override
public void flush() throws IOException {
notifyListeners();
wrappedWriter.flush();
}
+ @Override
public void close() throws IOException {
wrappedWriter.close();
}
+ @Override
public void write(int c) throws IOException {
wrappedWriter.write(c);
}
+ @Override
public void write(char[] cbuf) throws IOException {
wrappedWriter.write(cbuf);
String str = new String(cbuf);
maybeNotifyListeners(str);
}
+ @Override
public void write(String str) throws IOException {
wrappedWriter.write(str);
maybeNotifyListeners(str);
}
+ @Override
public void write(String str, int off, int len) throws IOException {
wrappedWriter.write(str, off, len);
str = str.substring(off, off + len);
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java
index f702052fd..4c9ce0699 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java
@@ -290,8 +290,6 @@ public class PacketParserUtils {
break outerloop;
}
break;
- case XmlPullParser.TEXT:
- throw new IllegalStateException("Invalid Stanza: Must not contain text or mixed content as direct child of ");
}
}
@@ -592,8 +590,6 @@ public class PacketParserUtils {
break outerloop;
}
break;
- case XmlPullParser.TEXT:
- throw new IllegalStateException("Invalid Stanza: Must not contain text or mixed content as direct child of ");
}
}
return presence;
@@ -650,8 +646,6 @@ public class PacketParserUtils {
break outerloop;
}
break;
- case XmlPullParser.TEXT:
- throw new IllegalStateException("Invalid Stanza: Must not contain text or mixed content as direct child of ");
}
}
// Decide what to do when an IQ packet was not understood
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java
index bd4c722fc..5a67c720e 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright © 2014 Florian Schmaus
+ * Copyright © 2014-2017 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ import java.util.Locale;
import org.jivesoftware.smack.SmackException;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.EntityFullJid;
+import org.jxmpp.jid.EntityJid;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.jid.parts.Resourcepart;
@@ -98,6 +99,24 @@ public class ParserUtils {
return JidCreate.entityFullFrom(jidString);
}
+ public static EntityJid getEntityJidAttribute(XmlPullParser parser, String name) throws XmppStringprepException {
+ final String jidString = parser.getAttributeValue("", name);
+ if (jidString == null) {
+ return null;
+ }
+ Jid jid = JidCreate.from(jidString);
+
+ if (!jid.hasLocalpart()) return null;
+
+ EntityFullJid fullJid = jid.asEntityFullJidIfPossible();
+ if (fullJid != null) {
+ return fullJid;
+ }
+
+ EntityBareJid bareJid = jid.asEntityBareJidIfPossible();
+ return bareJid;
+ }
+
public static Resourcepart getResourcepartAttribute(XmlPullParser parser, String name) throws XmppStringprepException {
final String resourcepartString = parser.getAttributeValue("", name);
if (resourcepartString == null) {
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/dns/DNSResolver.java b/smack-core/src/main/java/org/jivesoftware/smack/util/dns/DNSResolver.java
index 79de3e08a..f5e4518f9 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/dns/DNSResolver.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/dns/DNSResolver.java
@@ -20,6 +20,7 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.List;
+import java.util.logging.Logger;
import org.jivesoftware.smack.ConnectionConfiguration.DnssecMode;
@@ -29,6 +30,8 @@ import org.jivesoftware.smack.ConnectionConfiguration.DnssecMode;
*/
public abstract class DNSResolver {
+ protected static final Logger LOGGER = Logger.getLogger(DNSResolver.class.getName());
+
private final boolean supportsDnssec;
protected DNSResolver(boolean supportsDnssec) {
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base32.java b/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base32.java
index 3a373671a..8e2f27f14 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base32.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/stringencoder/Base32.java
@@ -20,6 +20,9 @@ package org.jivesoftware.smack.util.stringencoder;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+import org.jivesoftware.smack.util.StringUtils;
/**
* Base32 string encoding is useful for when filenames case-insensitive filesystems are encoded.
@@ -53,7 +56,13 @@ public class Base32 {
public static String decode(String str) {
ByteArrayOutputStream bs = new ByteArrayOutputStream();
- byte[] raw = str.getBytes();
+ byte[] raw;
+ try {
+ raw = str.getBytes(StringUtils.UTF8);
+ }
+ catch (UnsupportedEncodingException e) {
+ throw new AssertionError(e);
+ }
for (int i = 0; i < raw.length; i++) {
char c = (char) raw[i];
if (!Character.isWhitespace(c)) {
@@ -106,11 +115,24 @@ public class Base32 {
}
}
- return new String(bs.toByteArray());
+ String res;
+ try {
+ res = new String(bs.toByteArray(), StringUtils.UTF8);
+ }
+ catch (UnsupportedEncodingException e) {
+ throw new AssertionError(e);
+ }
+ return res;
}
public static String encode(String str) {
- byte[] b = str.getBytes();
+ byte[] b;
+ try {
+ b = str.getBytes(StringUtils.UTF8);
+ }
+ catch (UnsupportedEncodingException e) {
+ throw new AssertionError(e);
+ }
ByteArrayOutputStream os = new ByteArrayOutputStream();
for (int i = 0; i < (b.length + 4) / 5; i++) {
@@ -153,7 +175,14 @@ public class Base32 {
os.write(c);
}
}
- return new String(os.toByteArray());
+ String res;
+ try {
+ res = new String(os.toByteArray(), StringUtils.UTF8);
+ }
+ catch (UnsupportedEncodingException e) {
+ throw new AssertionError(e);
+ }
+ return res;
}
private static int lenToPadding(int blocklen) {
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 1bd11e119..40f9b4e7a 100644
--- a/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java
+++ b/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java
@@ -180,6 +180,7 @@ public class DummyConnection extends AbstractXMPPConnection {
*
* @param packet the stanza(/packet) to process.
*/
+ @Override
public void processStanza(Stanza packet) {
invokeStanzaCollectorsAndNotifyRecvListeners(packet);
}
diff --git a/smack-core/src/test/java/org/jivesoftware/smack/StanzaCollectorTest.java b/smack-core/src/test/java/org/jivesoftware/smack/StanzaCollectorTest.java
index be4f771f0..4120f4529 100644
--- a/smack-core/src/test/java/org/jivesoftware/smack/StanzaCollectorTest.java
+++ b/smack-core/src/test/java/org/jivesoftware/smack/StanzaCollectorTest.java
@@ -26,190 +26,190 @@ import org.junit.Test;
public class StanzaCollectorTest
{
- @Test
- public void verifyRollover() throws InterruptedException
- {
- TestStanzaCollector collector = new TestStanzaCollector(null, new OKEverything(), 5);
+ @Test
+ public void verifyRollover() throws InterruptedException
+ {
+ TestStanzaCollector collector = new TestStanzaCollector(null, new OKEverything(), 5);
- for (int i=0; i<6; i++)
- {
- Stanza testPacket = new TestPacket(i);
- collector.processStanza(testPacket);
- }
+ for (int i=0; i<6; i++)
+ {
+ Stanza testPacket = new TestPacket(i);
+ collector.processStanza(testPacket);
+ }
- // Assert that '0' has rolled off
- assertEquals("1", collector.nextResultBlockForever().getStanzaId());
- assertEquals("2", collector.nextResultBlockForever().getStanzaId());
- assertEquals("3", collector.nextResultBlockForever().getStanzaId());
- assertEquals("4", collector.nextResultBlockForever().getStanzaId());
- assertEquals("5", collector.pollResult().getStanzaId());
- assertNull(collector.pollResult());
+ // Assert that '0' has rolled off
+ assertEquals("1", collector.nextResultBlockForever().getStanzaId());
+ assertEquals("2", collector.nextResultBlockForever().getStanzaId());
+ assertEquals("3", collector.nextResultBlockForever().getStanzaId());
+ assertEquals("4", collector.nextResultBlockForever().getStanzaId());
+ assertEquals("5", collector.pollResult().getStanzaId());
+ assertNull(collector.pollResult());
- for (int i=10; i<15; i++)
- {
- Stanza testPacket = new TestPacket(i);
- collector.processStanza(testPacket);
- }
+ for (int i=10; i<15; i++)
+ {
+ Stanza testPacket = new TestPacket(i);
+ collector.processStanza(testPacket);
+ }
- assertEquals("10", collector.nextResultBlockForever().getStanzaId());
- assertEquals("11", collector.nextResultBlockForever().getStanzaId());
- assertEquals("12", collector.nextResultBlockForever().getStanzaId());
- assertEquals("13", collector.nextResultBlockForever().getStanzaId());
- assertEquals("14", collector.pollResult().getStanzaId());
- assertNull(collector.pollResult());
+ assertEquals("10", collector.nextResultBlockForever().getStanzaId());
+ assertEquals("11", collector.nextResultBlockForever().getStanzaId());
+ assertEquals("12", collector.nextResultBlockForever().getStanzaId());
+ assertEquals("13", collector.nextResultBlockForever().getStanzaId());
+ assertEquals("14", collector.pollResult().getStanzaId());
+ assertNull(collector.pollResult());
- assertNull(collector.nextResult(1000));
- }
+ assertNull(collector.nextResult(1000));
+ }
/**
* Although this doesn't guarentee anything due to the nature of threading, it can potentially
* catch problems.
*/
- @Test
- public void verifyThreadSafety()
- {
- int insertCount = 500;
- final TestStanzaCollector collector = new TestStanzaCollector(null, new OKEverything(), insertCount);
+ @Test
+ public void verifyThreadSafety()
+ {
+ int insertCount = 500;
+ final TestStanzaCollector collector = new TestStanzaCollector(null, new OKEverything(), insertCount);
- Thread consumer1 = new Thread(new Runnable()
- {
- @Override
- public void run()
- {
- try
- {
- while (true)
- {
- try
- {
- Thread.sleep(3);
- }
- catch (InterruptedException e)
- {
- }
- @SuppressWarnings("unused")
- Stanza packet = collector.nextResultBlockForever();
-// System.out.println(Thread.currentThread().getName() + " packet: " + packet);
- }
- }
+ Thread consumer1 = new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ while (true)
+ {
+ try
+ {
+ Thread.sleep(3);
+ }
+ catch (InterruptedException e)
+ {
+ }
+ @SuppressWarnings("unused")
+ Stanza packet = collector.nextResultBlockForever();
+// System.out.println(Thread.currentThread().getName() + " packet: " + packet);
+ }
+ }
catch (InterruptedException e) {
throw new RuntimeException(e);
}
- }
- });
- consumer1.setName("consumer 1");
+ }
+ });
+ consumer1.setName("consumer 1");
- Thread consumer2 = new Thread(new Runnable()
- {
- @Override
- public void run()
- {
- Stanza p = null;
+ Thread consumer2 = new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ Stanza p = null;
- do
- {
- try
- {
- Thread.sleep(3);
- }
- catch (InterruptedException e)
- {
- }
- try {
+ do
+ {
+ try
+ {
+ Thread.sleep(3);
+ }
+ catch (InterruptedException e)
+ {
+ }
+ try {
p = collector.nextResult(1);
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
-// System.out.println(Thread.currentThread().getName() + " packet: " + p);
- }
- while (p != null);
- }
- });
- consumer2.setName("consumer 2");
+// System.out.println(Thread.currentThread().getName() + " packet: " + p);
+ }
+ while (p != null);
+ }
+ });
+ consumer2.setName("consumer 2");
- Thread consumer3 = new Thread(new Runnable()
- {
- @Override
- public void run()
- {
- Stanza p = null;
+ Thread consumer3 = new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ Stanza p = null;
- do
- {
- try
- {
- Thread.sleep(3);
- }
- catch (InterruptedException e)
- {
- }
- p = collector.pollResult();
-// System.out.println(Thread.currentThread().getName() + " packet: " + p);
- }
- while (p != null);
- }
- });
- consumer3.setName("consumer 3");
+ do
+ {
+ try
+ {
+ Thread.sleep(3);
+ }
+ catch (InterruptedException e)
+ {
+ }
+ p = collector.pollResult();
+// System.out.println(Thread.currentThread().getName() + " packet: " + p);
+ }
+ while (p != null);
+ }
+ });
+ consumer3.setName("consumer 3");
- consumer1.start();
- consumer2.start();
- consumer3.start();
+ consumer1.start();
+ consumer2.start();
+ consumer3.start();
- for(int i=0; i" + getStanzaId() + "";
- }
+ @Override
+ public String toXML()
+ {
+ return "" + getStanzaId() + "";
+ }
@Override
public String toString() {
return toXML();
}
- }
+ }
}
diff --git a/smack-core/src/test/java/org/jivesoftware/smack/sasl/DigestMd5SaslTest.java b/smack-core/src/test/java/org/jivesoftware/smack/sasl/DigestMd5SaslTest.java
index 5855aba7f..9e1862b11 100644
--- a/smack-core/src/test/java/org/jivesoftware/smack/sasl/DigestMd5SaslTest.java
+++ b/smack-core/src/test/java/org/jivesoftware/smack/sasl/DigestMd5SaslTest.java
@@ -19,6 +19,7 @@ package org.jivesoftware.smack.sasl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
@@ -38,14 +39,14 @@ public class DigestMd5SaslTest extends AbstractSaslTest {
super(saslMechanism);
}
- protected void runTest(boolean useAuthzid) throws NotConnectedException, SmackException, InterruptedException, XmppStringprepException {
+ protected void runTest(boolean useAuthzid) throws NotConnectedException, SmackException, InterruptedException, XmppStringprepException, UnsupportedEncodingException {
EntityBareJid authzid = null;
if (useAuthzid) {
authzid = JidCreate.entityBareFrom("shazbat@xmpp.org");
}
saslMechanism.authenticate("florian", "irrelevant", JidCreate.domainBareFrom("xmpp.org"), "secret", authzid, null);
byte[] response = saslMechanism.evaluateChallenge(challengeBytes);
- String responseString = new String(response);
+ String responseString = new String(response, StringUtils.UTF8);
String[] responseParts = responseString.split(",");
Map responsePairs = new HashMap();
for (String part : responseParts) {
diff --git a/smack-core/src/test/java/org/jivesoftware/smack/util/PacketParserUtilsTest.java b/smack-core/src/test/java/org/jivesoftware/smack/util/PacketParserUtilsTest.java
index e24196d15..b988a3e3a 100644
--- a/smack-core/src/test/java/org/jivesoftware/smack/util/PacketParserUtilsTest.java
+++ b/smack-core/src/test/java/org/jivesoftware/smack/util/PacketParserUtilsTest.java
@@ -710,8 +710,8 @@ public class PacketParserUtilsTest {
try {
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
fail("Exception should be thrown");
- } catch(IllegalStateException e) {
- assertTrue(e.getMessage().contains("Invalid Stanza"));
+ } catch(XmlPullParserException e) {
+ assertTrue(e.getMessage().contains("end tag name