mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-10 17:49:38 +02:00
Expose InterruptedException
SMACK-632
This commit is contained in:
parent
43b99a2a85
commit
bc61527bd2
124 changed files with 977 additions and 597 deletions
|
@ -362,10 +362,10 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
@Override
|
||||
public abstract boolean isSecureConnection();
|
||||
|
||||
protected abstract void sendPacketInternal(Stanza packet) throws NotConnectedException;
|
||||
protected abstract void sendPacketInternal(Stanza packet) throws NotConnectedException, InterruptedException;
|
||||
|
||||
@Override
|
||||
public abstract void send(PlainStreamElement element) throws NotConnectedException;
|
||||
public abstract void send(PlainStreamElement element) throws NotConnectedException, InterruptedException;
|
||||
|
||||
@Override
|
||||
public abstract boolean isUsingCompression();
|
||||
|
@ -382,8 +382,9 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
* @throws IOException
|
||||
* @throws ConnectionException with detailed information about the failed connection.
|
||||
* @return a reference to this object, to chain <code>connect()</code> with <code>login()</code>.
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public synchronized AbstractXMPPConnection connect() throws SmackException, IOException, XMPPException {
|
||||
public synchronized AbstractXMPPConnection connect() throws SmackException, IOException, XMPPException, InterruptedException {
|
||||
// Check if not already connected
|
||||
throwAlreadyConnectedExceptionIfAppropriate();
|
||||
|
||||
|
@ -406,8 +407,9 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
* @throws SmackException
|
||||
* @throws IOException
|
||||
* @throws XMPPException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
protected abstract void connectInternal() throws SmackException, IOException, XMPPException;
|
||||
protected abstract void connectInternal() throws SmackException, IOException, XMPPException, InterruptedException;
|
||||
|
||||
private String usedUsername, usedPassword, usedResource;
|
||||
|
||||
|
@ -432,8 +434,9 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
* @throws XMPPException if an error occurs on the XMPP protocol level.
|
||||
* @throws SmackException if an error occurs somewhere else besides XMPP protocol level.
|
||||
* @throws IOException if an I/O error occurs during login.
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public synchronized void login() throws XMPPException, SmackException, IOException {
|
||||
public synchronized void login() throws XMPPException, SmackException, IOException, InterruptedException {
|
||||
if (isAnonymous()) {
|
||||
throwNotConnectedExceptionIfAppropriate();
|
||||
throwAlreadyLoggedInExceptionIfAppropriate();
|
||||
|
@ -457,10 +460,11 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
* @throws XMPPException
|
||||
* @throws SmackException
|
||||
* @throws IOException
|
||||
* @throws InterruptedException
|
||||
* @see #login
|
||||
*/
|
||||
public synchronized void login(CharSequence username, String password) throws XMPPException, SmackException,
|
||||
IOException {
|
||||
IOException, InterruptedException {
|
||||
login(username, password, config.getResource());
|
||||
}
|
||||
|
||||
|
@ -474,10 +478,11 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
* @throws XMPPException
|
||||
* @throws SmackException
|
||||
* @throws IOException
|
||||
* @throws InterruptedException
|
||||
* @see #login
|
||||
*/
|
||||
public synchronized void login(CharSequence username, String password, String resource) throws XMPPException,
|
||||
SmackException, IOException {
|
||||
SmackException, IOException, InterruptedException {
|
||||
if (!config.allowNullOrEmptyUsername) {
|
||||
StringUtils.requireNotNullOrEmpty(username, "Username must not be null or empty");
|
||||
}
|
||||
|
@ -490,9 +495,9 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
}
|
||||
|
||||
protected abstract void loginNonAnonymously(String username, String password, String resource)
|
||||
throws XMPPException, SmackException, IOException;
|
||||
throws XMPPException, SmackException, IOException, InterruptedException;
|
||||
|
||||
protected abstract void loginAnonymously() throws XMPPException, SmackException, IOException;
|
||||
protected abstract void loginAnonymously() throws XMPPException, SmackException, IOException, InterruptedException;
|
||||
|
||||
@Override
|
||||
public final boolean isConnected() {
|
||||
|
@ -520,7 +525,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
// TODO remove this suppression once "disable legacy session" code has been removed from Smack
|
||||
@SuppressWarnings("deprecation")
|
||||
protected void bindResourceAndEstablishSession(String resource) throws XMPPErrorException,
|
||||
IOException, SmackException {
|
||||
IOException, SmackException, InterruptedException {
|
||||
|
||||
// Wait until either:
|
||||
// - the servers last features stanza has been parsed
|
||||
|
@ -557,7 +562,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
}
|
||||
}
|
||||
|
||||
protected void afterSuccessfulLogin(final boolean resumed) throws NotConnectedException {
|
||||
protected void afterSuccessfulLogin(final boolean resumed) throws NotConnectedException, InterruptedException {
|
||||
// Indicate that we're now authenticated.
|
||||
this.authenticated = true;
|
||||
|
||||
|
@ -634,7 +639,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(Stanza packet) throws NotConnectedException {
|
||||
public void sendPacket(Stanza packet) throws NotConnectedException, InterruptedException {
|
||||
Objects.requireNonNull(packet, "Packet must not be null");
|
||||
|
||||
throwNotConnectedExceptionIfAppropriate();
|
||||
|
@ -693,7 +698,12 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
* @throws NotConnectedException
|
||||
*/
|
||||
public synchronized void disconnect(Presence unavailablePresence) throws NotConnectedException {
|
||||
sendPacket(unavailablePresence);
|
||||
try {
|
||||
sendPacket(unavailablePresence);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
LOGGER.log(Level.FINE, "Was interrupted while sending unavailable presence. Continuing to disconnect the connection", e);
|
||||
}
|
||||
shutdown();
|
||||
callConnectionClosedListener();
|
||||
}
|
||||
|
@ -717,7 +727,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
}
|
||||
|
||||
@Override
|
||||
public PacketCollector createPacketCollectorAndSend(IQ packet) throws NotConnectedException {
|
||||
public PacketCollector createPacketCollectorAndSend(IQ packet) throws NotConnectedException, InterruptedException {
|
||||
PacketFilter packetFilter = new IQReplyFilter(packet, this);
|
||||
// Create the packet collector before sending the packet
|
||||
PacketCollector packetCollector = createPacketCollectorAndSend(packetFilter, packet);
|
||||
|
@ -726,14 +736,14 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
|
||||
@Override
|
||||
public PacketCollector createPacketCollectorAndSend(PacketFilter packetFilter, Stanza packet)
|
||||
throws NotConnectedException {
|
||||
throws NotConnectedException, InterruptedException {
|
||||
// Create the packet collector before sending the packet
|
||||
PacketCollector packetCollector = createPacketCollector(packetFilter);
|
||||
try {
|
||||
// Now we can send the packet as the collector has been created
|
||||
sendPacket(packet);
|
||||
}
|
||||
catch (NotConnectedException | RuntimeException e) {
|
||||
catch (InterruptedException | NotConnectedException | RuntimeException e) {
|
||||
packetCollector.cancel();
|
||||
throw e;
|
||||
}
|
||||
|
@ -1062,8 +1072,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
try {
|
||||
sendPacket(errorIQ);
|
||||
}
|
||||
catch (NotConnectedException e) {
|
||||
LOGGER.log(Level.WARNING, "NotConnectedException while sending error IQ to unkown IQ request", e);
|
||||
catch (InterruptedException | NotConnectedException e) {
|
||||
LOGGER.log(Level.WARNING, "Exception while sending error IQ to unkown IQ request", e);
|
||||
}
|
||||
} else {
|
||||
ExecutorService executorService = null;
|
||||
|
@ -1091,8 +1101,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
try {
|
||||
sendPacket(response);
|
||||
}
|
||||
catch (NotConnectedException e) {
|
||||
LOGGER.log(Level.WARNING, "NotConnectedException while sending response to IQ request", e);
|
||||
catch (InterruptedException | NotConnectedException e) {
|
||||
LOGGER.log(Level.WARNING, "Exception while sending response to IQ request", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1334,7 +1344,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
}
|
||||
|
||||
protected final void parseFeatures(XmlPullParser parser) throws XmlPullParserException,
|
||||
IOException, SmackException {
|
||||
IOException, SmackException, InterruptedException {
|
||||
streamFeatures.clear();
|
||||
final int initialDepth = parser.getDepth();
|
||||
while (true) {
|
||||
|
@ -1397,7 +1407,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
afterFeaturesReceived();
|
||||
}
|
||||
|
||||
protected void afterFeaturesReceived() throws SecurityRequiredException, NotConnectedException {
|
||||
protected void afterFeaturesReceived() throws SecurityRequiredException, NotConnectedException, InterruptedException {
|
||||
// Default implementation does nothing
|
||||
}
|
||||
|
||||
|
@ -1419,14 +1429,14 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
|
||||
@Override
|
||||
public void sendStanzaWithResponseCallback(Stanza stanza, PacketFilter replyFilter,
|
||||
PacketListener callback) throws NotConnectedException {
|
||||
PacketListener callback) throws NotConnectedException, InterruptedException {
|
||||
sendStanzaWithResponseCallback(stanza, replyFilter, callback, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStanzaWithResponseCallback(Stanza stanza, PacketFilter replyFilter,
|
||||
PacketListener callback, ExceptionCallback exceptionCallback)
|
||||
throws NotConnectedException {
|
||||
throws NotConnectedException, InterruptedException {
|
||||
sendStanzaWithResponseCallback(stanza, replyFilter, callback, exceptionCallback,
|
||||
getPacketReplyTimeout());
|
||||
}
|
||||
|
@ -1434,7 +1444,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
@Override
|
||||
public void sendStanzaWithResponseCallback(Stanza stanza, PacketFilter replyFilter,
|
||||
final PacketListener callback, final ExceptionCallback exceptionCallback,
|
||||
long timeout) throws NotConnectedException {
|
||||
long timeout) throws NotConnectedException, InterruptedException {
|
||||
Objects.requireNonNull(stanza, "stanza must not be null");
|
||||
// While Smack allows to add PacketListeners with a PacketFilter value of 'null', we
|
||||
// disallow it here in the async API as it makes no sense
|
||||
|
@ -1443,7 +1453,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
|
||||
final PacketListener packetListener = new PacketListener() {
|
||||
@Override
|
||||
public void processPacket(Stanza packet) throws NotConnectedException {
|
||||
public void processPacket(Stanza packet) throws NotConnectedException, InterruptedException {
|
||||
try {
|
||||
XMPPErrorException.ifHasErrorThenThrow(packet);
|
||||
callback.processPacket(packet);
|
||||
|
@ -1475,20 +1485,20 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
|
||||
@Override
|
||||
public void sendIqWithResponseCallback(IQ iqRequest, PacketListener callback)
|
||||
throws NotConnectedException {
|
||||
throws NotConnectedException, InterruptedException {
|
||||
sendIqWithResponseCallback(iqRequest, callback, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendIqWithResponseCallback(IQ iqRequest, PacketListener callback,
|
||||
ExceptionCallback exceptionCallback) throws NotConnectedException {
|
||||
ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException {
|
||||
sendIqWithResponseCallback(iqRequest, callback, exceptionCallback, getPacketReplyTimeout());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendIqWithResponseCallback(IQ iqRequest, final PacketListener callback,
|
||||
final ExceptionCallback exceptionCallback, long timeout)
|
||||
throws NotConnectedException {
|
||||
throws NotConnectedException, InterruptedException {
|
||||
PacketFilter replyFilter = new IQReplyFilter(iqRequest, this);
|
||||
sendStanzaWithResponseCallback(iqRequest, replyFilter, callback, exceptionCallback, timeout);
|
||||
}
|
||||
|
@ -1497,7 +1507,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
public void addOneTimeSyncCallback(final PacketListener callback, final PacketFilter packetFilter) {
|
||||
final PacketListener packetListener = new PacketListener() {
|
||||
@Override
|
||||
public void processPacket(Stanza packet) throws NotConnectedException {
|
||||
public void processPacket(Stanza packet) throws NotConnectedException, InterruptedException {
|
||||
try {
|
||||
callback.processPacket(packet);
|
||||
} finally {
|
||||
|
|
|
@ -19,8 +19,6 @@ package org.jivesoftware.smack;
|
|||
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
|
@ -43,8 +41,6 @@ import org.jivesoftware.smack.packet.Stanza;
|
|||
*/
|
||||
public class PacketCollector {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(PacketCollector.class.getName());
|
||||
|
||||
private final PacketFilter packetFilter;
|
||||
private final ArrayBlockingQueue<Stanza> resultQueue;
|
||||
|
||||
|
@ -131,18 +127,14 @@ public class PacketCollector {
|
|||
* available.
|
||||
*
|
||||
* @return the next available packet.
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <P extends Stanza> P nextResultBlockForever() {
|
||||
public <P extends Stanza> P nextResultBlockForever() throws InterruptedException {
|
||||
throwIfCancelled();
|
||||
P res = null;
|
||||
while (res == null) {
|
||||
try {
|
||||
res = (P) resultQueue.take();
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.log(Level.FINE,
|
||||
"nextResultBlockForever was interrupted", e);
|
||||
}
|
||||
res = (P) resultQueue.take();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -152,8 +144,9 @@ public class PacketCollector {
|
|||
* timeout has elapsed.
|
||||
*
|
||||
* @return the next available packet.
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public <P extends Stanza> P nextResult() {
|
||||
public <P extends Stanza> P nextResult() throws InterruptedException {
|
||||
return nextResult(connection.getPacketReplyTimeout());
|
||||
}
|
||||
|
||||
|
@ -166,20 +159,16 @@ public class PacketCollector {
|
|||
*
|
||||
* @param timeout the timeout in milliseconds.
|
||||
* @return the next available packet.
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <P extends Stanza> P nextResult(long timeout) {
|
||||
public <P extends Stanza> P nextResult(long timeout) throws InterruptedException {
|
||||
throwIfCancelled();
|
||||
P res = null;
|
||||
long remainingWait = timeout;
|
||||
waitStart = System.currentTimeMillis();
|
||||
do {
|
||||
try {
|
||||
res = (P) resultQueue.poll(remainingWait, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
LOGGER.log(Level.FINE, "nextResult was interrupted", e);
|
||||
}
|
||||
res = (P) resultQueue.poll(remainingWait, TimeUnit.MILLISECONDS);
|
||||
if (res != null) {
|
||||
return res;
|
||||
}
|
||||
|
@ -196,8 +185,9 @@ public class PacketCollector {
|
|||
* @return the next available packet.
|
||||
* @throws XMPPErrorException in case an error response.
|
||||
* @throws NoResponseException if there was no response from the server.
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public <P extends Stanza> P nextResultOrThrow() throws NoResponseException, XMPPErrorException {
|
||||
public <P extends Stanza> P nextResultOrThrow() throws NoResponseException, XMPPErrorException, InterruptedException {
|
||||
return nextResultOrThrow(connection.getPacketReplyTimeout());
|
||||
}
|
||||
|
||||
|
@ -209,8 +199,9 @@ public class PacketCollector {
|
|||
* @return the next available packet.
|
||||
* @throws NoResponseException if there was no response from the server.
|
||||
* @throws XMPPErrorException in case an error response.
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public <P extends Stanza> P nextResultOrThrow(long timeout) throws NoResponseException, XMPPErrorException {
|
||||
public <P extends Stanza> P nextResultOrThrow(long timeout) throws NoResponseException, XMPPErrorException, InterruptedException {
|
||||
P result = nextResult(timeout);
|
||||
cancel();
|
||||
if (result == null) {
|
||||
|
|
|
@ -47,7 +47,8 @@ public interface PacketListener {
|
|||
* </p>
|
||||
*
|
||||
* @param packet the packet to process.
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void processPacket(Stanza packet) throws NotConnectedException;
|
||||
public void processPacket(Stanza packet) throws NotConnectedException, InterruptedException;
|
||||
|
||||
}
|
||||
|
|
|
@ -180,21 +180,17 @@ public class SASLAuthentication {
|
|||
* @throws XMPPErrorException
|
||||
* @throws SASLErrorException
|
||||
* @throws SmackException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void authenticate(String resource, CallbackHandler cbh) throws IOException,
|
||||
XMPPErrorException, SASLErrorException, SmackException {
|
||||
XMPPErrorException, SASLErrorException, SmackException, InterruptedException {
|
||||
SASLMechanism selectedMechanism = selectMechanism();
|
||||
if (selectedMechanism != null) {
|
||||
currentMechanism = selectedMechanism;
|
||||
synchronized (this) {
|
||||
currentMechanism.authenticate(connection.getHost(), connection.getServiceName(), cbh);
|
||||
try {
|
||||
// Wait until SASL negotiation finishes
|
||||
wait(connection.getPacketReplyTimeout());
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
// Ignore
|
||||
}
|
||||
// Wait until SASL negotiation finishes
|
||||
wait(connection.getPacketReplyTimeout());
|
||||
}
|
||||
|
||||
maybeThrowException();
|
||||
|
@ -224,10 +220,11 @@ public class SASLAuthentication {
|
|||
* @throws SASLErrorException
|
||||
* @throws IOException
|
||||
* @throws SmackException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void authenticate(String username, String password, String resource)
|
||||
throws XMPPErrorException, SASLErrorException, IOException,
|
||||
SmackException {
|
||||
SmackException, InterruptedException {
|
||||
SASLMechanism selectedMechanism = selectMechanism();
|
||||
if (selectedMechanism != null) {
|
||||
currentMechanism = selectedMechanism;
|
||||
|
@ -235,13 +232,8 @@ public class SASLAuthentication {
|
|||
synchronized (this) {
|
||||
currentMechanism.authenticate(username, connection.getHost(),
|
||||
connection.getServiceName(), password);
|
||||
try {
|
||||
// Wait until SASL negotiation finishes
|
||||
wait(connection.getPacketReplyTimeout());
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
// Ignore
|
||||
}
|
||||
// Wait until SASL negotiation finishes
|
||||
wait(connection.getPacketReplyTimeout());
|
||||
}
|
||||
|
||||
maybeThrowException();
|
||||
|
@ -267,20 +259,16 @@ public class SASLAuthentication {
|
|||
* @throws SASLErrorException
|
||||
* @throws XMPPErrorException if an error occures while authenticating.
|
||||
* @throws SmackException if there was no response from the server.
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void authenticateAnonymously() throws SASLErrorException,
|
||||
SmackException, XMPPErrorException {
|
||||
SmackException, XMPPErrorException, InterruptedException {
|
||||
currentMechanism = (new SASLAnonymous()).instanceForAuthentication(connection);
|
||||
|
||||
// Wait until SASL negotiation finishes
|
||||
synchronized (this) {
|
||||
currentMechanism.authenticate(null, null, null, "");
|
||||
try {
|
||||
wait(connection.getPacketReplyTimeout());
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
// Ignore
|
||||
}
|
||||
wait(connection.getPacketReplyTimeout());
|
||||
}
|
||||
|
||||
maybeThrowException();
|
||||
|
@ -308,8 +296,9 @@ public class SASLAuthentication {
|
|||
*
|
||||
* @param challenge a base64 encoded string representing the challenge.
|
||||
* @throws SmackException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void challengeReceived(String challenge) throws SmackException {
|
||||
public void challengeReceived(String challenge) throws SmackException, InterruptedException {
|
||||
challengeReceived(challenge, false);
|
||||
}
|
||||
|
||||
|
@ -322,11 +311,12 @@ public class SASLAuthentication {
|
|||
* @param challenge a base64 encoded string representing the challenge.
|
||||
* @param finalChallenge true if this is the last challenge send by the server within the success stanza
|
||||
* @throws SmackException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void challengeReceived(String challenge, boolean finalChallenge) throws SmackException {
|
||||
public void challengeReceived(String challenge, boolean finalChallenge) throws SmackException, InterruptedException {
|
||||
try {
|
||||
currentMechanism.challengeReceived(challenge, finalChallenge);
|
||||
} catch (SmackException e) {
|
||||
} catch (InterruptedException | SmackException e) {
|
||||
authenticationFailed(e);
|
||||
throw e;
|
||||
}
|
||||
|
@ -336,8 +326,9 @@ public class SASLAuthentication {
|
|||
* Notification message saying that SASL authentication was successful. The next step
|
||||
* would be to bind the resource.
|
||||
* @throws SmackException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void authenticated(Success success) throws SmackException {
|
||||
public void authenticated(Success success) throws SmackException, InterruptedException {
|
||||
// RFC6120 6.3.10 "At the end of the authentication exchange, the SASL server (the XMPP
|
||||
// "receiving entity") can include "additional data with success" if appropriate for the
|
||||
// SASL mechanism in use. In XMPP, this is done by including the additional data as the XML
|
||||
|
|
|
@ -56,7 +56,7 @@ public class SynchronizationPoint<E extends Exception> {
|
|||
}
|
||||
|
||||
public void sendAndWaitForResponse(TopLevelStreamElement request) throws NoResponseException,
|
||||
NotConnectedException {
|
||||
NotConnectedException, InterruptedException {
|
||||
assert (state == State.Initial);
|
||||
connectionLock.lock();
|
||||
try {
|
||||
|
@ -80,7 +80,7 @@ public class SynchronizationPoint<E extends Exception> {
|
|||
}
|
||||
|
||||
public void sendAndWaitForResponseOrThrow(PlainStreamElement request) throws E, NoResponseException,
|
||||
NotConnectedException {
|
||||
NotConnectedException, InterruptedException {
|
||||
sendAndWaitForResponse(request);
|
||||
switch (state) {
|
||||
case Failure:
|
||||
|
@ -172,6 +172,7 @@ public class SynchronizationPoint<E extends Exception> {
|
|||
break;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// This InterruptedException could be "spurious wakeups", see javadoc of awaitNanos()
|
||||
LOGGER.log(Level.WARNING, "Thread interrupt while waiting for condition or timeout ignored", e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,8 +158,9 @@ public interface XMPPConnection {
|
|||
*
|
||||
* @param packet the packet to send.
|
||||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void sendPacket(Stanza packet) throws NotConnectedException;
|
||||
public void sendPacket(Stanza packet) throws NotConnectedException, InterruptedException;
|
||||
|
||||
/**
|
||||
* Send a PlainStreamElement.
|
||||
|
@ -171,8 +172,9 @@ public interface XMPPConnection {
|
|||
*
|
||||
* @param element
|
||||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void send(PlainStreamElement element) throws NotConnectedException;
|
||||
public void send(PlainStreamElement element) throws NotConnectedException, InterruptedException;
|
||||
|
||||
/**
|
||||
* Adds a connection listener to this connection that will be notified when
|
||||
|
@ -198,8 +200,9 @@ public interface XMPPConnection {
|
|||
* @param packet the packet to filter responses from
|
||||
* @return a new packet collector.
|
||||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public PacketCollector createPacketCollectorAndSend(IQ packet) throws NotConnectedException;
|
||||
public PacketCollector createPacketCollectorAndSend(IQ packet) throws NotConnectedException, InterruptedException;
|
||||
|
||||
/**
|
||||
* Creates a new packet collector for this connection. A packet filter determines
|
||||
|
@ -210,9 +213,11 @@ public interface XMPPConnection {
|
|||
* @param packetFilter the packet filter to use.
|
||||
* @param packet the packet to send right after the collector got created
|
||||
* @return a new packet collector.
|
||||
* @throws InterruptedException
|
||||
* @throws NotConnectedException
|
||||
*/
|
||||
public PacketCollector createPacketCollectorAndSend(PacketFilter packetFilter, Stanza packet)
|
||||
throws NotConnectedException;
|
||||
throws NotConnectedException, InterruptedException;
|
||||
|
||||
/**
|
||||
* Creates a new packet collector for this connection. A packet filter
|
||||
|
@ -462,9 +467,10 @@ public interface XMPPConnection {
|
|||
* @param replyFilter the filter used to determine response stanza (required)
|
||||
* @param callback the callback invoked if there is a response (required)
|
||||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void sendStanzaWithResponseCallback(Stanza stanza, PacketFilter replyFilter,
|
||||
PacketListener callback) throws NotConnectedException;
|
||||
PacketListener callback) throws NotConnectedException, InterruptedException;
|
||||
|
||||
/**
|
||||
* Send a stanza and wait asynchronously for a response by using <code>replyFilter</code>.
|
||||
|
@ -479,9 +485,10 @@ public interface XMPPConnection {
|
|||
* @param callback the callback invoked if there is a response (required)
|
||||
* @param exceptionCallback the callback invoked if there is an exception (optional)
|
||||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void sendStanzaWithResponseCallback(Stanza stanza, PacketFilter replyFilter, PacketListener callback,
|
||||
ExceptionCallback exceptionCallback) throws NotConnectedException;
|
||||
ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException;
|
||||
|
||||
/**
|
||||
* Send a stanza and wait asynchronously for a response by using <code>replyFilter</code>.
|
||||
|
@ -497,10 +504,11 @@ public interface XMPPConnection {
|
|||
* @param exceptionCallback the callback invoked if there is an exception (optional)
|
||||
* @param timeout the timeout in milliseconds to wait for a response
|
||||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void sendStanzaWithResponseCallback(Stanza stanza, PacketFilter replyFilter,
|
||||
final PacketListener callback, final ExceptionCallback exceptionCallback,
|
||||
long timeout) throws NotConnectedException;
|
||||
long timeout) throws NotConnectedException, InterruptedException;
|
||||
|
||||
/**
|
||||
* Send a IQ stanza and invoke <code>callback</code> if there is a result of
|
||||
|
@ -510,8 +518,9 @@ public interface XMPPConnection {
|
|||
* @param iqRequest the IQ stanza to send (required)
|
||||
* @param callback the callback invoked if there is result response (required)
|
||||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void sendIqWithResponseCallback(IQ iqRequest, PacketListener callback) throws NotConnectedException;
|
||||
public void sendIqWithResponseCallback(IQ iqRequest, PacketListener callback) throws NotConnectedException, InterruptedException;
|
||||
|
||||
/**
|
||||
* Send a IQ stanza and invoke <code>callback</code> if there is a result of
|
||||
|
@ -525,9 +534,10 @@ public interface XMPPConnection {
|
|||
* @param callback the callback invoked if there is result response (required)
|
||||
* @param exceptionCallback the callback invoked if there is an Exception optional
|
||||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void sendIqWithResponseCallback(IQ iqRequest, PacketListener callback,
|
||||
ExceptionCallback exceptionCallback) throws NotConnectedException;
|
||||
ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException;
|
||||
|
||||
/**
|
||||
* Send a IQ stanza and invoke <code>callback</code> if there is a result of
|
||||
|
@ -542,10 +552,11 @@ public interface XMPPConnection {
|
|||
* @param exceptionCallback the callback invoked if there is an Exception optional
|
||||
* @param timeout the timeout in milliseconds to wait for a response
|
||||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void sendIqWithResponseCallback(IQ iqRequest, final PacketListener callback,
|
||||
final ExceptionCallback exceptionCallback, long timeout)
|
||||
throws NotConnectedException;
|
||||
throws NotConnectedException, InterruptedException;
|
||||
|
||||
/**
|
||||
* Add a callback that is called exactly once and synchronously with the incoming stanza that matches the given
|
||||
|
|
|
@ -158,9 +158,10 @@ public abstract class SASLMechanism implements Comparable<SASLMechanism> {
|
|||
* @param password the password for this account.
|
||||
* @throws SmackException If a network error occurs while authenticating.
|
||||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public final void authenticate(String username, String host, String serviceName, String password)
|
||||
throws SmackException, NotConnectedException {
|
||||
throws SmackException, NotConnectedException, InterruptedException {
|
||||
this.authenticationId = username;
|
||||
this.host = host;
|
||||
this.serviceName = serviceName;
|
||||
|
@ -181,9 +182,10 @@ public abstract class SASLMechanism implements Comparable<SASLMechanism> {
|
|||
* @param cbh the CallbackHandler to obtain user information.
|
||||
* @throws SmackException
|
||||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void authenticate(String host,String serviceName, CallbackHandler cbh)
|
||||
throws SmackException, NotConnectedException {
|
||||
throws SmackException, NotConnectedException, InterruptedException {
|
||||
this.host = host;
|
||||
this.serviceName = serviceName;
|
||||
authenticateInternal(cbh);
|
||||
|
@ -192,7 +194,7 @@ public abstract class SASLMechanism implements Comparable<SASLMechanism> {
|
|||
|
||||
protected abstract void authenticateInternal(CallbackHandler cbh) throws SmackException;
|
||||
|
||||
private final void authenticate() throws SmackException, NotConnectedException {
|
||||
private final void authenticate() throws SmackException, NotConnectedException, InterruptedException {
|
||||
byte[] authenticationBytes = getAuthenticationText();
|
||||
String authenticationText;
|
||||
if (authenticationBytes != null) {
|
||||
|
@ -224,8 +226,9 @@ public abstract class SASLMechanism implements Comparable<SASLMechanism> {
|
|||
* @param finalChallenge true if this is the last challenge send by the server within the success stanza
|
||||
* @throws NotConnectedException
|
||||
* @throws SmackException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public final void challengeReceived(String challengeString, boolean finalChallenge) throws SmackException, NotConnectedException {
|
||||
public final void challengeReceived(String challengeString, boolean finalChallenge) throws SmackException, NotConnectedException, InterruptedException {
|
||||
byte[] challenge = Base64.decode(challengeString);
|
||||
byte[] response = evaluateChallenge(challenge);
|
||||
if (finalChallenge) {
|
||||
|
|
|
@ -226,7 +226,21 @@ public class ArrayBlockingQueueWithShutdown<E> extends AbstractQueue<E> implemen
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Inserts the specified element into this queue, waiting if necessary
|
||||
* for space to become available.
|
||||
* <p>
|
||||
* This may throw an {@link InterruptedException} in two cases
|
||||
* <ol>
|
||||
* <li>If the queue was shut down.</li>
|
||||
* <li>If the thread was was interrupted.</li>
|
||||
* </ol>
|
||||
* So you have to check which is the case, e.g. by calling {@link #isShutdown()}.
|
||||
* </p>
|
||||
*
|
||||
* @param e the element to add.
|
||||
* @throws InterruptedException if interrupted while waiting or if the queue was shut down.
|
||||
*/
|
||||
public void put(E e) throws InterruptedException {
|
||||
checkNotNull(e);
|
||||
lock.lockInterruptibly();
|
||||
|
|
|
@ -198,7 +198,7 @@ public class DummyConnection extends AbstractXMPPConnection {
|
|||
dummyConnection.connect();
|
||||
dummyConnection.login();
|
||||
}
|
||||
catch (SmackException | IOException | XMPPException e) {
|
||||
catch (InterruptedException | SmackException | IOException | XMPPException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
return dummyConnection;
|
||||
|
|
|
@ -27,7 +27,7 @@ public class PacketCollectorTest
|
|||
{
|
||||
|
||||
@Test
|
||||
public void verifyRollover()
|
||||
public void verifyRollover() throws InterruptedException
|
||||
{
|
||||
TestPacketCollector collector = new TestPacketCollector(null, new OKEverything(), 5);
|
||||
|
||||
|
@ -92,13 +92,9 @@ public class PacketCollectorTest
|
|||
// System.out.println(Thread.currentThread().getName() + " packet: " + packet);
|
||||
}
|
||||
}
|
||||
catch (RuntimeException re)
|
||||
{
|
||||
if (re.getCause() instanceof InterruptedException)
|
||||
{
|
||||
// System.out.println(Thread.currentThread().getName() + " has been interupted");
|
||||
}
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
consumer1.setName("consumer 1");
|
||||
|
@ -119,7 +115,12 @@ public class PacketCollectorTest
|
|||
catch (InterruptedException e)
|
||||
{
|
||||
}
|
||||
p = collector.nextResult(1);
|
||||
try {
|
||||
p = collector.nextResult(1);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// System.out.println(Thread.currentThread().getName() + " packet: " + p);
|
||||
}
|
||||
while (p != null);
|
||||
|
|
|
@ -38,7 +38,7 @@ public class ThreadedDummyConnection extends DummyConnection {
|
|||
private volatile boolean timeout = false;
|
||||
|
||||
@Override
|
||||
public void sendPacket(Stanza packet) throws NotConnectedException {
|
||||
public void sendPacket(Stanza packet) throws NotConnectedException, InterruptedException {
|
||||
super.sendPacket(packet);
|
||||
|
||||
if (packet instanceof IQ && !timeout) {
|
||||
|
@ -102,7 +102,7 @@ public class ThreadedDummyConnection extends DummyConnection {
|
|||
}
|
||||
}
|
||||
|
||||
public static ThreadedDummyConnection newInstance() throws SmackException, IOException, XMPPException {
|
||||
public static ThreadedDummyConnection newInstance() throws SmackException, IOException, XMPPException, InterruptedException {
|
||||
ThreadedDummyConnection threadedDummyConnection = new ThreadedDummyConnection();
|
||||
threadedDummyConnection.connect();
|
||||
return threadedDummyConnection;
|
||||
|
|
|
@ -35,7 +35,7 @@ public class DigestMd5SaslTest extends AbstractSaslTest {
|
|||
super(saslMechanism);
|
||||
}
|
||||
|
||||
protected void runTest() throws NotConnectedException, SmackException {
|
||||
protected void runTest() throws NotConnectedException, SmackException, InterruptedException {
|
||||
saslMechanism.authenticate("florian", "irrelevant", "xmpp.org", "secret");
|
||||
|
||||
byte[] response = saslMechanism.evaluateChallenge(challengeBytes);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue