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 ac1f5020b..07bd364de 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -71,7 +71,6 @@ import org.jivesoftware.smack.packet.PlainStreamElement; import org.jivesoftware.smack.packet.StreamError; import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smack.parsing.ParsingExceptionCallback; -import org.jivesoftware.smack.parsing.UnparsablePacket; import org.jivesoftware.smack.provider.ExtensionElementProvider; import org.jivesoftware.smack.provider.ProviderManager; import org.jivesoftware.smack.util.DNSUtil; @@ -956,10 +955,10 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { catch (Exception e) { CharSequence content = PacketParserUtils.parseContentDepth(parser, parserDepth); - UnparsablePacket message = new UnparsablePacket(content, e); + UnparseableStanza message = new UnparseableStanza(content, e); ParsingExceptionCallback callback = getParsingExceptionCallback(); if (callback != null) { - callback.handleUnparsablePacket(message); + callback.handleUnparsableStanza(message); } } ParserUtils.assertAtEndTag(parser); diff --git a/smack-core/src/main/java/org/jivesoftware/smack/parsing/UnparsablePacket.java b/smack-core/src/main/java/org/jivesoftware/smack/UnparseableStanza.java similarity index 83% rename from smack-core/src/main/java/org/jivesoftware/smack/parsing/UnparsablePacket.java rename to smack-core/src/main/java/org/jivesoftware/smack/UnparseableStanza.java index 108198980..ab1e15a6f 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/parsing/UnparsablePacket.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/UnparseableStanza.java @@ -1,6 +1,6 @@ /** * - * Copyright 2013 Florian Schmaus. + * Copyright 2013-2015 Florian Schmaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,20 +15,19 @@ * limitations under the License. */ -package org.jivesoftware.smack.parsing; - +package org.jivesoftware.smack; /** - * Representation of an unparsable packet. + * Representation of an unparsable stanza. * * @author Florian Schmaus * */ -public class UnparsablePacket { +public class UnparseableStanza { private final CharSequence content; private final Exception e; - public UnparsablePacket(final CharSequence content, final Exception e) { + UnparseableStanza(CharSequence content, Exception e) { this.content = content; this.e = e; } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/parsing/ExceptionLoggingCallback.java b/smack-core/src/main/java/org/jivesoftware/smack/parsing/ExceptionLoggingCallback.java index 9ee34fe3d..fe104c721 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/parsing/ExceptionLoggingCallback.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/parsing/ExceptionLoggingCallback.java @@ -1,6 +1,6 @@ /** * - * Copyright 2013 Florian Schmaus. + * Copyright 2013-2015 Florian Schmaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,18 +20,19 @@ package org.jivesoftware.smack.parsing; import java.util.logging.Level; import java.util.logging.Logger; +import org.jivesoftware.smack.UnparseableStanza; + /** * Simple parsing exception callback that only logs the encountered parsing exception to java util logging. * * @author Florian Schmaus * */ -public class ExceptionLoggingCallback extends ParsingExceptionCallback { +public class ExceptionLoggingCallback implements ParsingExceptionCallback { private static final Logger LOGGER = Logger.getLogger(ExceptionLoggingCallback.class.getName()); @Override - public void handleUnparsablePacket(UnparsablePacket unparsed) throws Exception { - LOGGER.log(Level.SEVERE, "Smack message parsing exception: ", unparsed.getParsingException()); - LOGGER.severe("Unparsed content: " + unparsed.getContent()); + public void handleUnparsableStanza(UnparseableStanza unparsed) throws Exception { + LOGGER.log(Level.SEVERE, "Smack message parsing exception. Content: '" + unparsed.getContent() + "'", unparsed.getParsingException()); } } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/parsing/ExceptionThrowingCallback.java b/smack-core/src/main/java/org/jivesoftware/smack/parsing/ExceptionThrowingCallback.java index 815ac78d7..50d38939d 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/parsing/ExceptionThrowingCallback.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/parsing/ExceptionThrowingCallback.java @@ -1,6 +1,6 @@ /** * - * Copyright 2013 Florian Schmaus. + * Copyright 2013-2015 Florian Schmaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,18 +18,19 @@ package org.jivesoftware.smack.parsing; import org.jivesoftware.smack.ConnectionListener; +import org.jivesoftware.smack.UnparseableStanza; /** * Parsing exception callback class that simply throws the encountered parsing exception. This usually leads to an - * {@link ConnectionListener#connectionClosedOnError(Exception)} disconnect of the connection. + * {@link ConnectionListener#connectionClosedOnError(Exception)} and disconnect of the connection. * * @author Florian Schmaus * */ -public class ExceptionThrowingCallback extends ParsingExceptionCallback { +public class ExceptionThrowingCallback implements ParsingExceptionCallback { @Override - public void handleUnparsablePacket(UnparsablePacket packetData) throws Exception { + public void handleUnparsableStanza(UnparseableStanza packetData) throws Exception { throw packetData.getParsingException(); } } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/parsing/ParsingExceptionCallback.java b/smack-core/src/main/java/org/jivesoftware/smack/parsing/ParsingExceptionCallback.java index db90c3fee..232a61ec6 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/parsing/ParsingExceptionCallback.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/parsing/ParsingExceptionCallback.java @@ -1,6 +1,6 @@ /** * - * Copyright 2013 Florian Schmaus. + * Copyright 2013-2015 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,31 +16,29 @@ */ package org.jivesoftware.smack.parsing; +import org.jivesoftware.smack.UnparseableStanza; + /** - * Base class to receive parsing exceptions. - * + * Interface to receive parsing exceptions. + *

* If this class is used as callback, then Smack will silently ignore the stanza that caused the parsing exception and * place the parser after the faulty stanza. - * - * Subclasses may or may not override certain methods of this class. Each of these methods will receive the exception - * that caused the parsing error and an instance of an Unparsed Stanza(/Packet) type. The latter can be used to inspect the - * stanza that caused the parsing error by using the getContent() (for example {@link UnparsablePacket#getContent()}) - * method. - * + *

+ *

* Smack provides 2 predefined ParsingExceptionCallback's: {@link ExceptionLoggingCallback} and {@link ExceptionThrowingCallback}. + *

* * @author Florian Schmaus * */ -public abstract class ParsingExceptionCallback { +public interface ParsingExceptionCallback { /** - * Called when parsing an message stanza caused an exception. + * Called when parsing a stanza caused an exception. * - * @param stanzaData - * the raw message stanza data that caused the exception + * @param stanzaData the raw stanza data that caused the exception * @throws Exception */ - public void handleUnparsablePacket(UnparsablePacket stanzaData) throws Exception { - } + public void handleUnparsableStanza(UnparseableStanza stanzaData) throws Exception; + }