From ba323b51f97fdb70973837357102fe45fdc55a85 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 16 Aug 2017 14:31:46 +0200 Subject: [PATCH] Remove API parts scheduled to be removed in Smack 4.3 --- .../smack/AbstractXMPPConnection.java | 40 -------------- .../smack/SmackConfiguration.java | 3 +- .../jivesoftware/smack/packet/XMPPError.java | 47 +--------------- .../jivesoftware/smack/util/StringUtils.java | 13 ----- .../jivesoftware/smackx/mam/MamManager.java | 17 ------ .../smackx/bytestreams/BytestreamManager.java | 2 +- .../ibb/InBandBytestreamManager.java | 4 +- .../socks5/Socks5BytestreamManager.java | 4 +- .../smackx/caps/EntityCapsManager.java | 4 +- .../smackx/commands/AdHocCommandManager.java | 55 +++++++++---------- .../smackx/commands/LocalCommandFactory.java | 8 ++- 11 files changed, 39 insertions(+), 158 deletions(-) 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 984f876a2..95eea00b6 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -963,52 +963,12 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { replyTimeout = timeout; } - /** - * Set the default value used to determine if new connection will reply to unknown IQ requests. The pre-configured - * default is 'true'. - * - * @param replyToUnkownIqDefault - * @see #setReplyToUnknownIq(boolean) - * @deprecated Use {@link SmackConfiguration#setUnknownIqRequestReplyMode(org.jivesoftware.smack.SmackConfiguration.UnknownIqRequestReplyMode)} instead. - */ - @Deprecated - // TODO Remove in Smack 4.3 - public static void setReplyToUnknownIqDefault(boolean replyToUnkownIqDefault) { - SmackConfiguration.UnknownIqRequestReplyMode mode; - if (replyToUnkownIqDefault) { - mode = SmackConfiguration.UnknownIqRequestReplyMode.replyServiceUnavailable; - } else { - mode = SmackConfiguration.UnknownIqRequestReplyMode.doNotReply; - } - SmackConfiguration.setUnknownIqRequestReplyMode(mode); - } - private SmackConfiguration.UnknownIqRequestReplyMode unknownIqRequestReplyMode = SmackConfiguration.getUnknownIqRequestReplyMode(); public void setUnknownIqRequestReplyMode(UnknownIqRequestReplyMode unknownIqRequestReplyMode) { this.unknownIqRequestReplyMode = Objects.requireNonNull(unknownIqRequestReplyMode, "Mode must not be null"); } - /** - * Set if Smack will automatically send - * {@link org.jivesoftware.smack.packet.XMPPError.Condition#feature_not_implemented} when a request IQ without a - * registered {@link IQRequestHandler} is received. - * - * @param replyToUnknownIq - * @deprecated use {@link #setUnknownIqRequestReplyMode(UnknownIqRequestReplyMode)} instead. - */ - @Deprecated - // TODO Remove in Smack 4.3 - public void setReplyToUnknownIq(boolean replyToUnknownIq) { - SmackConfiguration.UnknownIqRequestReplyMode mode; - if (replyToUnknownIq) { - mode = SmackConfiguration.UnknownIqRequestReplyMode.replyServiceUnavailable; - } else { - mode = SmackConfiguration.UnknownIqRequestReplyMode.doNotReply; - } - unknownIqRequestReplyMode = mode; - } - protected void parseAndProcessStanza(XmlPullParser parser) throws Exception { ParserUtils.assertAtStartTag(parser); int parserDepth = parser.getDepth(); diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java b/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java index 7bf89847f..179b73a7f 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java @@ -345,8 +345,7 @@ public final class SmackConfiguration { replyServiceUnavailable, } - // TODO Change to replyFeatureNotImplemented in Smack 4.3 - private static UnknownIqRequestReplyMode unknownIqRequestReplyMode = UnknownIqRequestReplyMode.replyServiceUnavailable; + private static UnknownIqRequestReplyMode unknownIqRequestReplyMode = UnknownIqRequestReplyMode.replyFeatureNotImplemented; public static UnknownIqRequestReplyMode getUnknownIqRequestReplyMode() { return unknownIqRequestReplyMode; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java index 3913fe374..4312bdb45 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java @@ -1,6 +1,6 @@ /** * - * Copyright 2003-2007 Jive Software, 2015 Florian Schmaus + * Copyright 2003-2007 Jive Software, 2015-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. @@ -16,7 +16,6 @@ */ package org.jivesoftware.smack.packet; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -102,50 +101,6 @@ public class XMPPError extends AbstractError { private final Type type; private final Stanza stanza; - // TODO: Deprecated constructors - // deprecate in 4.3 - - /** - * Create a new XMPPError. - * - * @param condition - * @deprecated use {@link Builder} instead. - */ - @Deprecated - public XMPPError(Condition condition) { - this(condition, null, null, null, null, null, null); - } - - /** - * Create a new XMPPError. - * - * @param condition - * @param applicationSpecificCondition - * @deprecated use {@link Builder} instead. - */ - @Deprecated - public XMPPError(Condition condition, ExtensionElement applicationSpecificCondition) { - this(condition, null, null, null, null, Arrays.asList(applicationSpecificCondition), null); - } - - /** - * Creates a new error with the specified type, condition and message. - * This constructor is used when the condition is not recognized automatically by XMPPError - * i.e. there is not a defined instance of ErrorCondition or it does not apply the default - * specification. - * - * @param type the error type. - * @param condition the error condition. - * @param descriptiveTexts - * @param extensions list of stanza(/packet) extensions - * @deprecated use {@link Builder} instead. - */ - @Deprecated - public XMPPError(Condition condition, String conditionText, String errorGenerator, Type type, Map descriptiveTexts, - List extensions) { - this(condition, conditionText, errorGenerator, type, descriptiveTexts, extensions, null); - } - /** * Creates a new error with the specified type, condition and message. * This constructor is used when the condition is not recognized automatically by XMPPError diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java index c2bb9210a..77dd81141 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/StringUtils.java @@ -41,19 +41,6 @@ public class StringUtils { public static final char[] HEX_CHARS = "0123456789abcdef".toCharArray(); - /** - * Escape input for XML. - * - * @param input the input to escape. - * @return the XML escaped variant of input. - * @deprecated use {@link #escapeForXml(CharSequence)} instead. - */ - // Remove in 4.3. - @Deprecated - public static CharSequence escapeForXML(CharSequence input) { - return escapeForXml(input); - } - /** * Escape input for XML. * diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java index 9d800f73c..d24772b0b 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java @@ -607,23 +607,6 @@ public final class MamManager extends Manager { return serviceDiscoveryManager.supportsFeature(myBareJid, MamElements.NAMESPACE); } - /** - * Returns true if Message Archive Management is supported by the server. - * - * @return true if Message Archive Management is supported by the server. - * @throws NotConnectedException - * @throws XMPPErrorException - * @throws NoResponseException - * @throws InterruptedException - * @depreacted use {@link #isSupported()} instead. - */ - @Deprecated - // TODO Remove in Smack 4.3 - public boolean isSupportedByServer() - throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { - return ServiceDiscoveryManager.getInstanceFor(connection()).serverSupportsFeature(MamElements.NAMESPACE); - } - private static DataForm getNewMamForm() { FormField field = new FormField(FormField.FORM_TYPE); field.setType(FormField.Type.hidden); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/BytestreamManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/BytestreamManager.java index 08318c6b2..302cef86e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/BytestreamManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/BytestreamManager.java @@ -75,7 +75,7 @@ public interface BytestreamManager { * * @param initiatorJID the JID of the user the listener should be removed */ - public void removeIncomingBytestreamListener(String initiatorJID); + public void removeIncomingBytestreamListener(Jid initiatorJID); /** * Establishes a bytestream with the given user and returns the session to send/receive data diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java index 5e7f99d45..3b0be019c 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java @@ -282,9 +282,7 @@ public final class InBandBytestreamManager extends Manager implements Bytestream * @param initiatorJID the JID of the user the listener should be removed */ @Override - // TODO: Change argument to Jid in Smack 4.3. - @SuppressWarnings("CollectionIncompatibleType") - public void removeIncomingBytestreamListener(String initiatorJID) { + public void removeIncomingBytestreamListener(Jid initiatorJID) { this.userListeners.remove(initiatorJID); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java index 247e4de7e..258d6715b 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java @@ -245,10 +245,8 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream * * @param initiatorJID the JID of the user the listener should be removed */ - // TODO: Change parameter to Jid in Smack 4.3. @Override - @SuppressWarnings("CollectionIncompatibleType") - public void removeIncomingBytestreamListener(String initiatorJID) { + public void removeIncomingBytestreamListener(Jid initiatorJID) { this.userListeners.remove(initiatorJID); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java index b28eb5ff4..3a94a3e0f 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java @@ -408,9 +408,7 @@ public final class EntityCapsManager extends Manager { * @param user * the user (Full JID) */ - // TODO: Change parameter type to Jid in Smack 4.3. - @SuppressWarnings("CollectionIncompatibleType") - public static void removeUserCapsNode(String user) { + public static void removeUserCapsNode(Jid user) { // While JID_TO_NODEVER_CHACHE has the generic types , it is ok to call remove with String // arguments, since the same Jid and String representations would be equal and have the same hash code. JID_TO_NODEVER_CACHE.remove(user); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommandManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommandManager.java index 80f6a2a02..a63a17bcf 100755 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommandManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommandManager.java @@ -205,15 +205,8 @@ public final class AdHocCommandManager extends Manager { public void registerCommand(String node, String name, final Class clazz) { registerCommand(node, name, new LocalCommandFactory() { @Override - public LocalCommand getInstance() throws InstantiationException, IllegalAccessException { - try { - return clazz.getConstructor().newInstance(); - } - catch (IllegalArgumentException | InvocationTargetException | NoSuchMethodException - | SecurityException e) { - // TODO: Throw those method in Smack 4.3. - throw new IllegalStateException(e); - } + public LocalCommand getInstance() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + return clazz.getConstructor().newInstance(); } }); } @@ -361,7 +354,15 @@ public final class AdHocCommandManager extends Manager { try { // Create a new instance of the command with the // corresponding sessioid - LocalCommand command = newInstanceOfCmd(commandNode, sessionId); + LocalCommand command; + try { + command = newInstanceOfCmd(commandNode, sessionId); + } + catch (InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException | NoSuchMethodException | SecurityException e) { + XMPPError.Builder xmppError = XMPPError.getBuilder().setCondition(XMPPError.Condition.internal_server_error).setDescriptiveEnText(e.getMessage()); + return respondError(response, xmppError); + } response.setType(IQ.Type.result); command.setData(response); @@ -627,26 +628,22 @@ public final class AdHocCommandManager extends Manager { * @param sessionID the session id of this execution. * @return the command instance to execute. * @throws XMPPErrorException if there is problem creating the new instance. + * @throws SecurityException + * @throws NoSuchMethodException + * @throws InvocationTargetException + * @throws IllegalArgumentException + * @throws IllegalAccessException + * @throws InstantiationException */ - @SuppressWarnings("deprecation") - private LocalCommand newInstanceOfCmd(String commandNode, String sessionID) throws XMPPErrorException - { + private LocalCommand newInstanceOfCmd(String commandNode, String sessionID) + throws XMPPErrorException, InstantiationException, IllegalAccessException, IllegalArgumentException, + InvocationTargetException, NoSuchMethodException, SecurityException { AdHocCommandInfo commandInfo = commands.get(commandNode); - LocalCommand command; - try { - command = commandInfo.getCommandInstance(); - command.setSessionID(sessionID); - command.setName(commandInfo.getName()); - command.setNode(commandInfo.getNode()); - } - catch (InstantiationException e) { - throw new XMPPErrorException(XMPPError.getBuilder( - XMPPError.Condition.internal_server_error)); - } - catch (IllegalAccessException e) { - throw new XMPPErrorException(XMPPError.getBuilder( - XMPPError.Condition.internal_server_error)); - } + LocalCommand command = commandInfo.getCommandInstance(); + command.setSessionID(sessionID); + command.setName(commandInfo.getName()); + command.setNode(commandInfo.getNode()); + return command; } @@ -680,7 +677,7 @@ public final class AdHocCommandManager extends Manager { } public LocalCommand getCommandInstance() throws InstantiationException, - IllegalAccessException + IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { return factory.getInstance(); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/LocalCommandFactory.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/LocalCommandFactory.java index aabf5b490..d8248e0ef 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/LocalCommandFactory.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/commands/LocalCommandFactory.java @@ -16,6 +16,8 @@ */ package org.jivesoftware.smackx.commands; +import java.lang.reflect.InvocationTargetException; + /** * A factory for creating local commands. It's useful in cases where instantiation * of a command is more complicated than just using the default constructor. For example, @@ -34,7 +36,11 @@ public interface LocalCommandFactory { * @return a LocalCommand instance. * @throws InstantiationException if creating an instance failed. * @throws IllegalAccessException if creating an instance is not allowed. + * @throws SecurityException + * @throws NoSuchMethodException + * @throws InvocationTargetException + * @throws IllegalArgumentException */ - public LocalCommand getInstance() throws InstantiationException, IllegalAccessException; + public LocalCommand getInstance() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException; }