1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-27 13:07:58 +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:
Gaston Dombiak 2005-11-08 20:10:33 +00:00 committed by gato
parent cb06777500
commit c23b4f20db
2 changed files with 60 additions and 1 deletions

View file

@ -30,6 +30,7 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.util.*;
import java.io.IOException;
/**
* 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")) {
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 {
boolean startTLSReceived = false;
boolean done = false;

View file

@ -21,6 +21,7 @@
package org.jivesoftware.smack;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.packet.StreamError;
import java.io.PrintStream;
import java.io.PrintWriter;
@ -29,13 +30,19 @@ import java.io.PrintWriter;
* 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
* 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
* @author Matt Tucker
*/
public class XMPPException extends Exception {
private StreamError streamError = null;
private XMPPError error = null;
private Throwable wrappedThrowable = null;
@ -66,6 +73,18 @@ public class XMPPException extends Exception {
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
* exception.
@ -125,6 +144,17 @@ public class XMPPException extends Exception {
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
* isn't one.
@ -162,6 +192,9 @@ public class XMPPException extends Exception {
if (msg == null && error != null) {
return error.toString();
}
else if (msg == null && streamError != null) {
return streamError.toString();
}
return msg;
}
@ -174,6 +207,9 @@ public class XMPPException extends Exception {
if (error != null) {
buf.append(error);
}
if (streamError != null) {
buf.append(streamError);
}
if (wrappedThrowable != null) {
buf.append("\n -- caused by: ").append(wrappedThrowable);
}