mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 22:12:05 +01:00
Added stream errors support. SMACK-107
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@3042 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
cb06777500
commit
c23b4f20db
2 changed files with 60 additions and 1 deletions
|
@ -30,6 +30,7 @@ import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listens for XML traffic from the XMPP server and parses it into packet objects.
|
* Listens for XML traffic from the XMPP server and parses it into packet objects.
|
||||||
|
@ -305,6 +306,9 @@ class PacketReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (parser.getName().equals("error")) {
|
||||||
|
throw new XMPPException(parseStreamError(parser));
|
||||||
|
}
|
||||||
else if (parser.getName().equals("features")) {
|
else if (parser.getName().equals("features")) {
|
||||||
parseFeatures(parser);
|
parseFeatures(parser);
|
||||||
}
|
}
|
||||||
|
@ -409,6 +413,25 @@ class PacketReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private StreamError parseStreamError(XmlPullParser parser) throws IOException,
|
||||||
|
XmlPullParserException {
|
||||||
|
StreamError streamError = null;
|
||||||
|
boolean done = false;
|
||||||
|
while (!done) {
|
||||||
|
int eventType = parser.next();
|
||||||
|
|
||||||
|
if (eventType == XmlPullParser.START_TAG) {
|
||||||
|
streamError = new StreamError(parser.getName());
|
||||||
|
}
|
||||||
|
else if (eventType == XmlPullParser.END_TAG) {
|
||||||
|
if (parser.getName().equals("error")) {
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return streamError;
|
||||||
|
}
|
||||||
|
|
||||||
private void parseFeatures(XmlPullParser parser) throws Exception {
|
private void parseFeatures(XmlPullParser parser) throws Exception {
|
||||||
boolean startTLSReceived = false;
|
boolean startTLSReceived = false;
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
package org.jivesoftware.smack;
|
package org.jivesoftware.smack;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.XMPPError;
|
import org.jivesoftware.smack.packet.XMPPError;
|
||||||
|
import org.jivesoftware.smack.packet.StreamError;
|
||||||
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
@ -29,13 +30,19 @@ import java.io.PrintWriter;
|
||||||
* A generic exception that is thrown when an error occurs performing an
|
* A generic exception that is thrown when an error occurs performing an
|
||||||
* XMPP operation. XMPP servers can respond to error conditions with an error code
|
* XMPP operation. XMPP servers can respond to error conditions with an error code
|
||||||
* and textual description of the problem, which are encapsulated in the XMPPError
|
* and textual description of the problem, which are encapsulated in the XMPPError
|
||||||
* class. When appropriate, an XMPPError instance is attached instances of this exception.
|
* class. When appropriate, an XMPPError instance is attached instances of this exception.<p>
|
||||||
|
*
|
||||||
|
* When a stream error occured, the server will send a stream error to the client before
|
||||||
|
* closing the connection. Stream errors are unrecoverable errors. When a stream error
|
||||||
|
* is sent to the client an XMPPException will be thrown containing the StreamError sent
|
||||||
|
* by the server.
|
||||||
*
|
*
|
||||||
* @see XMPPError
|
* @see XMPPError
|
||||||
* @author Matt Tucker
|
* @author Matt Tucker
|
||||||
*/
|
*/
|
||||||
public class XMPPException extends Exception {
|
public class XMPPException extends Exception {
|
||||||
|
|
||||||
|
private StreamError streamError = null;
|
||||||
private XMPPError error = null;
|
private XMPPError error = null;
|
||||||
private Throwable wrappedThrowable = null;
|
private Throwable wrappedThrowable = null;
|
||||||
|
|
||||||
|
@ -66,6 +73,18 @@ public class XMPPException extends Exception {
|
||||||
this.wrappedThrowable = wrappedThrowable;
|
this.wrappedThrowable = wrappedThrowable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cretaes a new XMPPException with the stream error that was the root case of the
|
||||||
|
* exception. When a stream error is received from the server then the underlying
|
||||||
|
* TCP connection will be closed by the server.
|
||||||
|
*
|
||||||
|
* @param streamError the root cause of the exception.
|
||||||
|
*/
|
||||||
|
public XMPPException(StreamError streamError) {
|
||||||
|
super();
|
||||||
|
this.streamError = streamError;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cretaes a new XMPPException with the XMPPError that was the root case of the
|
* Cretaes a new XMPPException with the XMPPError that was the root case of the
|
||||||
* exception.
|
* exception.
|
||||||
|
@ -125,6 +144,17 @@ public class XMPPException extends Exception {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the StreamError asscociated with this exception, or <tt>null</tt> if there
|
||||||
|
* isn't one. The underlying TCP connection is closed by the server after sending the
|
||||||
|
* stream error to the client.
|
||||||
|
*
|
||||||
|
* @return the StreamError asscociated with this exception.
|
||||||
|
*/
|
||||||
|
public StreamError getStreamError() {
|
||||||
|
return streamError;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Throwable asscociated with this exception, or <tt>null</tt> if there
|
* Returns the Throwable asscociated with this exception, or <tt>null</tt> if there
|
||||||
* isn't one.
|
* isn't one.
|
||||||
|
@ -162,6 +192,9 @@ public class XMPPException extends Exception {
|
||||||
if (msg == null && error != null) {
|
if (msg == null && error != null) {
|
||||||
return error.toString();
|
return error.toString();
|
||||||
}
|
}
|
||||||
|
else if (msg == null && streamError != null) {
|
||||||
|
return streamError.toString();
|
||||||
|
}
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,6 +207,9 @@ public class XMPPException extends Exception {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
buf.append(error);
|
buf.append(error);
|
||||||
}
|
}
|
||||||
|
if (streamError != null) {
|
||||||
|
buf.append(streamError);
|
||||||
|
}
|
||||||
if (wrappedThrowable != null) {
|
if (wrappedThrowable != null) {
|
||||||
buf.append("\n -- caused by: ").append(wrappedThrowable);
|
buf.append("\n -- caused by: ").append(wrappedThrowable);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue