mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 17:19:39 +02:00
Make Provider.parse() just throw Exception
instead of throwing XmlPullParserException, IOException and SmackException. Add a guard to AbstractXMPPConnection.processPacket() to always re-throw RuntimeExceptions.
This commit is contained in:
parent
4d9bd6f216
commit
bc093b620d
29 changed files with 63 additions and 156 deletions
|
@ -85,7 +85,6 @@ import org.jxmpp.jid.FullJid;
|
|||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.util.XmppStringUtils;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
|
||||
public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||
|
@ -960,6 +959,10 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
stanza = PacketParserUtils.parseStanza(parser);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Always re-throw runtime exceptions, they are fatal
|
||||
if (e instanceof RuntimeException) {
|
||||
throw (RuntimeException) e;
|
||||
}
|
||||
CharSequence content = PacketParserUtils.parseContentDepth(parser,
|
||||
parserDepth);
|
||||
UnparsablePacket message = new UnparsablePacket(content, e);
|
||||
|
@ -1315,8 +1318,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
}
|
||||
}
|
||||
|
||||
protected final void parseFeatures(XmlPullParser parser) throws XmlPullParserException,
|
||||
IOException, SmackException, InterruptedException {
|
||||
protected final void parseFeatures(XmlPullParser parser) throws Exception {
|
||||
streamFeatures.clear();
|
||||
final int initialDepth = parser.getDepth();
|
||||
while (true) {
|
||||
|
|
|
@ -16,17 +16,14 @@
|
|||
*/
|
||||
package org.jivesoftware.smack.provider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -84,8 +81,7 @@ import org.xmlpull.v1.XmlPullParserException;
|
|||
public abstract class EmbeddedExtensionProvider<PE extends ExtensionElement> extends ExtensionElementProvider<PE> {
|
||||
|
||||
@Override
|
||||
public final PE parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException,
|
||||
SmackException {
|
||||
public final PE parse(XmlPullParser parser, int initialDepth) throws Exception {
|
||||
final String namespace = parser.getNamespace();
|
||||
final String name = parser.getName();
|
||||
final int attributeCount = parser.getAttributeCount();
|
||||
|
|
|
@ -17,17 +17,13 @@
|
|||
|
||||
package org.jivesoftware.smack.provider;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.packet.Element;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
public abstract class Provider<E extends Element> {
|
||||
|
||||
public final E parse(XmlPullParser parser) throws XmlPullParserException, IOException, SmackException {
|
||||
public final E parse(XmlPullParser parser) throws Exception{
|
||||
// XPP3 calling convention assert: Parser should be at start tag
|
||||
ParserUtils.assertAtStartTag(parser);
|
||||
|
||||
|
@ -39,5 +35,5 @@ public abstract class Provider<E extends Element> {
|
|||
return e;
|
||||
}
|
||||
|
||||
public abstract E parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException;
|
||||
public abstract E parse(XmlPullParser parser, int initialDepth) throws Exception;
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ public class PacketParserUtils {
|
|||
return parser;
|
||||
}
|
||||
|
||||
public static Stanza parseStanza(String stanza) throws XmlPullParserException, IOException, SmackException {
|
||||
public static Stanza parseStanza(String stanza) throws Exception {
|
||||
return parseStanza(getParserFor(stanza));
|
||||
}
|
||||
|
||||
|
@ -140,11 +140,9 @@ public class PacketParserUtils {
|
|||
*
|
||||
* @param parser
|
||||
* @return a packet which is either a Message, IQ or Presence.
|
||||
* @throws XmlPullParserException
|
||||
* @throws SmackException
|
||||
* @throws IOException
|
||||
* @throws Exception
|
||||
*/
|
||||
public static Stanza parseStanza(XmlPullParser parser) throws XmlPullParserException, IOException, SmackException {
|
||||
public static Stanza parseStanza(XmlPullParser parser) throws Exception {
|
||||
ParserUtils.assertAtStartTag(parser);
|
||||
final String name = parser.getName();
|
||||
switch (name) {
|
||||
|
@ -211,12 +209,10 @@ public class PacketParserUtils {
|
|||
*
|
||||
* @param parser the XML parser, positioned at the start of a message packet.
|
||||
* @return a Message packet.
|
||||
* @throws IOException
|
||||
* @throws XmlPullParserException
|
||||
* @throws SmackException
|
||||
* @throws Exception
|
||||
*/
|
||||
public static Message parseMessage(XmlPullParser parser)
|
||||
throws XmlPullParserException, IOException, SmackException {
|
||||
throws Exception {
|
||||
ParserUtils.assertAtStartTag(parser);
|
||||
assert(parser.getName().equals(Message.ELEMENT));
|
||||
|
||||
|
@ -513,12 +509,10 @@ public class PacketParserUtils {
|
|||
*
|
||||
* @param parser the XML parser, positioned at the start of a presence packet.
|
||||
* @return a Presence packet.
|
||||
* @throws IOException
|
||||
* @throws XmlPullParserException
|
||||
* @throws SmackException
|
||||
* @throws Exception
|
||||
*/
|
||||
public static Presence parsePresence(XmlPullParser parser)
|
||||
throws XmlPullParserException, IOException, SmackException {
|
||||
throws Exception {
|
||||
ParserUtils.assertAtStartTag(parser);
|
||||
final int initialDepth = parser.getDepth();
|
||||
|
||||
|
@ -600,7 +594,7 @@ public class PacketParserUtils {
|
|||
* @throws IOException
|
||||
* @throws SmackException
|
||||
*/
|
||||
public static IQ parseIQ(XmlPullParser parser) throws XmlPullParserException, IOException, SmackException {
|
||||
public static IQ parseIQ(XmlPullParser parser) throws Exception {
|
||||
ParserUtils.assertAtStartTag(parser);
|
||||
final int initialDepth = parser.getDepth();
|
||||
IQ iqPacket = null;
|
||||
|
@ -792,11 +786,9 @@ public class PacketParserUtils {
|
|||
*
|
||||
* @param parser the XML parser.
|
||||
* @return an stream error packet.
|
||||
* @throws XmlPullParserException if an exception occurs while parsing the packet.
|
||||
* @throws SmackException
|
||||
* @throws Exception if an exception occurs while parsing the packet.
|
||||
*/
|
||||
public static StreamError parseStreamError(XmlPullParser parser) throws IOException, XmlPullParserException,
|
||||
SmackException {
|
||||
public static StreamError parseStreamError(XmlPullParser parser) throws Exception {
|
||||
final int initialDepth = parser.getDepth();
|
||||
List<ExtensionElement> extensions = new ArrayList<ExtensionElement>();
|
||||
Map<String, String> descriptiveTexts = null;
|
||||
|
@ -844,12 +836,10 @@ public class PacketParserUtils {
|
|||
*
|
||||
* @param parser the XML parser.
|
||||
* @return an error sub-packet.
|
||||
* @throws IOException
|
||||
* @throws XmlPullParserException
|
||||
* @throws SmackException
|
||||
* @throws Exception
|
||||
*/
|
||||
public static XMPPError parseError(XmlPullParser parser)
|
||||
throws XmlPullParserException, IOException, SmackException {
|
||||
throws Exception {
|
||||
final int initialDepth = parser.getDepth();
|
||||
Map<String, String> descriptiveTexts = null;
|
||||
XMPPError.Condition condition = null;
|
||||
|
@ -898,8 +888,7 @@ public class PacketParserUtils {
|
|||
*/
|
||||
@Deprecated
|
||||
public static ExtensionElement parsePacketExtension(String elementName, String namespace,
|
||||
XmlPullParser parser) throws XmlPullParserException,
|
||||
IOException, SmackException {
|
||||
XmlPullParser parser) throws Exception {
|
||||
return parseExtensionElement(elementName, namespace, parser);
|
||||
}
|
||||
|
||||
|
@ -912,8 +901,7 @@ public class PacketParserUtils {
|
|||
* @return an extension element.
|
||||
*/
|
||||
public static ExtensionElement parseExtensionElement(String elementName, String namespace,
|
||||
XmlPullParser parser) throws XmlPullParserException,
|
||||
IOException, SmackException {
|
||||
XmlPullParser parser) throws Exception {
|
||||
ParserUtils.assertAtStartTag(parser);
|
||||
// See if a provider is registered to handle the extension.
|
||||
ExtensionElementProvider<ExtensionElement> provider = ProviderManager.getExtensionProvider(elementName, namespace);
|
||||
|
@ -1017,51 +1005,49 @@ public class PacketParserUtils {
|
|||
}
|
||||
|
||||
@Deprecated
|
||||
public static void addPacketExtension(Stanza packet, XmlPullParser parser) throws XmlPullParserException,
|
||||
IOException, SmackException {
|
||||
public static void addPacketExtension(Stanza packet, XmlPullParser parser) throws Exception {
|
||||
addExtensionElement(packet, parser);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void addPacketExtension(Stanza packet, XmlPullParser parser, String elementName, String namespace)
|
||||
throws XmlPullParserException, IOException, SmackException {
|
||||
throws Exception {
|
||||
addExtensionElement(packet, parser, elementName, namespace);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void addPacketExtension(Collection<ExtensionElement> collection, XmlPullParser parser)
|
||||
throws XmlPullParserException, IOException, SmackException {
|
||||
throws Exception {
|
||||
addExtensionElement(collection, parser, parser.getName(), parser.getNamespace());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void addPacketExtension(Collection<ExtensionElement> collection, XmlPullParser parser,
|
||||
String elementName, String namespace) throws XmlPullParserException, IOException, SmackException {
|
||||
String elementName, String namespace) throws Exception {
|
||||
addExtensionElement(collection, parser, elementName, namespace);
|
||||
}
|
||||
|
||||
|
||||
public static void addExtensionElement(Stanza packet, XmlPullParser parser)
|
||||
throws XmlPullParserException, IOException, SmackException {
|
||||
throws Exception {
|
||||
ParserUtils.assertAtStartTag(parser);
|
||||
addExtensionElement(packet, parser, parser.getName(), parser.getNamespace());
|
||||
}
|
||||
|
||||
public static void addExtensionElement(Stanza packet, XmlPullParser parser, String elementName,
|
||||
String namespace) throws XmlPullParserException, IOException, SmackException {
|
||||
String namespace) throws Exception{
|
||||
ExtensionElement packetExtension = parseExtensionElement(elementName, namespace, parser);
|
||||
packet.addExtension(packetExtension);
|
||||
}
|
||||
|
||||
public static void addExtensionElement(Collection<ExtensionElement> collection,
|
||||
XmlPullParser parser) throws XmlPullParserException, IOException,
|
||||
SmackException {
|
||||
XmlPullParser parser) throws Exception {
|
||||
addExtensionElement(collection, parser, parser.getName(), parser.getNamespace());
|
||||
}
|
||||
|
||||
public static void addExtensionElement(Collection<ExtensionElement> collection,
|
||||
XmlPullParser parser, String elementName, String namespace)
|
||||
throws XmlPullParserException, IOException, SmackException {
|
||||
throws Exception {
|
||||
ExtensionElement packetExtension = parseExtensionElement(elementName, namespace, parser);
|
||||
collection.add(packetExtension);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import java.io.IOException;
|
|||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
|
@ -79,13 +78,13 @@ final public class TestUtils {
|
|||
}
|
||||
|
||||
public static <EE extends ExtensionElement> EE parseExtensionElement(String elementString)
|
||||
throws XmlPullParserException, IOException, SmackException {
|
||||
throws Exception {
|
||||
return parseExtensionElement(getParser(elementString));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <EE extends ExtensionElement> EE parseExtensionElement(XmlPullParser parser)
|
||||
throws XmlPullParserException, IOException, SmackException {
|
||||
throws Exception {
|
||||
ParserUtils.assertAtStartTag(parser);
|
||||
final String elementName = parser.getName();
|
||||
final String namespace = parser.getNamespace();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue